Skip to content

Commit

Permalink
edit migration file
Browse files Browse the repository at this point in the history
  • Loading branch information
olfamizen committed Feb 14, 2024
1 parent 4ce89f9 commit 778a122
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions alembic/versions/fd73601a9075_add_delete_cascade_studies.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""add-delete-cascade-studies
"""Add delete cascade studies
Revision ID: fd73601a9075
Revises: 3c70366b10ea
Create Date: 2024-02-12 17:27:37.314443
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'fd73601a9075'
Expand All @@ -17,34 +15,40 @@


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('rawstudy', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'study', ['id'], ['id'], ondelete='CASCADE')

with op.batch_alter_table('study_additional_data', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'study', ['study_id'], ['id'], ondelete='CASCADE')

with op.batch_alter_table('variantstudy', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'study', ['id'], ['id'], ondelete='CASCADE')
# connexion: Connection = op.get_bind()
# connexion.execute("DROP TABLE IF EXISTS _alembic_tmp_rawstudy")
print(op.get_context().dialect.name)
if op.get_context().dialect.name == 'postgresql':
print(op.get_context().dialect.name)
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('rawstudy', schema=None) as batch_op:
batch_op.drop_constraint('rawstudy_id_fkey', type_='foreignkey')
batch_op.create_foreign_key('rawstudy_id_fkey', 'study', ['id'], ['id'], ondelete='CASCADE')

with op.batch_alter_table('study_additional_data', schema=None) as batch_op:
batch_op.drop_constraint('study_additional_data_study_id_fkey', type_='foreignkey')
batch_op.create_foreign_key('study_additional_data_study_id_fkey', 'study', ['study_id'], ['id'], ondelete='CASCADE')

with op.batch_alter_table('variantstudy', schema=None) as batch_op:
batch_op.drop_constraint('variantstudy_id_fkey', type_='foreignkey')
batch_op.create_foreign_key('variantstudy_id_fkey', 'study', ['id'], ['id'], ondelete='CASCADE')

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('variantstudy', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'study', ['id'], ['id'])

with op.batch_alter_table('study_additional_data', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'study', ['study_id'], ['id'])

with op.batch_alter_table('rawstudy', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'study', ['id'], ['id'])
if op.get_context().dialect.name == 'postgresql':
with op.batch_alter_table('variantstudy', schema=None) as batch_op:
batch_op.drop_constraint('rawstudy_id_fkey', type_='foreignkey')
batch_op.create_foreign_key('rawstudy_id_fkey', 'study', ['id'], ['id'])

with op.batch_alter_table('study_additional_data', schema=None) as batch_op:
batch_op.drop_constraint('study_additional_data_study_id_fkey', type_='foreignkey')
batch_op.create_foreign_key('study_additional_data_study_id_fkey', 'study', ['study_id'], ['id'])

with op.batch_alter_table('rawstudy', schema=None) as batch_op:
batch_op.drop_constraint('variantstudy_id_fkey', type_='foreignkey')
batch_op.create_foreign_key('variantstudy_id_fkey', 'study', ['id'], ['id'])

# ### end Alembic commands ###

0 comments on commit 778a122

Please sign in to comment.