Skip to content

Commit

Permalink
fixup! fixup! Fix alembic autogeneration and rename mismatching const…
Browse files Browse the repository at this point in the history
…raints
  • Loading branch information
ephraimbuddy committed Apr 15, 2024
1 parent 2f2b184 commit c43f01b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import sqlalchemy as sa
from alembic import op

from sqlalchemy import literal

# revision identifiers, used by Alembic.
revision = '686269002441'
Expand All @@ -42,31 +42,61 @@ def upgrade():
batch_op.drop_constraint('unique_conn_id', type_='unique')
batch_op.create_unique_constraint(batch_op.f('connection_conn_id_uq'), ['conn_id'])

max_cons = sa.table('dag', sa.column('max_consecutive_failed_dag_runs'))
op.execute(max_cons.update().values(max_consecutive_failed_dag_runs=literal("0")))
with op.batch_alter_table('dag') as batch_op:
batch_op.alter_column('max_consecutive_failed_dag_runs',
existing_type=sa.Integer(),
nullable=False)
batch_op.alter_column('max_consecutive_failed_dag_runs', existing_type=sa.Integer(), nullable=False)

with op.batch_alter_table("task_instance") as batch_op:
batch_op.drop_constraint("task_instance_dag_run_fkey", type_="foreignkey")
with op.batch_alter_table("task_reschedule") as batch_op:
batch_op.drop_constraint("task_reschedule_dr_fkey", type_="foreignkey")

with op.batch_alter_table('dag_run') as batch_op:
batch_op.drop_constraint('dag_run_dag_id_execution_date_uq', type_='unique')
batch_op.drop_constraint('dag_run_dag_id_run_id_uq', type_='unique')
batch_op.create_unique_constraint('dag_run_dag_id_execution_date_key', ['dag_id', 'execution_date'])
batch_op.create_unique_constraint('dag_run_dag_id_run_id_key', ['dag_id', 'run_id'])
with op.batch_alter_table("task_instance") as batch_op:
batch_op.create_foreign_key("task_instance_dag_run_fkey", "dag_run", ["dag_id", "run_id"], ["dag_id", "run_id"])
with op.batch_alter_table("task_reschedule") as batch_op:
batch_op.create_foreign_key(
"task_reschedule_dr_fkey",
"dag_run",
["dag_id", "run_id"],
["dag_id", "run_id"],
ondelete="CASCADE",
)


def downgrade():
"""Unapply Update missing constraints"""
with op.batch_alter_table('dag_run', schema=None) as batch_op:
with op.batch_alter_table("task_instance") as batch_op:
batch_op.drop_constraint("task_instance_dag_run_fkey", type_="foreignkey")
with op.batch_alter_table("task_reschedule") as batch_op:
batch_op.drop_constraint("task_reschedule_dr_fkey", type_="foreignkey")
with op.batch_alter_table('dag_run') as batch_op:
batch_op.drop_constraint('dag_run_dag_id_run_id_key', type_='unique')
batch_op.drop_constraint('dag_run_dag_id_execution_date_key', type_='unique')
batch_op.create_unique_constraint('dag_run_dag_id_run_id_uq', ['dag_id', 'run_id'])
batch_op.create_unique_constraint('dag_run_dag_id_execution_date_uq', ['dag_id', 'execution_date'])

with op.batch_alter_table('dag', schema=None) as batch_op:
with op.batch_alter_table("task_instance") as batch_op:
batch_op.create_foreign_key("task_instance_dag_run_fkey", "dag_run", ["dag_id", "run_id"], ["dag_id", "run_id"])
with op.batch_alter_table("task_reschedule") as batch_op:
batch_op.create_foreign_key(
"task_reschedule_dr_fkey",
"dag_run",
["dag_id", "run_id"],
["dag_id", "run_id"],
ondelete="CASCADE",
)

with op.batch_alter_table('dag') as batch_op:
batch_op.alter_column('max_consecutive_failed_dag_runs',
existing_type=sa.Integer(),
nullable=True)

with op.batch_alter_table('connection', schema=None) as batch_op:
with op.batch_alter_table('connection') as batch_op:
batch_op.drop_constraint(batch_op.f('connection_conn_id_uq'), type_='unique')
batch_op.create_unique_constraint('unique_conn_id', ['conn_id'])
2 changes: 1 addition & 1 deletion docs/apache-airflow/img/airflow_erd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54a34534280d8d8af3011b4279324ab73ee1dac7ffd3a1e8874134d41de4f4a5
eca313f14ea57b46094fe63b84617458d68826772e0cdf1c9fed090b86494642
4 changes: 2 additions & 2 deletions docs/apache-airflow/img/airflow_erd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c43f01b

Please sign in to comment.