This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-0-test by this push:
     new 06f909c7fff Do not use introspection in migration (#49873)
06f909c7fff is described below

commit 06f909c7fffdd96c89eeff47b1a4c4d04eb1d2fd
Author: Vincent <[email protected]>
AuthorDate: Tue May 6 15:26:04 2025 +0200

    Do not use introspection in migration (#49873)
    
    (cherry picked from commit ed5fceda57972288b0eae3c91bc6993715bff88a)
---
 airflow-core/docs/img/airflow_erd.sha256           |  2 +-
 .../0028_3_0_0_drop_ab_user_id_foreign_key.py      | 51 +++++-----------------
 2 files changed, 13 insertions(+), 40 deletions(-)

diff --git a/airflow-core/docs/img/airflow_erd.sha256 
b/airflow-core/docs/img/airflow_erd.sha256
index 75ee17e07f7..f92146f77a8 100644
--- a/airflow-core/docs/img/airflow_erd.sha256
+++ b/airflow-core/docs/img/airflow_erd.sha256
@@ -1 +1 @@
-26444bb1e7b1d3ec60bcba5d9b1d70d43c26c2b769b3878f1c60f74fac1250f0
\ No newline at end of file
+1b5221fa589cfc8652242b95f24d218c632168238933b82b533321a217c2447f
\ No newline at end of file
diff --git 
a/airflow-core/src/airflow/migrations/versions/0028_3_0_0_drop_ab_user_id_foreign_key.py
 
b/airflow-core/src/airflow/migrations/versions/0028_3_0_0_drop_ab_user_id_foreign_key.py
index 383319cd6d9..4387728020e 100644
--- 
a/airflow-core/src/airflow/migrations/versions/0028_3_0_0_drop_ab_user_id_foreign_key.py
+++ 
b/airflow-core/src/airflow/migrations/versions/0028_3_0_0_drop_ab_user_id_foreign_key.py
@@ -28,7 +28,6 @@ Create Date: 2024-08-02 07:18:29.830521
 from __future__ import annotations
 
 from alembic import op
-from sqlalchemy import inspect
 
 # revision identifiers, used by Alembic.
 revision = "044f740568ec"
@@ -38,54 +37,28 @@ depends_on = None
 airflow_version = "3.0.0"
 
 
-def table_exists(table_name):
-    """Check if a table exists in the database."""
-    inspector = inspect(op.get_bind())
-    return table_name in inspector.get_table_names()
-
-
-def constraint_exists(table_name, constraint_name):
-    """Check if a foreign key constraint exists on a table."""
-    inspector = inspect(op.get_bind())
-    foreign_keys = inspector.get_foreign_keys(table_name)
-    return any(fk["name"] == constraint_name for fk in foreign_keys)
-
-
-def index_exists(table_name, index_name):
-    """Check if an index exists on a table."""
-    inspector = inspect(op.get_bind())
-    indexes = inspector.get_indexes(table_name)
-    return any(idx["name"] == index_name for idx in indexes)
-
-
 def upgrade():
     """Apply Drop ab_user.id foreign key."""
-    if constraint_exists("dag_run_note", "dag_run_note_user_fkey"):
-        with op.batch_alter_table("dag_run_note", schema=None) as batch_op:
-            batch_op.drop_constraint("dag_run_note_user_fkey", 
type_="foreignkey")
-
-    if constraint_exists("task_instance_note", "task_instance_note_user_fkey"):
-        with op.batch_alter_table("task_instance_note", schema=None) as 
batch_op:
-            batch_op.drop_constraint("task_instance_note_user_fkey", 
type_="foreignkey")
+    with op.batch_alter_table("dag_run_note", schema=None) as batch_op:
+        batch_op.drop_constraint("dag_run_note_user_fkey", type_="foreignkey")
+    with op.batch_alter_table("task_instance_note", schema=None) as batch_op:
+        batch_op.drop_constraint("task_instance_note_user_fkey", 
type_="foreignkey")
 
     if op.get_bind().dialect.name == "mysql":
-        if index_exists("dag_run_note", "dag_run_note_user_fkey"):
-            with op.batch_alter_table("dag_run_note", schema=None) as batch_op:
-                batch_op.drop_index("dag_run_note_user_fkey")
+        with op.batch_alter_table("dag_run_note", schema=None) as batch_op:
+            batch_op.drop_index("dag_run_note_user_fkey")
 
-        if index_exists("task_instance_note", "task_instance_note_user_fkey"):
-            with op.batch_alter_table("task_instance_note", schema=None) as 
batch_op:
-                batch_op.drop_index("task_instance_note_user_fkey")
+        with op.batch_alter_table("task_instance_note", schema=None) as 
batch_op:
+            batch_op.drop_index("task_instance_note_user_fkey")
 
 
 def downgrade():
     """Unapply Drop ab_user.id foreign key."""
-    if table_exists("ab_user"):
-        with op.batch_alter_table("task_instance_note", schema=None) as 
batch_op:
-            batch_op.create_foreign_key("task_instance_note_user_fkey", 
"ab_user", ["user_id"], ["id"])
+    with op.batch_alter_table("task_instance_note", schema=None) as batch_op:
+        batch_op.create_foreign_key("task_instance_note_user_fkey", "ab_user", 
["user_id"], ["id"])
 
-        with op.batch_alter_table("dag_run_note", schema=None) as batch_op:
-            batch_op.create_foreign_key("dag_run_note_user_fkey", "ab_user", 
["user_id"], ["id"])
+    with op.batch_alter_table("dag_run_note", schema=None) as batch_op:
+        batch_op.create_foreign_key("dag_run_note_user_fkey", "ab_user", 
["user_id"], ["id"])
 
     if op.get_bind().dialect.name == "mysql":
         with op.batch_alter_table("task_instance_note", schema=None) as 
batch_op:

Reply via email to