sortega commented on code in PR #64311: URL: https://github.com/apache/airflow/pull/64311#discussion_r3022289768
########## airflow-core/src/airflow/migrations/versions/0110_3_2_0_add_performance_indexes.py: ########## @@ -0,0 +1,68 @@ +# +# 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 performance indexes on serialized_dag, dag_code, and task_instance. + +Revision ID: 76984aa0347c +Revises: 1d6611b6ab7c +Create Date: 2026-03-27 00:00:00.000000 + +""" + +from __future__ import annotations + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "76984aa0347c" +down_revision = "a4c2d171ae18" +branch_labels = None +depends_on = None +airflow_version = "3.3.0" + + +def upgrade(): + """Add indexes for query performance on serialized_dag, dag_code, and task_instance.""" + with op.batch_alter_table("serialized_dag", schema=None) as batch_op: + batch_op.create_index( + "idx_serialized_dag_dag_id_last_updated", ["dag_id", "last_updated"], unique=False + ) + + with op.batch_alter_table("dag_code", schema=None) as batch_op: + batch_op.create_index("idx_dag_code_dag_id", ["dag_id"], unique=False) + + with op.batch_alter_table("task_instance", schema=None) as batch_op: + batch_op.create_index("idx_task_instance_dag_version_id", ["dag_version_id"], unique=False) + + +def downgrade(): + """Remove performance indexes.""" + conn = op.get_bind() Review Comment: `op.get_bind()` is the standard pattern used in ~20 other migrations in this repo. In offline mode there is no connection, but `batch_alter_table` also does not work offline — the entire downgrade is inherently online-only, so this is consistent with the rest of the codebase. -- 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]
