Skip to content

Commit

Permalink
Add a CASCADE on delete for annotation_slim.group_id
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Sep 28, 2023
1 parent 1f956a7 commit 44ede4a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ omit =
[report]
show_missing = True
precision = 2
fail_under = 98.59
fail_under = 98.58

skip_covered = True
34 changes: 34 additions & 0 deletions h/migrations/versions/0d101aa6b9a5_anno_slim_group_cascade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Add CASCADE on deletion for annotation_slim.group."""
from alembic import op

revision = "0d101aa6b9a5"
down_revision = "28a982795769"


def upgrade():
op.drop_constraint(
"fk__annotation_slim__group_id__group", "annotation_slim", type_="foreignkey"
)
op.create_foreign_key(
op.f("fk__annotation_slim__group_id__group"),
"annotation_slim",
"group",
["group_id"],
["id"],
ondelete="CASCADE",
)


def downgrade():
op.drop_constraint(
op.f("fk__annotation_slim__group_id__group"),
"annotation_slim",
type_="foreignkey",
)
op.create_foreign_key(
"fk__annotation_slim__group_id__group",
"annotation_slim",
"group",
["group_id"],
["id"],
)
4 changes: 3 additions & 1 deletion h/models/annotation_slim.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,7 @@ class AnnotationSlim(Base):
)
user = sa.orm.relationship("User")

group_id = sa.Column(sa.Integer, sa.ForeignKey("group.id"), nullable=False)
group_id = sa.Column(
sa.Integer, sa.ForeignKey("group.id", ondelete="CASCADE"), nullable=False
)
group = sa.orm.relationship("Group")

0 comments on commit 44ede4a

Please sign in to comment.