Skip to content

Commit

Permalink
Migration to add CASCADE to user_group.group_id
Browse files Browse the repository at this point in the history
Add a DB migration to add `ON DELETE CASCADE` to the
`user_group.group_id` column's foreign key to `group.id`.
  • Loading branch information
seanh committed May 21, 2024
1 parent 349f85c commit a3821ee
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Add ON DELETE CASCADE to user_group.group_id."""

from alembic import op

revision = "857c71c8f5f3"
down_revision = "22a9ef7407ee"


def upgrade():
op.drop_constraint(
"fk__user_group__group_id__group", "user_group", type_="foreignkey"
)
op.create_foreign_key(
"fk__user_group__group_id__group",
"user_group",
"group",
["group_id"],
["id"],
ondelete="cascade",
)


def downgrade():
op.drop_constraint(
"fk__user_group__group_id__group", "user_group", type_="foreignkey"
)
op.create_foreign_key(
"fk__user_group__group_id__group", "user_group", "group", ["group_id"], ["id"]
)

0 comments on commit a3821ee

Please sign in to comment.