-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1943 from AntaresSimulatorTeam/bugfix/952-correct…
…-additional-data-casecade-delete fix(variant-db): correct foreign key constraints on variant study table
- Loading branch information
Showing
4 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
alembic/versions/c0c4aaf84861_add_delete_cascade_variant_studies.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Add delete cascade constraint to variant study foreign keys | ||
Revision ID: c0c4aaf84861 | ||
Revises: fd73601a9075 | ||
Create Date: 2024-02-21 17:29:48.736664 | ||
""" | ||
from alembic import op # type: ignore | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "c0c4aaf84861" | ||
down_revision = "fd73601a9075" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
COMMAND_BLOCK_FK = "commandblock_study_id_fkey" | ||
SNAPSHOT_FK = "variant_study_snapshot_id_fkey" | ||
|
||
|
||
def upgrade() -> None: | ||
dialect_name: str = op.get_context().dialect.name | ||
|
||
# SQLite doesn't support dropping foreign keys, so we need to ignore it here | ||
if dialect_name == "postgresql": | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("commandblock", schema=None) as batch_op: | ||
batch_op.drop_constraint(COMMAND_BLOCK_FK, type_="foreignkey") | ||
batch_op.create_foreign_key(COMMAND_BLOCK_FK, "variantstudy", ["study_id"], ["id"], ondelete="CASCADE") | ||
|
||
with op.batch_alter_table("variant_study_snapshot", schema=None) as batch_op: | ||
batch_op.drop_constraint(SNAPSHOT_FK, type_="foreignkey") | ||
batch_op.create_foreign_key(SNAPSHOT_FK, "variantstudy", ["id"], ["id"], ondelete="CASCADE") | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
dialect_name: str = op.get_context().dialect.name | ||
|
||
# SQLite doesn't support dropping foreign keys, so we need to ignore it here | ||
if dialect_name == "postgresql": | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("variant_study_snapshot", schema=None) as batch_op: | ||
batch_op.drop_constraint(SNAPSHOT_FK, type_="foreignkey") | ||
batch_op.create_foreign_key(SNAPSHOT_FK, "variantstudy", ["id"], ["id"]) | ||
|
||
with op.batch_alter_table("commandblock", schema=None) as batch_op: | ||
batch_op.drop_constraint(COMMAND_BLOCK_FK, type_="foreignkey") | ||
batch_op.create_foreign_key(COMMAND_BLOCK_FK, "variantstudy", ["study_id"], ["id"]) | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters