AutomationDev85 commented on code in PR #30827:
URL: https://github.com/apache/airflow/pull/30827#discussion_r1179024126


##########
airflow/migrations/versions/0125_2_6_0_add_index_on_last_scheduling_decision_.py:
##########
@@ -0,0 +1,57 @@
+#
+# 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 last_scheduling_decision NULLS FIRST, execution_date, state 
for queued dagrun
+
+Revision ID: c702ac480bc5
+Revises: 98ae134e6fff
+Create Date: 2023-04-25 09:18:33.450424
+
+"""
+from __future__ import annotations
+
+from alembic import op
+from sqlalchemy import text
+
+# revision identifiers, used by Alembic.
+revision = "c702ac480bc5"
+down_revision = "98ae134e6fff"
+branch_labels = None
+depends_on = None
+airflow_version = "2.6.0"
+
+
+def upgrade():
+    """Apply Add index on last_scheduling_decision NULLS FIRST, 
execution_date, state for queued dagrun"""
+    conn = op.get_bind()
+    if conn.dialect.name != "sqlite":
+        with op.batch_alter_table("dag_run") as batch_op:
+            batch_op.create_index(
+                "idx_last_scheduling_decision_queued",
+                [text("last_scheduling_decision NULLS FIRST"), 
"execution_date", "state"],
+                postgresql_where=text("state='queued'"),
+                mssql_where=text("state='queued'"),
+            )

Review Comment:
   Problem for me was after I added the Index to the __table_args__ of dagrun 
alembic tried to add this index automatically during pre-commit and this was 
failing because sqlite does not handle the NULLS FIRST. So I only added this in 
the migration script. Is there a better way to handle this?



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