Skip to content

Commit

Permalink
Ensures new incident roles match all priorities (#1616)
Browse files Browse the repository at this point in the history
* Ensures new incident roles match all priorities

* removing unneeded import

* Fixing id
  • Loading branch information
kevgliss authored Sep 13, 2021
1 parent 120261a commit 2d40c5b
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class IncidentType(Base):
liaison_service = relationship("Service", foreign_keys=[liaison_service_id])


class IncidentPriority(Base):
__tablename__ = "incident_priority"
id = Column(Integer, primary_key=True)


assoc_incident_roles_incident_types = Table(
"incident_role_incident_type",
Base.metadata,
Expand All @@ -52,6 +57,14 @@ class IncidentType(Base):
PrimaryKeyConstraint("incident_role_id", "incident_type_id"),
)

assoc_incident_roles_incident_priorities = Table(
"incident_role_incident_priorities",
Base.metadata,
Column("incident_role_id", Integer, ForeignKey("incident_role.id")),
Column("incident_priority_id", Integer, ForeignKey("incident_priority.id")),
PrimaryKeyConstraint("incident_role_id", "incident_priority_id"),
)


class IncidentRole(Base):
__tablename__ = "incident_role"
Expand All @@ -67,6 +80,9 @@ class IncidentRole(Base):

# Relationships
incident_types = relationship("IncidentType", secondary=assoc_incident_roles_incident_types)
incident_priorities = relationship(
"IncidentPriority", secondary=assoc_incident_roles_incident_priorities
)

service_id = Column(Integer, ForeignKey("service.id"))
service = relationship("Service")
Expand Down Expand Up @@ -155,12 +171,15 @@ def upgrade():
if i_type.liaison_service_id:
roles[(i_type.project_id, i_type.liaison_service_id, "Liaison")].append(i_type)

incident_priorities = session.query(IncidentPriority).all()

for k, v in roles.items():
project_id, service_id, role = k
session.add(
IncidentRole(
project_id=project_id,
incident_types=v,
incident_priorities=incident_priorities,
role=role,
service_id=service_id,
)
Expand Down

0 comments on commit 2d40c5b

Please sign in to comment.