diff --git a/airflow/migrations/versions/0069_2_0_0_add_scheduling_decision_to_dagrun_and_.py b/airflow/migrations/versions/0069_2_0_0_add_scheduling_decision_to_dagrun_and_.py index 923106fd483e53..34b676943137d3 100644 --- a/airflow/migrations/versions/0069_2_0_0_add_scheduling_decision_to_dagrun_and_.py +++ b/airflow/migrations/versions/0069_2_0_0_add_scheduling_decision_to_dagrun_and_.py @@ -48,7 +48,9 @@ def upgrade(): with op.batch_alter_table("dag_run", schema=None) as batch_op: batch_op.add_column(sa.Column("last_scheduling_decision", TIMESTAMP, nullable=True)) - batch_op.create_index("idx_last_scheduling_decision", ["last_scheduling_decision"], unique=False) + # Earlier we had here an index created on the last_scheduling_decision column. + # But we don't add it anymore since it's not useful. + batch_op.add_column(sa.Column("dag_hash", sa.String(32), nullable=True)) with op.batch_alter_table("dag", schema=None) as batch_op: @@ -95,8 +97,14 @@ def downgrade(): if is_sqlite: op.execute("PRAGMA foreign_keys=off") + # At 2.9.1 we removed idx_last_scheduling_decision index as it is not used, and changed this migration + # not to add it. So we use drop if exists (because it might not be there) + from contextlib import suppress + + with suppress(sa.exc.DatabaseError): # mysql does not support drop if exists index + op.drop_index("idx_last_scheduling_decision", table_name="dag_run", if_exists=True) + with op.batch_alter_table("dag_run", schema=None) as batch_op: - batch_op.drop_index("idx_last_scheduling_decision") batch_op.drop_column("last_scheduling_decision") batch_op.drop_column("dag_hash") diff --git a/airflow/migrations/versions/0142_2_9_1_remove_idx_last_scheduling_decision_.py b/airflow/migrations/versions/0142_2_9_1_remove_idx_last_scheduling_decision_.py new file mode 100644 index 00000000000000..d8ab46bccc6a1d --- /dev/null +++ b/airflow/migrations/versions/0142_2_9_1_remove_idx_last_scheduling_decision_.py @@ -0,0 +1,50 @@ +# +# 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. + +"""Remove ``idx_last_scheduling_decision`` index on last_scheduling_decision in dag_run table + +Revision ID: bff083ad727d +Revises: 677fdbb7fc54 +Create Date: 2024-04-26 12:58:00.594762 + +""" + +import sqlalchemy as sa +from alembic import op + + +# revision identifiers, used by Alembic. +revision = 'bff083ad727d' +down_revision = '677fdbb7fc54' +branch_labels = None +depends_on = None +airflow_version = "2.9.1" + + +def upgrade(): + """Apply Remove idx_last_scheduling_decision index on last_scheduling_decision in dag_run table""" + # This index may have been created in 2.0.0, but we've since removed it from migrations + from contextlib import suppress + + with suppress(sa.exc.DatabaseError): # mysql does not support drop if exists index + op.drop_index("idx_last_scheduling_decision", table_name="dag_run", if_exists=True) + + +def downgrade(): + """Unapply Remove idx_last_scheduling_decision index on last_scheduling_decision in dag_run table""" + pass diff --git a/airflow/models/dagrun.py b/airflow/models/dagrun.py index 777280e9aa7f1d..077a726d09604a 100644 --- a/airflow/models/dagrun.py +++ b/airflow/models/dagrun.py @@ -159,7 +159,6 @@ class DagRun(Base, LoggingMixin): Index("dag_id_state", dag_id, _state), UniqueConstraint("dag_id", "execution_date", name="dag_run_dag_id_execution_date_key"), UniqueConstraint("dag_id", "run_id", name="dag_run_dag_id_run_id_key"), - Index("idx_last_scheduling_decision", last_scheduling_decision), Index("idx_dag_run_dag_id", dag_id), Index( "idx_dag_run_running_dags", diff --git a/docs/apache-airflow/img/airflow_erd.sha256 b/docs/apache-airflow/img/airflow_erd.sha256 index cdcf039446dd59..439fae1e056dd8 100644 --- a/docs/apache-airflow/img/airflow_erd.sha256 +++ b/docs/apache-airflow/img/airflow_erd.sha256 @@ -1 +1 @@ -77757e21aee500cb7fe7fd75e0f158633a0037d4d74e6f45eb14238f901ebacd \ No newline at end of file +3800f2d692be3ed255727b5b07767a4e6e35fd65b6d77eefcb4404d0b243b7ba \ No newline at end of file diff --git a/docs/apache-airflow/img/airflow_erd.svg b/docs/apache-airflow/img/airflow_erd.svg index fb280ee0ea7fce..01a3702c74a533 100644 --- a/docs/apache-airflow/img/airflow_erd.svg +++ b/docs/apache-airflow/img/airflow_erd.svg @@ -1435,14 +1435,14 @@ task_instance--xcom -1 +0..N 1 task_instance--xcom -0..N +1 1 diff --git a/docs/apache-airflow/migrations-ref.rst b/docs/apache-airflow/migrations-ref.rst index d858879d545fc2..f8ce355b184be1 100644 --- a/docs/apache-airflow/migrations-ref.rst +++ b/docs/apache-airflow/migrations-ref.rst @@ -39,7 +39,10 @@ Here's the list of all the Database Migrations that are executed via when you ru +---------------------------------+-------------------+-------------------+--------------------------------------------------------------+ | Revision ID | Revises ID | Airflow Version | Description | +=================================+===================+===================+==============================================================+ -| ``677fdbb7fc54`` (head) | ``1949afb29106`` | ``2.10.0`` | add new executor field to db | +| ``bff083ad727d`` (head) | ``677fdbb7fc54`` | ``2.9.1`` | Remove ``idx_last_scheduling_decision`` index on | +| | | | last_scheduling_decision in dag_run table | ++---------------------------------+-------------------+-------------------+--------------------------------------------------------------+ +| ``677fdbb7fc54`` | ``1949afb29106`` | ``2.10.0`` | add new executor field to db | +---------------------------------+-------------------+-------------------+--------------------------------------------------------------+ | ``1949afb29106`` | ``ee1467d4aa35`` | ``2.9.0`` | update trigger kwargs type and encrypt | +---------------------------------+-------------------+-------------------+--------------------------------------------------------------+