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


##########
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:
   Ok I added the index again in the __table_args__ . If i added this in the 
__table_args__ and executing the pre-commit after "alembic revision -m "add new 
field to db"" step it was failing do to the null errors and thought alembic is 
automatically trying to convert DB.... Only with removing the index out of 
__table_args__ and then working on the alembic script it was passing the 
pre-commit.



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