Copilot commented on code in PR #64818:
URL: https://github.com/apache/airflow/pull/64818#discussion_r3066486376


##########
airflow-core/src/airflow/migrations/versions/0111_3_3_0_add_indexes_on_dag_run_created_dag_.py:
##########
@@ -0,0 +1,79 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Add indexes on dag_run.created_dag_version_id and task_instance.dag_version_id.
+
+Revision ID: 9ff64e1c35d3
+Revises: a4c2d171ae18
+Create Date: 2026-04-06 22:54:17.279733
+
+"""
+
+from __future__ import annotations
+
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = "9ff64e1c35d3"
+down_revision = "a4c2d171ae18"
+branch_labels = None
+depends_on = None
+airflow_version = "3.3.0"
+
+
+def upgrade():
+    """Apply Add indexes on dag_run.created_dag_version_id and 
task_instance.dag_version_id."""
+    with op.batch_alter_table("dag_run", schema=None) as batch_op:
+        batch_op.create_index("idx_created_dag_version_id", 
["created_dag_version_id"], unique=False)
+
+    with op.batch_alter_table("task_instance", schema=None) as batch_op:
+        batch_op.create_index("ti_dag_version_id", ["dag_version_id"], 
unique=False)
+
+
+def downgrade():
+    """Unapply Add indexes on dag_run.created_dag_version_id and 
task_instance.dag_version_id."""
+    conn = op.get_bind()
+
+    with op.batch_alter_table("task_instance") as batch_op:
+        if conn.dialect.name == "mysql":
+            batch_op.drop_constraint("task_instance_dag_version_id_fkey", 
type_="foreignkey")
+            batch_op.drop_index("ti_dag_version_id")
+            batch_op.create_foreign_key(
+                "task_instance_dag_version_id_fkey",
+                "dag_version",
+                ["dag_version_id"],

Review Comment:
   In the MySQL downgrade path, the FK name for `task_instance.dag_version_id` 
is hard-coded as `task_instance_dag_version_id_fkey`. Other migrations use 
`batch_op.f("task_instance_dag_version_id_fkey")` to apply the SQLAlchemy 
naming convention; using `batch_op.f(...)` here would keep this downgrade 
resilient to naming-convention changes.



##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -245,6 +245,7 @@ class DagRun(Base, LoggingMixin):
         UniqueConstraint("dag_id", "logical_date", 
name="dag_run_dag_id_logical_date_key"),
         Index("idx_dag_run_dag_id", dag_id),
         Index("idx_dag_run_run_after", run_after),
+        Index("idx_created_dag_version_id", created_dag_version_id),

Review Comment:
   Index name `idx_created_dag_version_id` is inconsistent with the other 
DagRun indexes in this model (`idx_dag_run_*`). Consider renaming it (and the 
matching migration) to follow the existing `idx_dag_run_<...>` pattern to avoid 
ambiguity/collisions at the schema level.
   ```suggestion
           Index("idx_dag_run_created_dag_version_id", created_dag_version_id),
   ```



##########
airflow-core/src/airflow/migrations/versions/0111_3_3_0_add_indexes_on_dag_run_created_dag_.py:
##########
@@ -0,0 +1,79 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Add indexes on dag_run.created_dag_version_id and task_instance.dag_version_id.
+
+Revision ID: 9ff64e1c35d3
+Revises: a4c2d171ae18
+Create Date: 2026-04-06 22:54:17.279733
+
+"""
+
+from __future__ import annotations
+
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = "9ff64e1c35d3"
+down_revision = "a4c2d171ae18"
+branch_labels = None
+depends_on = None
+airflow_version = "3.3.0"
+
+
+def upgrade():
+    """Apply Add indexes on dag_run.created_dag_version_id and 
task_instance.dag_version_id."""
+    with op.batch_alter_table("dag_run", schema=None) as batch_op:
+        batch_op.create_index("idx_created_dag_version_id", 
["created_dag_version_id"], unique=False)
+
+    with op.batch_alter_table("task_instance", schema=None) as batch_op:
+        batch_op.create_index("ti_dag_version_id", ["dag_version_id"], 
unique=False)
+

Review Comment:
   The migration creates/drops the index named `idx_created_dag_version_id`. If 
you rename the ORM index to follow the existing `idx_dag_run_*` naming pattern, 
please keep this migration in sync so that upgrades/downgrades operate on the 
same index name.



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