You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2026/05/01 15:27:41 UTC

(airflow) branch v3-2-test updated: [v3-2-test] Fix missing autoincrement sequence on callback_request downgrade (#65230) (#66189)

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

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


The following commit(s) were added to refs/heads/v3-2-test by this push:
     new 6c42957e100 [v3-2-test] Fix missing autoincrement sequence on callback_request downgrade (#65230) (#66189)
6c42957e100 is described below

commit 6c42957e100afe0dfcd050c5e13f5474fe740ec1
Author: github-actions[bot] <41...@users.noreply.github.com>
AuthorDate: Fri May 1 17:27:33 2026 +0200

    [v3-2-test] Fix missing autoincrement sequence on callback_request downgrade (#65230) (#66189)
    
    (cherry picked from commit c1056986fff15b629829962b8a810d6f505fbdb2)
    
    
    closes: #65000
    
    Co-authored-by: rjgoyln <15...@users.noreply.github.com>
---
 .../0093_3_2_0_restructure_callback_table.py       | 31 ++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/airflow-core/src/airflow/migrations/versions/0093_3_2_0_restructure_callback_table.py b/airflow-core/src/airflow/migrations/versions/0093_3_2_0_restructure_callback_table.py
index d7037393ce6..640ff5728af 100644
--- a/airflow-core/src/airflow/migrations/versions/0093_3_2_0_restructure_callback_table.py
+++ b/airflow-core/src/airflow/migrations/versions/0093_3_2_0_restructure_callback_table.py
@@ -96,3 +96,34 @@ def downgrade():
         batch_op.drop_column("type")
 
     op.rename_table("callback", "callback_request")
+    bind = op.get_bind()
+    dialect_name = bind.dialect.name
+    if dialect_name == "postgresql":
+        op.execute("CREATE SEQUENCE IF NOT EXISTS callback_request_id_seq")
+
+        with op.batch_alter_table("callback_request", schema=None) as batch_op:
+            batch_op.alter_column(
+                "id",
+                existing_type=sa.INTEGER(),
+                nullable=False,
+                server_default=sa.text("nextval('callback_request_id_seq')"),
+            )
+
+        op.execute("ALTER SEQUENCE callback_request_id_seq OWNED BY callback_request.id")
+        op.execute(
+            "SELECT setval('callback_request_id_seq', "
+            "COALESCE((SELECT MAX(id) FROM callback_request), 1), "
+            "(SELECT MAX(id) IS NOT NULL FROM callback_request))"
+        )
+
+    elif dialect_name == "mysql":
+        with op.batch_alter_table("callback_request", schema=None) as batch_op:
+            batch_op.alter_column(
+                "id",
+                existing_type=sa.INTEGER(),
+                nullable=False,
+                autoincrement=True,
+            )
+        result = bind.execute(sa.text("SELECT COALESCE(MAX(id), 0) + 1 FROM callback_request"))
+        next_id = result.scalar()
+        op.execute(sa.text(f"ALTER TABLE callback_request AUTO_INCREMENT = {next_id}"))