Skip to content

Commit a3821ee

Browse files
committed
Migration to add CASCADE to user_group.group_id
Add a DB migration to add `ON DELETE CASCADE` to the `user_group.group_id` column's foreign key to `group.id`.
1 parent 349f85c commit a3821ee

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Add ON DELETE CASCADE to user_group.group_id."""
2+
3+
from alembic import op
4+
5+
revision = "857c71c8f5f3"
6+
down_revision = "22a9ef7407ee"
7+
8+
9+
def upgrade():
10+
op.drop_constraint(
11+
"fk__user_group__group_id__group", "user_group", type_="foreignkey"
12+
)
13+
op.create_foreign_key(
14+
"fk__user_group__group_id__group",
15+
"user_group",
16+
"group",
17+
["group_id"],
18+
["id"],
19+
ondelete="cascade",
20+
)
21+
22+
23+
def downgrade():
24+
op.drop_constraint(
25+
"fk__user_group__group_id__group", "user_group", type_="foreignkey"
26+
)
27+
op.create_foreign_key(
28+
"fk__user_group__group_id__group", "user_group", "group", ["group_id"], ["id"]
29+
)

0 commit comments

Comments
 (0)