Skip to content

Commit

Permalink
Add a CASCADE on delete for annotation_slim.document_id
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Oct 4, 2023
1 parent 48dba18 commit 0b50fc3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
36 changes: 36 additions & 0 deletions h/migrations/versions/7418b43b64c3_anno_slim_document_cascade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Add CASCADE on deletion for annotation_slim.document_id."""
from alembic import op

revision = "7418b43b64c3"
down_revision = "3081971a50fc"


def upgrade():
op.drop_constraint(
"fk__annotation_slim__document_id__document",
"annotation_slim",
type_="foreignkey",
)
op.create_foreign_key(
op.f("fk__annotation_slim__document_id__document"),
"annotation_slim",
"document",
["document_id"],
["id"],
ondelete="CASCADE",
)


def downgrade():
op.drop_constraint(
op.f("fk__annotation_slim__document_id__document"),
"annotation_slim",
type_="foreignkey",
)
op.create_foreign_key(
"fk__annotation_slim__document_id__document",
"annotation_slim",
"document",
["document_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 @@ -69,7 +69,9 @@ class AnnotationSlim(Base):
server_default=sa.sql.expression.false(),
)

document_id = sa.Column(sa.Integer, sa.ForeignKey("document.id"), nullable=False)
document_id = sa.Column(
sa.Integer, sa.ForeignKey("document.id", ondelete="CASCADE"), nullable=False
)
document = sa.orm.relationship("Document")

user_id = sa.Column(
Expand Down

0 comments on commit 0b50fc3

Please sign in to comment.