iting0321 commented on code in PR #64838:
URL: https://github.com/apache/airflow/pull/64838#discussion_r3256774073
##########
airflow-core/src/airflow/migrations/versions/0041_3_0_0_rename_dataset_as_asset.py:
##########
@@ -103,19 +102,18 @@ def _drop_fkey_if_exists(table, constraint_name):
conn = op.get_bind()
dialect_name = conn.dialect.name
Review Comment:
change to `dialect_name = get_dialect_name(op)`
##########
airflow-core/src/airflow/migrations/versions/0101_3_2_0_ui_improvements_for_deadlines.py:
##########
@@ -171,64 +172,58 @@ def upgrade() -> None:
# user-provided DeadlineDefinition, and the actual instance of a
Definition is (still) the Deadline.
# This feels more intuitive than DeadlineAlert defining the Deadline.
- op.create_table(
- "deadline_alert",
- sa.Column("id", sa.Uuid(), default=uuid6.uuid7),
- sa.Column("created_at", UtcDateTime, nullable=False),
- sa.Column("serialized_dag_id", sa.Uuid(), nullable=False),
- sa.Column("name", sa.String(250), nullable=True),
- sa.Column("description", sa.Text(), nullable=True),
- sa.Column("reference", sa.JSON(), nullable=False),
- sa.Column("interval", sa.Float(), nullable=False),
- sa.Column("callback_def", sa.JSON(), nullable=False),
- sa.PrimaryKeyConstraint("id", name=op.f("deadline_alert_pkey")),
- )
-
- conn = op.get_bind()
- dialect_name = conn.dialect.name
-
- if dialect_name == "sqlite":
- conn.execute(sa.text("PRAGMA foreign_keys=OFF"))
-
- with op.batch_alter_table("deadline", schema=None) as batch_op:
- batch_op.add_column(sa.Column("deadline_alert_id", sa.Uuid(),
nullable=True))
- batch_op.add_column(sa.Column("created_at", UtcDateTime,
nullable=True))
- batch_op.add_column(sa.Column("last_updated_at", UtcDateTime,
nullable=True))
- batch_op.create_foreign_key(
- batch_op.f("deadline_deadline_alert_id_fkey"),
+ with disable_sqlite_fkeys(op):
+ op.create_table(
"deadline_alert",
- ["deadline_alert_id"],
- ["id"],
- ondelete="SET NULL",
+ sa.Column("id", sa.Uuid(), default=uuid6.uuid7),
+ sa.Column("created_at", UtcDateTime, nullable=False),
+ sa.Column("serialized_dag_id", sa.Uuid(), nullable=False),
+ sa.Column("name", sa.String(250), nullable=True),
+ sa.Column("description", sa.Text(), nullable=True),
+ sa.Column("reference", sa.JSON(), nullable=False),
+ sa.Column("interval", sa.Float(), nullable=False),
+ sa.Column("callback_def", sa.JSON(), nullable=False),
+ sa.PrimaryKeyConstraint("id", name=op.f("deadline_alert_pkey")),
)
- # For migration/backcompat purposes if no timestamp is there from the
migration, use now()
- # then lock the columns down so all new entries require the timestamps to
be provided.
- now = timezone.utcnow()
- conn.execute(
- sa.text("""
- UPDATE deadline
- SET created_at = :now, last_updated_at = :now
- WHERE created_at IS NULL OR last_updated_at IS NULL
- """),
- {"now": now},
- )
+ conn = op.get_bind()
+
+ with op.batch_alter_table("deadline", schema=None) as batch_op:
+ batch_op.add_column(sa.Column("deadline_alert_id", sa.Uuid(),
nullable=True))
+ batch_op.add_column(sa.Column("created_at", UtcDateTime,
nullable=True))
+ batch_op.add_column(sa.Column("last_updated_at", UtcDateTime,
nullable=True))
+ batch_op.create_foreign_key(
+ batch_op.f("deadline_deadline_alert_id_fkey"),
+ "deadline_alert",
+ ["deadline_alert_id"],
+ ["id"],
+ ondelete="SET NULL",
+ )
- with op.batch_alter_table("deadline", schema=None) as batch_op:
- batch_op.alter_column("created_at", existing_type=UtcDateTime,
nullable=False)
- batch_op.alter_column("last_updated_at", existing_type=UtcDateTime,
nullable=False)
-
- with op.batch_alter_table("deadline_alert", schema=None) as batch_op:
- batch_op.create_foreign_key(
- batch_op.f("deadline_alert_serialized_dag_id_fkey"),
- "serialized_dag",
- ["serialized_dag_id"],
- ["id"],
- ondelete="CASCADE",
+ # For migration/backcompat purposes if no timestamp is there from the
migration, use now()
+ # then lock the columns down so all new entries require the timestamps
to be provided.
+ now = timezone.utcnow()
+ conn.execute(
+ sa.text("""
+ UPDATE deadline
+ SET created_at = :now, last_updated_at = :now
+ WHERE created_at IS NULL OR last_updated_at IS NULL
+ """),
+ {"now": now},
)
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]