Lee-W commented on code in PR #55883:
URL: https://github.com/apache/airflow/pull/55883#discussion_r2362719932


##########
airflow-core/src/airflow/migrations/versions/0041_3_0_0_rename_dataset_as_asset.py:
##########
@@ -101,14 +103,22 @@ 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":
+    conn = op.get_bind()
+    dialect_name = conn.dialect.name
+
+    if dialect_name == "sqlite":
+        exitstack = contextlib.ExitStack()
+        # 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:
+            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

Review Comment:
   ```suggestion
           conn.execute(text("PRAGMA foreign_keys=OFF"))
           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
           conn.execute(text("PRAGMA foreign_keys=ON"))
   ```
   
   is there any reason we don't try something like this ?



-- 
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]

Reply via email to