Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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