Skip to content

Commit

Permalink
[migration] fix last migration for Notification.type being not null
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBldy committed Jul 30, 2024
1 parent f674fef commit a83990b
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

from alembic import op
import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy.ext.declarative import declarative_base
from zou.migrations.utils.base import BaseMixin
from sqlalchemy_utils import UUIDType, ChoiceType


# revision identifiers, used by Alembic.
Expand All @@ -18,6 +22,65 @@


def upgrade():
base = declarative_base()

TYPES = [
("comment", "Comment"),
("mention", "Mention"),
("assignation", "Assignation"),
("reply", "Reply"),
("reply-mention", "Reply Mention"),
]

class Notification(base, BaseMixin):
"""
A notification is stored each time a comment is posted.
"""

__tablename__ = "notification"
read = sa.Column(sa.Boolean, nullable=False, default=False)
change = sa.Column(sa.Boolean, nullable=False, default=False)
type = sa.Column(ChoiceType(TYPES), nullable=False)
person_id = sa.Column(
UUIDType(binary=False),
nullable=False,
index=True,
)
author_id = sa.Column(
UUIDType(binary=False),
nullable=False,
index=True,
)
comment_id = sa.Column(
UUIDType(binary=False),
nullable=True,
index=True,
)
task_id = sa.Column(
UUIDType(binary=False),
nullable=False,
index=True,
)
reply_id = sa.Column(UUIDType(binary=False), nullable=True, index=True)

__table_args__ = (
sa.UniqueConstraint(
"person_id",
"author_id",
"comment_id",
"reply_id",
"type",
name="notification_uc",
),
)

bind = op.get_bind()
session = orm.Session(bind=bind)
session.query(Notification).where(Notification.type == None).update(
{Notification.type: "comment"}
)
session.commit()

# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("notification", schema=None) as batch_op:
batch_op.alter_column(
Expand Down

0 comments on commit a83990b

Please sign in to comment.