Skip to content

Commit

Permalink
Add a CASCADE on delete for annotation_slim.user_id
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Sep 28, 2023
1 parent 4342112 commit 1f956a7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
34 changes: 34 additions & 0 deletions h/migrations/versions/28a982795769_anno_slim_user_cascade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Add CASCADE on deletion for annotation_slim.user."""
from alembic import op

revision = "28a982795769"
down_revision = "15b5dc900ebb"


def upgrade():
op.drop_constraint(
"fk__annotation_slim__user_id__user", "annotation_slim", type_="foreignkey"
)
op.create_foreign_key(
op.f("fk__annotation_slim__user_id__user"),
"annotation_slim",
"user",
["user_id"],
["id"],
ondelete="CASCADE",
)


def downgrade():
op.drop_constraint(
op.f("fk__annotation_slim__user_id__user"),
"annotation_slim",
type_="foreignkey",
)
op.create_foreign_key(
"fk__annotation_slim__user_id__user",
"annotation_slim",
"user",
["user_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 @@ -72,7 +72,9 @@ class AnnotationSlim(Base):
document_id = sa.Column(sa.Integer, sa.ForeignKey("document.id"), nullable=False)
document = sa.orm.relationship("Document")

user_id = sa.Column(sa.Integer, sa.ForeignKey("user.id"), nullable=False)
user_id = sa.Column(
sa.Integer, sa.ForeignKey("user.id", ondelete="CASCADE"), nullable=False
)
user = sa.orm.relationship("User")

group_id = sa.Column(sa.Integer, sa.ForeignKey("group.id"), nullable=False)
Expand Down

0 comments on commit 1f956a7

Please sign in to comment.