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

rahulvats pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 3e02720e0b3 Improve 0102_3_2_0_make_external_executor_id_text 
downgrade migration (#63625)
3e02720e0b3 is described below

commit 3e02720e0b3661299596363bdafc6e4f74d8f7d6
Author: nhuantho <[email protected]>
AuthorDate: Sat Mar 21 12:37:02 2026 +0700

    Improve 0102_3_2_0_make_external_executor_id_text downgrade migration 
(#63625)
    
    * [migration-0102] Change logic migration data of postgresql
    
    * Remove wrong comment
---
 .../0102_3_2_0_make_external_executor_id_text.py   | 53 ++++++++++++++++------
 1 file changed, 40 insertions(+), 13 deletions(-)

diff --git 
a/airflow-core/src/airflow/migrations/versions/0102_3_2_0_make_external_executor_id_text.py
 
b/airflow-core/src/airflow/migrations/versions/0102_3_2_0_make_external_executor_id_text.py
index 425bb073066..ea4271e22c7 100644
--- 
a/airflow-core/src/airflow/migrations/versions/0102_3_2_0_make_external_executor_id_text.py
+++ 
b/airflow-core/src/airflow/migrations/versions/0102_3_2_0_make_external_executor_id_text.py
@@ -59,18 +59,45 @@ def upgrade():
 
 def downgrade():
     """Revert external_executor_id column from TEXT to VARCHAR(250)."""
-    with op.batch_alter_table("task_instance_history", schema=None) as 
batch_op:
-        batch_op.alter_column(
-            "external_executor_id",
-            existing_type=sa.Text(),
-            type_=sa.VARCHAR(length=250),
-            existing_nullable=True,
-        )
+    conn = op.get_bind()
+    dialect = conn.dialect.name
 
-    with op.batch_alter_table("task_instance", schema=None) as batch_op:
-        batch_op.alter_column(
-            "external_executor_id",
-            existing_type=sa.Text(),
-            type_=sa.VARCHAR(length=250),
-            existing_nullable=True,
+    if dialect == "postgresql":
+        op.execute(
+            """
+            ALTER TABLE task_instance_history
+            ALTER
+            COLUMN external_executor_id TYPE VARCHAR(250)
+            USING CASE
+                WHEN external_executor_id IS NOT NULL THEN 
external_executor_id::VARCHAR(250)
+                ELSE NULL
+            END
+            """
         )
+        op.execute(
+            """
+            ALTER TABLE task_instance
+            ALTER
+            COLUMN external_executor_id TYPE VARCHAR(250)
+            USING CASE
+                WHEN external_executor_id IS NOT NULL THEN 
external_executor_id::VARCHAR(250)
+                ELSE NULL
+            END
+            """
+        )
+    else:
+        with op.batch_alter_table("task_instance_history", schema=None) as 
batch_op:
+            batch_op.alter_column(
+                "external_executor_id",
+                existing_type=sa.Text(),
+                type_=sa.VARCHAR(length=250),
+                existing_nullable=True,
+            )
+
+        with op.batch_alter_table("task_instance", schema=None) as batch_op:
+            batch_op.alter_column(
+                "external_executor_id",
+                existing_type=sa.Text(),
+                type_=sa.VARCHAR(length=250),
+                existing_nullable=True,
+            )

Reply via email to