vatsrahul1001 commented on code in PR #55883:
URL: https://github.com/apache/airflow/pull/55883#discussion_r2362710961
##########
airflow-core/src/airflow/migrations/versions/0041_3_0_0_rename_dataset_as_asset.py:
##########
@@ -101,17 +103,26 @@ def _rename_pk_constraint(
def _drop_fkey_if_exists(table, constraint_name):
- dialect = op.get_bind().dialect.name
- if dialect == "sqlite":
- try:
- with op.batch_alter_table(table, schema=None) as batch_op:
- batch_op.drop_constraint(op.f(constraint_name),
type_="foreignkey")
- except ValueError:
- pass
- elif dialect == "mysql":
- mysql_drop_foreignkey_if_exists(constraint_name, table, op)
- else:
- op.execute(f"ALTER TABLE {table} DROP CONSTRAINT IF EXISTS
{constraint_name}")
+ conn = op.get_bind()
+ dialect_name = conn.dialect.name
+ exitstack = contextlib.ExitStack()
+
+ if dialect_name == "sqlite":
+ # SQLite requires foreign key constraints to be disabled during batch
operations
+ conn.execute(text("PRAGMA foreign_keys=OFF"))
+ exitstack.callback(conn.execute, text("PRAGMA foreign_keys=ON"))
+
+ with exitstack:
+ if dialect_name == "sqlite":
+ try:
Review Comment:
yes
--
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]