Skip to content

Commit

Permalink
fix migration
Browse files Browse the repository at this point in the history
  • Loading branch information
matusdrobuliak66 committed Nov 14, 2024
1 parent 092fa3d commit cc3be4b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""enhance projects_tags for RUT
Revision ID: 7b3a1c9a1e78
Revision ID: 61e798889f2f
Revises: 8bfe65a5e294
Create Date: 2024-11-13 15:13:32.262499+00:00
Create Date: 2024-11-14 14:36:14.377526+00:00
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "7b3a1c9a1e78"
revision = "61e798889f2f"
down_revision = "8bfe65a5e294"
branch_labels = None
depends_on = None
Expand All @@ -26,10 +26,12 @@ def upgrade():
op.drop_constraint(
"study_tags_study_id_tag_id_key", "projects_tags", type_="unique"
)
op.create_unique_constraint(None, "projects_tags", ["project_uuid", "tag_id"])
op.create_unique_constraint(
"project_tags_project_uuid_unique", "projects_tags", ["project_uuid", "tag_id"]
)
op.drop_constraint("study_tags_study_id_fkey", "projects_tags", type_="foreignkey")
op.create_foreign_key(
None,
"project_tags_project_id_fkey",
"projects_tags",
"projects",
["project_id"],
Expand All @@ -42,7 +44,9 @@ def upgrade():

def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "projects_tags", type_="foreignkey")
op.drop_constraint(
"project_tags_project_id_fkey", "projects_tags", type_="foreignkey"
)
op.create_foreign_key(
"study_tags_study_id_fkey",
"projects_tags",
Expand All @@ -52,7 +56,9 @@ def downgrade():
onupdate="CASCADE",
ondelete="CASCADE",
)
op.drop_constraint(None, "projects_tags", type_="unique")
op.drop_constraint(
"project_tags_project_uuid_unique", "projects_tags", type_="unique"
)
op.create_unique_constraint(
"study_tags_study_id_tag_id_key", "projects_tags", ["project_id", "tag_id"]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
sa.Column(
"project_id",
sa.BigInteger,
sa.ForeignKey(projects.c.id, onupdate="CASCADE", ondelete="SET NULL"),
sa.ForeignKey(
projects.c.id,
onupdate="CASCADE",
ondelete="SET NULL",
name="project_tags_project_id_fkey",
),
nullable=True, # <-- NULL means that project was deleted
doc="NOTE that project.c.id != project.c.uuid",
),
Expand All @@ -28,5 +33,7 @@
sa.String,
nullable=False,
),
sa.UniqueConstraint("project_uuid", "tag_id"),
sa.UniqueConstraint(
"project_uuid", "tag_id", name="project_tags_project_uuid_unique"
),
)

0 comments on commit cc3be4b

Please sign in to comment.