|
| 1 | +"""Adds on delete cascade behavior to foreign keys |
| 2 | +
|
| 3 | +Revision ID: 38f0b01448ba |
| 4 | +Revises: 1c3f808aa00c |
| 5 | +Create Date: 2020-12-17 16:20:11.517862 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | + |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = "38f0b01448ba" |
| 14 | +down_revision = "1c3f808aa00c" |
| 15 | +branch_labels = None |
| 16 | +depends_on = None |
| 17 | + |
| 18 | + |
| 19 | +def upgrade(): |
| 20 | + # ### commands auto generated by Alembic - please adjust! ### |
| 21 | + op.drop_table("document_incident") |
| 22 | + op.drop_constraint( |
| 23 | + "assoc_incident_tags_incident_id_fkey", "assoc_incident_tags", type_="foreignkey" |
| 24 | + ) |
| 25 | + op.drop_constraint("assoc_incident_tags_tag_id_fkey", "assoc_incident_tags", type_="foreignkey") |
| 26 | + op.create_foreign_key( |
| 27 | + None, "assoc_incident_tags", "tag", ["tag_id"], ["id"], ondelete="CASCADE" |
| 28 | + ) |
| 29 | + op.create_foreign_key( |
| 30 | + None, "assoc_incident_tags", "incident", ["incident_id"], ["id"], ondelete="CASCADE" |
| 31 | + ) |
| 32 | + op.drop_constraint( |
| 33 | + "assoc_incident_terms_incident_id_fkey", "assoc_incident_terms", type_="foreignkey" |
| 34 | + ) |
| 35 | + op.drop_constraint( |
| 36 | + "assoc_incident_terms_term_id_fkey", "assoc_incident_terms", type_="foreignkey" |
| 37 | + ) |
| 38 | + op.create_foreign_key( |
| 39 | + None, "assoc_incident_terms", "term", ["term_id"], ["id"], ondelete="CASCADE" |
| 40 | + ) |
| 41 | + op.create_foreign_key( |
| 42 | + None, "assoc_incident_terms", "incident", ["incident_id"], ["id"], ondelete="CASCADE" |
| 43 | + ) |
| 44 | + op.drop_constraint("conference_incident_id_fkey", "conference", type_="foreignkey") |
| 45 | + op.create_foreign_key( |
| 46 | + None, "conference", "incident", ["incident_id"], ["id"], ondelete="CASCADE" |
| 47 | + ) |
| 48 | + op.drop_constraint("conversation_incident_id_fkey", "conversation", type_="foreignkey") |
| 49 | + op.create_foreign_key( |
| 50 | + None, "conversation", "incident", ["incident_id"], ["id"], ondelete="CASCADE" |
| 51 | + ) |
| 52 | + op.drop_constraint("document_incident_id_fkey", "document", type_="foreignkey") |
| 53 | + op.create_foreign_key(None, "document", "incident", ["incident_id"], ["id"], ondelete="CASCADE") |
| 54 | + op.drop_constraint("event_individual_id_fkey", "event", type_="foreignkey") |
| 55 | + op.drop_constraint("event_incident_id_fkey", "event", type_="foreignkey") |
| 56 | + op.create_foreign_key(None, "event", "incident", ["incident_id"], ["id"], ondelete="CASCADE") |
| 57 | + op.create_foreign_key( |
| 58 | + None, "event", "individual_contact", ["individual_id"], ["id"], ondelete="CASCADE" |
| 59 | + ) |
| 60 | + op.drop_constraint("feedback_incident_id_fkey", "feedback", type_="foreignkey") |
| 61 | + op.create_foreign_key(None, "feedback", "incident", ["incident_id"], ["id"], ondelete="CASCADE") |
| 62 | + op.drop_constraint("group_incident_id_fkey", "group", type_="foreignkey") |
| 63 | + op.create_foreign_key(None, "group", "incident", ["incident_id"], ["id"], ondelete="CASCADE") |
| 64 | + op.drop_constraint("participant_incident_id_fkey", "participant", type_="foreignkey") |
| 65 | + op.create_foreign_key( |
| 66 | + None, "participant", "incident", ["incident_id"], ["id"], ondelete="CASCADE" |
| 67 | + ) |
| 68 | + op.drop_constraint( |
| 69 | + "participant_role_participant_id_fkey", "participant_role", type_="foreignkey" |
| 70 | + ) |
| 71 | + op.create_foreign_key( |
| 72 | + None, "participant_role", "participant", ["participant_id"], ["id"], ondelete="CASCADE" |
| 73 | + ) |
| 74 | + op.drop_constraint("report_incident_id_fkey", "report", type_="foreignkey") |
| 75 | + op.create_foreign_key(None, "report", "incident", ["incident_id"], ["id"], ondelete="CASCADE") |
| 76 | + op.drop_constraint("storage_incident_id_fkey", "storage", type_="foreignkey") |
| 77 | + op.create_foreign_key(None, "storage", "incident", ["incident_id"], ["id"], ondelete="CASCADE") |
| 78 | + op.drop_constraint("task_incident_id_fkey", "task", type_="foreignkey") |
| 79 | + op.create_foreign_key(None, "task", "incident", ["incident_id"], ["id"], ondelete="CASCADE") |
| 80 | + op.drop_constraint("ticket_incident_id_fkey", "ticket", type_="foreignkey") |
| 81 | + op.create_foreign_key(None, "ticket", "incident", ["incident_id"], ["id"], ondelete="CASCADE") |
| 82 | + op.drop_constraint( |
| 83 | + "workflow_instance_incident_id_fkey", "workflow_instance", type_="foreignkey" |
| 84 | + ) |
| 85 | + op.create_foreign_key( |
| 86 | + None, "workflow_instance", "incident", ["incident_id"], ["id"], ondelete="CASCADE" |
| 87 | + ) |
| 88 | + # ### end Alembic commands ### |
| 89 | + |
| 90 | + |
| 91 | +def downgrade(): |
| 92 | + # ### commands auto generated by Alembic - please adjust! ### |
| 93 | + op.drop_constraint(None, "workflow_instance", type_="foreignkey") |
| 94 | + op.create_foreign_key( |
| 95 | + "workflow_instance_incident_id_fkey", |
| 96 | + "workflow_instance", |
| 97 | + "incident", |
| 98 | + ["incident_id"], |
| 99 | + ["id"], |
| 100 | + ) |
| 101 | + op.drop_constraint(None, "ticket", type_="foreignkey") |
| 102 | + op.create_foreign_key("ticket_incident_id_fkey", "ticket", "incident", ["incident_id"], ["id"]) |
| 103 | + op.drop_constraint(None, "task", type_="foreignkey") |
| 104 | + op.create_foreign_key("task_incident_id_fkey", "task", "incident", ["incident_id"], ["id"]) |
| 105 | + op.drop_constraint(None, "storage", type_="foreignkey") |
| 106 | + op.create_foreign_key( |
| 107 | + "storage_incident_id_fkey", "storage", "incident", ["incident_id"], ["id"] |
| 108 | + ) |
| 109 | + op.drop_constraint(None, "report", type_="foreignkey") |
| 110 | + op.create_foreign_key("report_incident_id_fkey", "report", "incident", ["incident_id"], ["id"]) |
| 111 | + op.drop_constraint(None, "participant_role", type_="foreignkey") |
| 112 | + op.create_foreign_key( |
| 113 | + "participant_role_participant_id_fkey", |
| 114 | + "participant_role", |
| 115 | + "participant", |
| 116 | + ["participant_id"], |
| 117 | + ["id"], |
| 118 | + ) |
| 119 | + op.drop_constraint(None, "participant", type_="foreignkey") |
| 120 | + op.create_foreign_key( |
| 121 | + "participant_incident_id_fkey", "participant", "incident", ["incident_id"], ["id"] |
| 122 | + ) |
| 123 | + op.drop_constraint(None, "group", type_="foreignkey") |
| 124 | + op.create_foreign_key("group_incident_id_fkey", "group", "incident", ["incident_id"], ["id"]) |
| 125 | + op.drop_constraint(None, "feedback", type_="foreignkey") |
| 126 | + op.create_foreign_key( |
| 127 | + "feedback_incident_id_fkey", "feedback", "incident", ["incident_id"], ["id"] |
| 128 | + ) |
| 129 | + op.drop_constraint(None, "event", type_="foreignkey") |
| 130 | + op.drop_constraint(None, "event", type_="foreignkey") |
| 131 | + op.create_foreign_key("event_incident_id_fkey", "event", "incident", ["incident_id"], ["id"]) |
| 132 | + op.create_foreign_key( |
| 133 | + "event_individual_id_fkey", "event", "individual_contact", ["individual_id"], ["id"] |
| 134 | + ) |
| 135 | + op.drop_constraint(None, "document", type_="foreignkey") |
| 136 | + op.create_foreign_key( |
| 137 | + "document_incident_id_fkey", "document", "incident", ["incident_id"], ["id"] |
| 138 | + ) |
| 139 | + op.drop_constraint(None, "conversation", type_="foreignkey") |
| 140 | + op.create_foreign_key( |
| 141 | + "conversation_incident_id_fkey", "conversation", "incident", ["incident_id"], ["id"] |
| 142 | + ) |
| 143 | + op.drop_constraint(None, "conference", type_="foreignkey") |
| 144 | + op.create_foreign_key( |
| 145 | + "conference_incident_id_fkey", "conference", "incident", ["incident_id"], ["id"] |
| 146 | + ) |
| 147 | + op.drop_constraint(None, "assoc_incident_terms", type_="foreignkey") |
| 148 | + op.drop_constraint(None, "assoc_incident_terms", type_="foreignkey") |
| 149 | + op.create_foreign_key( |
| 150 | + "assoc_incident_terms_term_id_fkey", "assoc_incident_terms", "term", ["term_id"], ["id"] |
| 151 | + ) |
| 152 | + op.create_foreign_key( |
| 153 | + "assoc_incident_terms_incident_id_fkey", |
| 154 | + "assoc_incident_terms", |
| 155 | + "incident", |
| 156 | + ["incident_id"], |
| 157 | + ["id"], |
| 158 | + ) |
| 159 | + op.drop_constraint(None, "assoc_incident_tags", type_="foreignkey") |
| 160 | + op.drop_constraint(None, "assoc_incident_tags", type_="foreignkey") |
| 161 | + op.create_foreign_key( |
| 162 | + "assoc_incident_tags_tag_id_fkey", "assoc_incident_tags", "tag", ["tag_id"], ["id"] |
| 163 | + ) |
| 164 | + op.create_foreign_key( |
| 165 | + "assoc_incident_tags_incident_id_fkey", |
| 166 | + "assoc_incident_tags", |
| 167 | + "incident", |
| 168 | + ["incident_id"], |
| 169 | + ["id"], |
| 170 | + ) |
| 171 | + op.create_table( |
| 172 | + "document_incident", |
| 173 | + sa.Column("incident_id", sa.INTEGER(), autoincrement=False, nullable=False), |
| 174 | + sa.Column("document_id", sa.INTEGER(), autoincrement=False, nullable=False), |
| 175 | + sa.ForeignKeyConstraint( |
| 176 | + ["document_id"], ["document.id"], name="document_incident_document_id_fkey" |
| 177 | + ), |
| 178 | + sa.ForeignKeyConstraint( |
| 179 | + ["incident_id"], ["incident.id"], name="document_incident_incident_id_fkey" |
| 180 | + ), |
| 181 | + sa.PrimaryKeyConstraint("incident_id", "document_id", name="document_incident_pkey"), |
| 182 | + ) |
| 183 | + # ### end Alembic commands ### |
0 commit comments