Skip to content

Commit

Permalink
Adds ondelete cascades to foreign keys in the participant and case ta…
Browse files Browse the repository at this point in the history
…bles to allow project deletion (Netflix#3082) (#61)

Co-authored-by: Marc Vilanova <39573146+mvilanova@users.noreply.github.com>
  • Loading branch information
rutvijmehta-harness and mvilanova authored Mar 17, 2023
1 parent 3ffaf66 commit 067d452
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dispatch/case/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Case(Base, TimeStampMixin, ProjectMixin):
)

# relationships
assignee_id = Column(Integer, ForeignKey(Participant.id))
assignee_id = Column(Integer, ForeignKey("participant.id", ondelete="CASCADE"))
assignee = relationship(
Participant, foreign_keys=[assignee_id], lazy="subquery", post_update=True
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Adds ondelete cascade to case table for participant FK
Revision ID: 1d21b28bc553
Revises: 1ded4c2a7801
Create Date: 2023-03-08 10:26:05.472740
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "1d21b28bc553"
down_revision = "1ded4c2a7801"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("case_assignee_id_fkey", "case", type_="foreignkey")
op.create_foreign_key(None, "case", "participant", ["assignee_id"], ["id"], ondelete="CASCADE")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "case", type_="foreignkey")
op.create_foreign_key("case_assignee_id_fkey", "case", "participant", ["assignee_id"], ["id"])
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Adds ondelete cascade to participant table for individual_contact FK
Revision ID: 1ded4c2a7801
Revises: 7ddae3ba7822
Create Date: 2023-03-08 10:18:03.250210
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "1ded4c2a7801"
down_revision = "7ddae3ba7822"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("participant_individual_contact_id_fkey", "participant", type_="foreignkey")
op.create_foreign_key(
None,
"participant",
"individual_contact",
["individual_contact_id"],
["id"],
ondelete="CASCADE",
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "participant", type_="foreignkey")
op.create_foreign_key(
"participant_individual_contact_id_fkey",
"participant",
"individual_contact",
["individual_contact_id"],
["id"],
)
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion src/dispatch/participant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Participant(Base):
incident_id = Column(Integer, ForeignKey("incident.id", ondelete="CASCADE", use_alter=True))
case_id = Column(Integer, ForeignKey("case.id", ondelete="CASCADE", use_alter=True))
individual = relationship("IndividualContact", lazy="subquery", backref="participant")
individual_contact_id = Column(Integer, ForeignKey("individual_contact.id"))
individual_contact_id = Column(Integer, ForeignKey("individual_contact.id", ondelete="CASCADE"))
participant_roles = relationship(
"ParticipantRole", backref="participant", lazy="subquery", cascade="all, delete-orphan"
)
Expand Down

0 comments on commit 067d452

Please sign in to comment.