pankajkoti commented on code in PR #39526:
URL: https://github.com/apache/airflow/pull/39526#discussion_r1598002824


##########
airflow/migrations/versions/0143_2_9_2_add_index_on_dag_id_in_referencing_tables.py:
##########
@@ -0,0 +1,69 @@
+#
+# 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 index on dag_id in referencing tables.
+
+Revision ID: 250a7e04585c
+Revises: 686269002441
+Create Date: 2024-05-09 19:18:54.028277
+
+"""
+
+from __future__ import annotations
+
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = "250a7e04585c"
+down_revision = "686269002441"
+branch_labels = None
+depends_on = None
+airflow_version = "2.9.2"
+
+
+def upgrade():
+    """Apply Add index on dag_id in referencing tables."""
+    conn = op.get_bind()
+    # MySQL already indexes the foreign keys, hence only create indexes for 
postgres and sqlite.
+    if conn.dialect.name in ("postgresql", "sqlite"):

Review Comment:
   I opted to include explicit checks for PostgreSQL and SQLite here because 
we're aware that these database engines don't automatically create indexes on 
foreign keys. By doing so, if we introduce support for another database engine 
in the future, whose behaviour is similar to MySQL, which follows the same 
behaviour of creating indexes by default on foreign keys, this migration won't 
encounter issues. Otherwise, without these explicit checks, the migration might 
fail if the condition `conn.dialect.name != "mysql"` were present.
   
   For any additional databases we decide to support, we can create similar 
migrations tailored to their behavior regarding index creation on foreign keys.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to