You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ep...@apache.org on 2024/08/13 08:06:00 UTC
(airflow) branch main updated: Prune the migration files for Airflow 3 (#41120)
This is an automated email from the ASF dual-hosted git repository.
ephraimanierobi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new ba4d4a057d Prune the migration files for Airflow 3 (#41120)
ba4d4a057d is described below
commit ba4d4a057d54a0650c6393b727c1a19ed9b93548
Author: Ephraim Anierobi <sp...@gmail.com>
AuthorDate: Tue Aug 13 09:05:54 2024 +0100
Prune the migration files for Airflow 3 (#41120)
* Prune the migration files for Airflow 3
For a long time now, we have been able to create the metadata
database from the ORM without going through the migration files.
However, the migration files were not pruned because it would
result in users being unable to roll back to a previous version.
There's now an opportunity to prune this and start afresh.
The migration files are getting more significant, and there are
benefits to this pruning. Top in my mind is that the FAB migrations
will no longer be in the airflow migration file, which would help in
removing FAB from the Airflow core.
This change also means we can no longer create a new database from the
migration file. We can only do that through the ORM. I considered creating
the 'current schema' in the migration file, which means having the database
representation in the migration file and helping to create it from scratch.
I dropped the idea because there would be elements of FAB in the migration files again.
Due to this change, the db command option "--use-migration-files" was removed
since this creates the database from the migration file.
* fixup! Prune the migration files for Airflow 3
---
.github/actions/migration_tests/action.yml | 4 +-
airflow/cli/cli_config.py | 10 +-
airflow/cli/commands/db_command.py | 3 +-
.../versions/0001_1_5_0_current_schema.py | 243 ------------
...2_10_0_dag_schedule_dataset_alias_reference.py} | 4 +-
.../versions/0002_1_5_0_create_is_encrypted.py | 66 ----
.../versions/0003_1_5_0_for_compatibility.py | 42 --
.../0004_1_5_0_more_logging_into_task_isntance.py | 47 ---
.../versions/0005_1_5_2_job_id_indices.py | 44 ---
.../versions/0006_1_6_0_adding_extra_to_log.py | 45 ---
.../migrations/versions/0007_1_6_0_add_dagrun.py | 58 ---
.../versions/0008_1_6_0_task_duration.py | 53 ---
.../versions/0009_1_6_0_dagrun_config.py | 45 ---
.../0010_1_6_2_add_password_column_to_user.py | 45 ---
.../versions/0011_1_6_2_dagrun_start_end.py | 47 ---
...7_0_add_notification_sent_column_to_sla_miss.py | 45 ---
..._1_7_0_add_a_column_to_track_the_encryption_.py | 45 ---
...4_1_7_0_add_is_encrypted_column_to_variable_.py | 45 ---
.../versions/0015_1_7_1_rename_user_table.py | 44 ---
.../versions/0016_1_7_1_add_ti_state_index.py | 44 ---
.../0017_1_7_1_add_task_fails_journal_table.py | 57 ---
.../versions/0018_1_7_1_add_dag_stats_table.py | 54 ---
...1_7_1_add_fractional_seconds_to_mysql_tables.py | 124 ------
.../versions/0020_1_7_1_xcom_dag_task_indices.py | 46 ---
.../0021_1_7_1_add_pid_field_to_taskinstance.py | 47 ---
..._7_1_add_dag_id_state_index_on_dag_run_table.py | 44 ---
..._1_8_2_add_max_tries_column_to_task_instance.py | 128 ------
..._1_8_2_make_xcom_value_column_a_large_binary.py | 52 ---
.../versions/0025_1_8_2_add_ti_job_id_index.py | 44 ---
.../0026_1_8_2_increase_text_size_for_mysql.py | 49 ---
.../0027_1_10_0_add_time_zone_awareness.py | 430 ---------------------
...1_10_0_add_kubernetes_resource_checkpointing.py | 71 ----
..._1_10_0_add_executor_config_to_task_instance.py | 48 ---
...0_1_10_0_add_kubernetes_scheduler_uniqueness.py | 61 ---
.../migrations/versions/0031_1_10_0_merge_heads.py | 41 --
.../0032_1_10_0_fix_mysql_not_null_constraint.py | 55 ---
.../versions/0033_1_10_0_fix_sqlite_foreign_key.py | 75 ----
.../versions/0034_1_10_0_index_taskfail.py | 45 ---
.../versions/0035_1_10_2_add_idx_log_dag.py | 44 ---
.../0036_1_10_2_add_index_to_taskinstance.py | 44 ---
.../0037_1_10_2_add_task_reschedule_table.py | 75 ----
.../versions/0038_1_10_2_add_sm_dag_index.py | 43 ---
.../versions/0039_1_10_2_add_superuser_field.py | 44 ---
.../versions/0040_1_10_3_add_fields_to_dag.py | 47 ---
.../0041_1_10_3_add_schedule_interval_to_dag.py | 45 ---
..._1_10_3_task_reschedule_fk_on_cascade_delete.py | 58 ---
...3_1_10_4_make_taskinstance_pool_not_nullable.py | 108 ------
.../0044_1_10_7_add_serialized_dag_table.py | 103 -----
.../versions/0045_1_10_7_add_root_dag_id_to_dag.py | 51 ---
...0_5_change_datetime_to_datetime2_6_on_mssql_.py | 356 -----------------
.../0047_1_10_4_increase_queue_name_size_limit.py | 55 ---
.../versions/0048_1_10_3_remove_dag_stat_table.py | 54 ---
.../migrations/versions/0049_1_10_7_merge_heads.py | 42 --
...10_7_increase_length_for_connection_password.py | 59 ---
.../versions/0051_1_10_8_add_dagtags_table.py | 58 ---
..._10_10_add_pool_slots_field_to_task_instance.py | 45 ---
...0_10_add_rendered_task_instance_fields_table.py | 70 ----
.../versions/0054_1_10_10_add_dag_code_table.py | 89 -----
..._11_add_precision_to_execution_date_in_mysql.py | 58 ---
...10_12_add_dag_hash_column_to_serialized_dag_.py | 50 ---
.../versions/0057_1_10_13_add_fab_tables.py | 185 ---------
...1_10_13_increase_length_of_fab_ab_view_menu_.py | 98 -----
.../versions/0059_2_0_0_drop_user_and_chart.py | 115 ------
.../0060_2_0_0_remove_id_column_from_xcom.py | 127 ------
.../0061_2_0_0_increase_length_of_pool_name.py | 52 ---
.../versions/0062_2_0_0_add_dagrun_run_type.py | 92 -----
.../0063_2_0_0_set_conn_type_as_non_nullable.py | 70 ----
.../0064_2_0_0_add_unique_constraint_to_conn_id.py | 60 ---
.../0065_2_0_0_update_schema_for_smart_sensor.py | 81 ----
.../0066_2_0_0_add_queued_by_job_id_to_ti.py | 49 ---
.../0067_2_0_0_add_external_executor_id_to_ti.py | 49 ---
.../0068_2_0_0_drop_kuberesourceversion_and_.py | 108 ------
...2_0_0_add_scheduling_decision_to_dagrun_and_.py | 113 ------
...0_fix_mssql_exec_date_rendered_task_instance.py | 74 ----
.../0071_2_0_0_add_job_id_to_dagrun_table.py | 47 ---
...072_2_0_0_add_k8s_yaml_to_rendered_templates.py | 55 ---
.../versions/0073_2_0_0_prefix_dag_permissions.py | 241 ------------
.../0074_2_0_0_resource_based_permissions.py | 354 -----------------
...75_2_0_0_add_description_field_to_connection.py | 57 ---
..._0_0_fix_description_field_in_connection_to_.py | 81 ----
...2_0_0_change_field_in_dagcode_to_mediumtext_.py | 50 ---
..._2_0_1_remove_can_read_permission_on_config_.py | 74 ----
...0_2_increase_size_of_connection_extra_field_.py | 59 ---
.../0080_2_0_2_change_default_pool_slots_to_1.py | 61 ---
.../0081_2_0_2_rename_last_scheduler_run_column.py | 68 ----
..._1_0_increase_pool_name_size_in_taskinstance.py | 56 ---
...0083_2_1_0_add_description_field_to_variable.py | 49 ---
..._1_0_resource_based_permissions_for_default_.py | 206 ----------
...5_2_1_3_add_queued_at_column_to_dagrun_table.py | 50 ---
..._1_4_add_max_active_runs_column_to_dagmodel_.py | 63 ---
..._2_1_4_add_index_on_state_dag_id_for_queued_.py | 55 ---
.../0088_2_2_0_improve_mssql_compatibility.py | 221 -----------
...89_2_2_0_make_xcom_pkey_columns_non_nullable.py | 64 ---
..._2_0_rename_concurrency_column_in_dag_table_.py | 66 ----
.../0091_2_2_0_add_trigger_table_and_task_info.py | 72 ----
...ta_interval_start_end_to_dagmodel_and_dagrun.py | 59 ---
.../0093_2_2_0_taskinstance_keyed_to_dagrun.py | 409 --------------------
...2_3_add_has_import_errors_column_to_dagmodel.py | 48 ---
.../versions/0095_2_2_4_add_session_table_to_db.py | 57 ---
.../0096_2_2_4_adding_index_for_dag_id_in_job.py | 46 ---
..._2_3_0_increase_length_of_email_and_username.py | 84 ----
...098_2_3_0_added_timetable_description_column.py | 54 ---
...9_2_3_0_add_task_log_filename_template_model.py | 66 ----
...2_3_0_add_taskmap_and_map_id_on_taskinstance.py | 127 ------
..._2_3_0_add_data_compressed_to_serialized_dag.py | 49 ---
.../0102_2_3_0_switch_xcom_table_to_use_run_id.py | 181 ---------
.../0103_2_3_0_add_callback_request_table.py | 60 ---
...3_0_migrate_rtif_to_use_run_id_and_map_index.py | 170 --------
.../0105_2_3_0_add_map_index_to_taskfail.py | 158 --------
...on_for_fab_tables_to_add_missing_constraints.py | 109 ------
.../versions/0107_2_3_0_add_map_index_to_log.py | 47 ---
.../versions/0108_2_3_0_default_dag_view_grid.py | 57 ---
.../0109_2_3_1_add_index_for_event_in_log.py | 46 ---
...0110_2_3_2_add_cascade_to_dag_tag_foreignkey.py | 83 ----
.../0111_2_3_3_add_indexes_for_cascade_deletes.py | 99 -----
.../versions/0112_2_4_0_add_dagwarning_model.py | 62 ---
.../0113_2_4_0_compare_types_between_orm_and_db.py | 264 -------------
.../versions/0114_2_4_0_add_dataset_model.py | 192 ---------
.../versions/0115_2_4_0_remove_smart_sensors.py | 78 ----
.../0116_2_4_0_add_dag_owner_attributes_table.py | 56 ---
..._2_4_0_add_processor_subdir_to_dagmodel_and_.py | 78 ----
.../versions/0118_2_4_2_add_missing_autoinc_fab.py | 80 ----
...e_insensitive_unique_constraint_for_username.py | 90 -----
.../0120_2_5_0_add_updated_at_to_dagrun_and_ti.py | 58 ---
...21_2_5_0_add_dagrunnote_and_taskinstancenote.py | 95 -----
.../0122_2_5_0_add_is_orphaned_to_datasetmodel.py | 58 ---
.../0123_2_6_0_add_dttm_index_on_log_table.py | 47 ---
...0_increase_length_of_user_identifier_columns.py | 111 ------
.../0125_2_6_2_add_onupdate_cascade_to_taskmap.py | 64 ---
.../0126_2_7_0_add_index_to_task_instance_table.py | 55 ---
.../0127_2_7_0_add_custom_operator_name_column.py | 52 ---
...28_2_7_0_add_include_deferred_column_to_pool.py | 54 ---
.../0129_2_8_0_add_clear_number_to_dag_run.py | 64 ---
..._0_add_owner_display_name_to_audit_log_table.py | 52 ---
...31_2_8_0_make_connection_login_password_text.py | 60 ---
...0132_2_8_0_add_processor_subdir_import_error.py | 55 ---
.../0133_2_8_1_refactor_dag_run_indexes.py | 52 ---
...2_9_0_add_rendered_map_index_to_taskinstance.py | 50 ---
...audit_log_table_and_change_event_name_length.py | 66 ----
...136_2_9_0_add_dataset_expression_in_dagmodel.py | 55 ---
...2_9_0_adding_adding_max_failure_runs_column_.py | 56 ---
..._2_9_0_make_xcom_value_to_longblob_for_mysql.py | 55 ---
...139_2_9_0_add_display_name_for_dag_and_task_.py | 50 ---
.../0140_2_9_0_update_trigger_kwargs_type.py | 93 -----
...1_2_9_2_remove_idx_last_scheduling_decision_.py | 47 ---
...nconsistency_between_ORM_and_migration_files.py | 298 --------------
...dexes_on_dag_id_column_in_referencing_tables.py | 106 -----
.../0144_2_10_0_add_new_executor_field_to_db.py | 48 ---
...2_10_0_added_dagpriorityparsingrequest_table.py | 53 ---
.../0146_2_10_0_add_task_instance_history.py | 106 -----
.../versions/0147_2_10_0_add_dataset_alias.py | 60 ---
.../0148_2_10_0_dataset_alias_dataset_event.py | 68 ----
.../0149_2_10_0_add_try_number_to_audit_log.py | 54 ---
.../versions/0150_2_10_0_dataset_alias_dataset.py | 69 ----
airflow/models/__init__.py | 1 +
airflow/utils/db.py | 44 +--
contributing-docs/13_metadata_database_updates.rst | 5 +-
docs/apache-airflow/img/airflow_erd.sha256 | 2 +-
docs/apache-airflow/img/airflow_erd.svg | 234 +++++------
docs/apache-airflow/migrations-ref.rst | 338 +---------------
tests/cli/commands/test_db_command.py | 88 +++--
tests/conftest.py | 7 +-
tests/utils/test_db.py | 41 +-
163 files changed, 200 insertions(+), 13050 deletions(-)
diff --git a/.github/actions/migration_tests/action.yml b/.github/actions/migration_tests/action.yml
index a1d098713a..d805f5a825 100644
--- a/.github/actions/migration_tests/action.yml
+++ b/.github/actions/migration_tests/action.yml
@@ -26,7 +26,7 @@ runs:
run: >
breeze shell "airflow db reset --skip-init -y &&
airflow db migrate --to-revision heads &&
- airflow db downgrade -r e959f08ac86c -y &&
+ airflow db downgrade -r 22ed7efa9da2 -y &&
airflow db migrate"
env:
COMPOSE_PROJECT_NAME: "docker-compose"
@@ -40,7 +40,7 @@ runs:
run: >
breeze shell "airflow db reset -y &&
airflow db migrate &&
- airflow db downgrade -r e959f08ac86c -y &&
+ airflow db downgrade -r 22ed7efa9da2 -y &&
airflow db migrate"
COMPOSE_PROJECT_NAME: "docker-compose"
env:
diff --git a/airflow/cli/cli_config.py b/airflow/cli/cli_config.py
index abefb5cd63..7814c86bd6 100644
--- a/airflow/cli/cli_config.py
+++ b/airflow/cli/cli_config.py
@@ -704,12 +704,6 @@ ARG_DB_SKIP_INIT = Arg(
action="store_true",
default=False,
)
-ARG_DB_USE_MIGRATION_FILES = Arg(
- ("-m", "--use-migration-files"),
- help="Use migration files to perform migration",
- action="store_true",
- default=False,
-)
# webserver
ARG_PORT = Arg(
@@ -1546,7 +1540,7 @@ DB_COMMANDS = (
name="reset",
help="Burn down and rebuild the metadata database",
func=lazy_load_command("airflow.cli.commands.db_command.resetdb"),
- args=(ARG_YES, ARG_DB_SKIP_INIT, ARG_DB_USE_MIGRATION_FILES, ARG_VERBOSE),
+ args=(ARG_YES, ARG_DB_SKIP_INIT, ARG_VERBOSE),
),
ActionCommand(
name="upgrade",
@@ -1566,7 +1560,6 @@ DB_COMMANDS = (
ARG_DB_FROM_REVISION,
ARG_DB_FROM_VERSION,
ARG_DB_RESERIALIZE_DAGS,
- ARG_DB_USE_MIGRATION_FILES,
ARG_VERBOSE,
),
hide=True,
@@ -1590,7 +1583,6 @@ DB_COMMANDS = (
ARG_DB_FROM_REVISION,
ARG_DB_FROM_VERSION,
ARG_DB_RESERIALIZE_DAGS,
- ARG_DB_USE_MIGRATION_FILES,
ARG_VERBOSE,
),
),
diff --git a/airflow/cli/commands/db_command.py b/airflow/cli/commands/db_command.py
index 737dfa1ed4..776dabcdea 100644
--- a/airflow/cli/commands/db_command.py
+++ b/airflow/cli/commands/db_command.py
@@ -63,7 +63,7 @@ def resetdb(args):
print(f"DB: {settings.engine.url!r}")
if not (args.yes or input("This will drop existing tables if they exist. Proceed? (y/n)").upper() == "Y"):
raise SystemExit("Cancelled")
- db.resetdb(skip_init=args.skip_init, use_migration_files=args.use_migration_files)
+ db.resetdb(skip_init=args.skip_init)
def upgradedb(args):
@@ -142,7 +142,6 @@ def migratedb(args):
from_revision=from_revision,
show_sql_only=args.show_sql_only,
reserialize_dags=args.reserialize_dags,
- use_migration_files=args.use_migration_files,
)
if not args.show_sql_only:
print("Database migrating done!")
diff --git a/airflow/migrations/versions/0001_1_5_0_current_schema.py b/airflow/migrations/versions/0001_1_5_0_current_schema.py
deleted file mode 100644
index 0f3dc21668..0000000000
--- a/airflow/migrations/versions/0001_1_5_0_current_schema.py
+++ /dev/null
@@ -1,243 +0,0 @@
-#
-# 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.
-"""
-current schema.
-
-Revision ID: e3a246e0dc1
-Revises:
-Create Date: 2015-08-18 16:35:00.883495
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import func, inspect
-
-from airflow.migrations.db_types import StringID
-
-# revision identifiers, used by Alembic.
-revision = "e3a246e0dc1"
-down_revision = None
-branch_labels = None
-depends_on = None
-airflow_version = "1.5.0"
-
-
-def upgrade():
- conn = op.get_bind()
- inspector = inspect(conn)
- tables = inspector.get_table_names()
-
- if "connection" not in tables:
- op.create_table(
- "connection",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("conn_id", StringID(), nullable=True),
- sa.Column("conn_type", sa.String(length=500), nullable=True),
- sa.Column("host", sa.String(length=500), nullable=True),
- sa.Column("schema", sa.String(length=500), nullable=True),
- sa.Column("login", sa.String(length=500), nullable=True),
- sa.Column("password", sa.String(length=500), nullable=True),
- sa.Column("port", sa.Integer(), nullable=True),
- sa.Column("extra", sa.String(length=5000), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- )
- if "dag" not in tables:
- op.create_table(
- "dag",
- sa.Column("dag_id", StringID(), nullable=False),
- sa.Column("is_paused", sa.Boolean(), nullable=True),
- sa.Column("is_subdag", sa.Boolean(), nullable=True),
- sa.Column("is_active", sa.Boolean(), nullable=True),
- sa.Column("last_scheduler_run", sa.DateTime(), nullable=True),
- sa.Column("last_pickled", sa.DateTime(), nullable=True),
- sa.Column("last_expired", sa.DateTime(), nullable=True),
- sa.Column("scheduler_lock", sa.Boolean(), nullable=True),
- sa.Column("pickle_id", sa.Integer(), nullable=True),
- sa.Column("fileloc", sa.String(length=2000), nullable=True),
- sa.Column("owners", sa.String(length=2000), nullable=True),
- sa.PrimaryKeyConstraint("dag_id"),
- )
- if "dag_pickle" not in tables:
- op.create_table(
- "dag_pickle",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("pickle", sa.PickleType(), nullable=True),
- sa.Column("created_dttm", sa.DateTime(), nullable=True),
- sa.Column("pickle_hash", sa.BigInteger(), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- )
- if "import_error" not in tables:
- op.create_table(
- "import_error",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("timestamp", sa.DateTime(), nullable=True),
- sa.Column("filename", sa.String(length=1024), nullable=True),
- sa.Column("stacktrace", sa.Text(), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- )
- if "job" not in tables:
- op.create_table(
- "job",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("dag_id", sa.String(length=250), nullable=True),
- sa.Column("state", sa.String(length=20), nullable=True),
- sa.Column("job_type", sa.String(length=30), nullable=True),
- sa.Column("start_date", sa.DateTime(), nullable=True),
- sa.Column("end_date", sa.DateTime(), nullable=True),
- sa.Column("latest_heartbeat", sa.DateTime(), nullable=True),
- sa.Column("executor_class", sa.String(length=500), nullable=True),
- sa.Column("hostname", sa.String(length=500), nullable=True),
- sa.Column("unixname", sa.String(length=1000), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- )
- op.create_index("job_type_heart", "job", ["job_type", "latest_heartbeat"], unique=False)
- if "log" not in tables:
- op.create_table(
- "log",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("dttm", sa.DateTime(), nullable=True),
- sa.Column("dag_id", StringID(), nullable=True),
- sa.Column("task_id", StringID(), nullable=True),
- sa.Column("event", sa.String(length=30), nullable=True),
- sa.Column("execution_date", sa.DateTime(), nullable=True),
- sa.Column("owner", sa.String(length=500), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- )
- if "sla_miss" not in tables:
- op.create_table(
- "sla_miss",
- sa.Column("task_id", StringID(), nullable=False),
- sa.Column("dag_id", StringID(), nullable=False),
- sa.Column("execution_date", sa.DateTime(), nullable=False),
- sa.Column("email_sent", sa.Boolean(), nullable=True),
- sa.Column("timestamp", sa.DateTime(), nullable=True),
- sa.Column("description", sa.Text(), nullable=True),
- sa.PrimaryKeyConstraint("task_id", "dag_id", "execution_date"),
- )
- if "slot_pool" not in tables:
- op.create_table(
- "slot_pool",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("pool", StringID(length=50), nullable=True),
- sa.Column("slots", sa.Integer(), nullable=True),
- sa.Column("description", sa.Text(), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("pool"),
- )
- if "task_instance" not in tables:
- op.create_table(
- "task_instance",
- sa.Column("task_id", StringID(), nullable=False),
- sa.Column("dag_id", StringID(), nullable=False),
- sa.Column("execution_date", sa.DateTime(), nullable=False),
- sa.Column("start_date", sa.DateTime(), nullable=True),
- sa.Column("end_date", sa.DateTime(), nullable=True),
- sa.Column("duration", sa.Integer(), nullable=True),
- sa.Column("state", sa.String(length=20), nullable=True),
- sa.Column("try_number", sa.Integer(), nullable=True),
- sa.Column("hostname", sa.String(length=1000), nullable=True),
- sa.Column("unixname", sa.String(length=1000), nullable=True),
- sa.Column("job_id", sa.Integer(), nullable=True),
- sa.Column("pool", sa.String(length=50), nullable=True),
- sa.Column("queue", sa.String(length=50), nullable=True),
- sa.Column("priority_weight", sa.Integer(), nullable=True),
- sa.PrimaryKeyConstraint("task_id", "dag_id", "execution_date"),
- )
- op.create_index("ti_dag_state", "task_instance", ["dag_id", "state"], unique=False)
- op.create_index("ti_pool", "task_instance", ["pool", "state", "priority_weight"], unique=False)
- op.create_index(
- "ti_state_lkp", "task_instance", ["dag_id", "task_id", "execution_date", "state"], unique=False
- )
-
- if "user" not in tables:
- op.create_table(
- "user",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("username", StringID(), nullable=True),
- sa.Column("email", sa.String(length=500), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("username"),
- )
- if "variable" not in tables:
- op.create_table(
- "variable",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("key", StringID(), nullable=True),
- sa.Column("val", sa.Text(), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("key"),
- )
- if "chart" not in tables:
- op.create_table(
- "chart",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("label", sa.String(length=200), nullable=True),
- sa.Column("conn_id", sa.String(length=250), nullable=False),
- sa.Column("user_id", sa.Integer(), nullable=True),
- sa.Column("chart_type", sa.String(length=100), nullable=True),
- sa.Column("sql_layout", sa.String(length=50), nullable=True),
- sa.Column("sql", sa.Text(), nullable=True),
- sa.Column("y_log_scale", sa.Boolean(), nullable=True),
- sa.Column("show_datatable", sa.Boolean(), nullable=True),
- sa.Column("show_sql", sa.Boolean(), nullable=True),
- sa.Column("height", sa.Integer(), nullable=True),
- sa.Column("default_params", sa.String(length=5000), nullable=True),
- sa.Column("x_is_date", sa.Boolean(), nullable=True),
- sa.Column("iteration_no", sa.Integer(), nullable=True),
- sa.Column("last_modified", sa.DateTime(), nullable=True),
- sa.ForeignKeyConstraint(
- ["user_id"],
- ["user.id"],
- ),
- sa.PrimaryKeyConstraint("id"),
- )
- if "xcom" not in tables:
- op.create_table(
- "xcom",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("key", StringID(length=512), nullable=True),
- sa.Column("value", sa.PickleType(), nullable=True),
- sa.Column("timestamp", sa.DateTime(), default=func.now, nullable=False),
- sa.Column("execution_date", sa.DateTime(), nullable=False),
- sa.Column("task_id", StringID(), nullable=False),
- sa.Column("dag_id", StringID(), nullable=False),
- sa.PrimaryKeyConstraint("id"),
- )
-
-
-def downgrade():
- op.drop_table("chart")
- op.drop_table("variable")
- op.drop_table("user")
- op.drop_index("ti_state_lkp", table_name="task_instance")
- op.drop_index("ti_pool", table_name="task_instance")
- op.drop_index("ti_dag_state", table_name="task_instance")
- op.drop_table("task_instance")
- op.drop_table("slot_pool")
- op.drop_table("sla_miss")
- op.drop_table("log")
- op.drop_index("job_type_heart", table_name="job")
- op.drop_table("job")
- op.drop_table("import_error")
- op.drop_table("dag_pickle")
- op.drop_table("dag")
- op.drop_table("connection")
- op.drop_table("xcom")
diff --git a/airflow/migrations/versions/0151_2_10_0_dag_schedule_dataset_alias_reference.py b/airflow/migrations/versions/0001_2_10_0_dag_schedule_dataset_alias_reference.py
similarity index 97%
rename from airflow/migrations/versions/0151_2_10_0_dag_schedule_dataset_alias_reference.py
rename to airflow/migrations/versions/0001_2_10_0_dag_schedule_dataset_alias_reference.py
index a577a3eb78..7d8c745206 100644
--- a/airflow/migrations/versions/0151_2_10_0_dag_schedule_dataset_alias_reference.py
+++ b/airflow/migrations/versions/0001_2_10_0_dag_schedule_dataset_alias_reference.py
@@ -20,7 +20,7 @@
Add dag_schedule_dataset_alias_reference table.
Revision ID: 22ed7efa9da2
-Revises: 8684e37832e6
+Revises:
Create Date: 2024-08-05 08:41:47.696495
"""
@@ -35,7 +35,7 @@ from airflow.migrations.db_types import StringID
# revision identifiers, used by Alembic.
revision = "22ed7efa9da2"
-down_revision = "8684e37832e6"
+down_revision = None
branch_labels = None
depends_on = None
airflow_version = "2.10.0"
diff --git a/airflow/migrations/versions/0002_1_5_0_create_is_encrypted.py b/airflow/migrations/versions/0002_1_5_0_create_is_encrypted.py
deleted file mode 100644
index c28a5c4f41..0000000000
--- a/airflow/migrations/versions/0002_1_5_0_create_is_encrypted.py
+++ /dev/null
@@ -1,66 +0,0 @@
-#
-# 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 ``is_encrypted`` column in ``connection`` table.
-
-Revision ID: 1507a7289a2f
-Revises: e3a246e0dc1
-Create Date: 2015-08-18 18:57:51.927315
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import inspect
-
-# revision identifiers, used by Alembic.
-revision = "1507a7289a2f"
-down_revision = "e3a246e0dc1"
-branch_labels = None
-depends_on = None
-airflow_version = "1.5.0"
-
-connectionhelper = sa.Table(
- "connection", sa.MetaData(), sa.Column("id", sa.Integer, primary_key=True), sa.Column("is_encrypted")
-)
-
-
-def upgrade():
- # first check if the user already has this done. This should only be
- # true for users who are upgrading from a previous version of Airflow
- # that predates Alembic integration
- conn = op.get_bind()
- inspector = inspect(conn)
-
- # this will only be true if 'connection' already exists in the db,
- # but not if alembic created it in a previous migration
- if "connection" in inspector.get_table_names():
- col_names = [c["name"] for c in inspector.get_columns("connection")]
- if "is_encrypted" in col_names:
- return
-
- op.add_column("connection", sa.Column("is_encrypted", sa.Boolean, unique=False, default=False))
-
- conn = op.get_bind()
- conn.execute(connectionhelper.update().values(is_encrypted=False))
-
-
-def downgrade():
- op.drop_column("connection", "is_encrypted")
diff --git a/airflow/migrations/versions/0003_1_5_0_for_compatibility.py b/airflow/migrations/versions/0003_1_5_0_for_compatibility.py
deleted file mode 100644
index ed045e2b86..0000000000
--- a/airflow/migrations/versions/0003_1_5_0_for_compatibility.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# 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.
-"""
-Maintain history for compatibility with earlier migrations.
-
-Revision ID: 13eb55f81627
-Revises: 1507a7289a2f
-Create Date: 2015-08-23 05:12:49.732174
-
-"""
-
-from __future__ import annotations
-
-# revision identifiers, used by Alembic.
-revision = "13eb55f81627"
-down_revision = "1507a7289a2f"
-branch_labels = None
-depends_on = None
-airflow_version = "1.5.0"
-
-
-def upgrade():
- pass
-
-
-def downgrade():
- pass
diff --git a/airflow/migrations/versions/0004_1_5_0_more_logging_into_task_isntance.py b/airflow/migrations/versions/0004_1_5_0_more_logging_into_task_isntance.py
deleted file mode 100644
index d844fd8813..0000000000
--- a/airflow/migrations/versions/0004_1_5_0_more_logging_into_task_isntance.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# 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 ``operator`` and ``queued_dttm`` to ``task_instance`` table.
-
-Revision ID: 338e90f54d61
-Revises: 13eb55f81627
-Create Date: 2015-08-25 06:09:20.460147
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "338e90f54d61"
-down_revision = "13eb55f81627"
-branch_labels = None
-depends_on = None
-airflow_version = "1.5.0"
-
-
-def upgrade():
- op.add_column("task_instance", sa.Column("operator", sa.String(length=1000), nullable=True))
- op.add_column("task_instance", sa.Column("queued_dttm", sa.DateTime(), nullable=True))
-
-
-def downgrade():
- op.drop_column("task_instance", "queued_dttm")
- op.drop_column("task_instance", "operator")
diff --git a/airflow/migrations/versions/0005_1_5_2_job_id_indices.py b/airflow/migrations/versions/0005_1_5_2_job_id_indices.py
deleted file mode 100644
index 31dbdb58ca..0000000000
--- a/airflow/migrations/versions/0005_1_5_2_job_id_indices.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# 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 indices in ``job`` table.
-
-Revision ID: 52d714495f0
-Revises: 338e90f54d61
-Create Date: 2015-10-20 03:17:01.962542
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "52d714495f0"
-down_revision = "338e90f54d61"
-branch_labels = None
-depends_on = None
-airflow_version = "1.5.2"
-
-
-def upgrade():
- op.create_index("idx_job_state_heartbeat", "job", ["state", "latest_heartbeat"], unique=False)
-
-
-def downgrade():
- op.drop_index("idx_job_state_heartbeat", table_name="job")
diff --git a/airflow/migrations/versions/0006_1_6_0_adding_extra_to_log.py b/airflow/migrations/versions/0006_1_6_0_adding_extra_to_log.py
deleted file mode 100644
index d2361e50de..0000000000
--- a/airflow/migrations/versions/0006_1_6_0_adding_extra_to_log.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# 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.
-"""
-Adding ``extra`` column to ``Log`` table.
-
-Revision ID: 502898887f84
-Revises: 52d714495f0
-Create Date: 2015-11-03 22:50:49.794097
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "502898887f84"
-down_revision = "52d714495f0"
-branch_labels = None
-depends_on = None
-airflow_version = "1.6.0"
-
-
-def upgrade():
- op.add_column("log", sa.Column("extra", sa.Text(), nullable=True))
-
-
-def downgrade():
- op.drop_column("log", "extra")
diff --git a/airflow/migrations/versions/0007_1_6_0_add_dagrun.py b/airflow/migrations/versions/0007_1_6_0_add_dagrun.py
deleted file mode 100644
index 692332d5f0..0000000000
--- a/airflow/migrations/versions/0007_1_6_0_add_dagrun.py
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# 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 ``dag_run`` table.
-
-Revision ID: 1b38cef5b76e
-Revises: 502898887f84
-Create Date: 2015-10-27 08:31:48.475140
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.migrations.db_types import StringID
-
-# revision identifiers, used by Alembic.
-revision = "1b38cef5b76e"
-down_revision = "502898887f84"
-branch_labels = None
-depends_on = None
-airflow_version = "1.6.0"
-
-
-def upgrade():
- op.create_table(
- "dag_run",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("dag_id", StringID(), nullable=True),
- sa.Column("execution_date", sa.DateTime(), nullable=True),
- sa.Column("state", sa.String(length=50), nullable=True),
- sa.Column("run_id", StringID(), nullable=True),
- sa.Column("external_trigger", sa.Boolean(), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("dag_id", "execution_date"),
- sa.UniqueConstraint("dag_id", "run_id"),
- )
-
-
-def downgrade():
- op.drop_table("dag_run")
diff --git a/airflow/migrations/versions/0008_1_6_0_task_duration.py b/airflow/migrations/versions/0008_1_6_0_task_duration.py
deleted file mode 100644
index 2e6c1e2de8..0000000000
--- a/airflow/migrations/versions/0008_1_6_0_task_duration.py
+++ /dev/null
@@ -1,53 +0,0 @@
-#
-# 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.
-"""
-Change ``task_instance.task_duration`` type to ``FLOAT``.
-
-Revision ID: 2e541a1dcfed
-Revises: 1b38cef5b76e
-Create Date: 2015-10-28 20:38:41.266143
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy.dialects import mysql
-
-# revision identifiers, used by Alembic.
-revision = "2e541a1dcfed"
-down_revision = "1b38cef5b76e"
-branch_labels = None
-depends_on = None
-airflow_version = "1.6.0"
-
-
-def upgrade():
- # use batch_alter_table to support SQLite workaround
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.alter_column(
- "duration",
- existing_type=mysql.INTEGER(display_width=11),
- type_=sa.Float(),
- existing_nullable=True,
- )
-
-
-def downgrade():
- pass
diff --git a/airflow/migrations/versions/0009_1_6_0_dagrun_config.py b/airflow/migrations/versions/0009_1_6_0_dagrun_config.py
deleted file mode 100644
index 00ffe32ab0..0000000000
--- a/airflow/migrations/versions/0009_1_6_0_dagrun_config.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# 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 ``conf`` column in ``dag_run`` table.
-
-Revision ID: 40e67319e3a9
-Revises: 2e541a1dcfed
-Create Date: 2015-10-29 08:36:31.726728
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "40e67319e3a9"
-down_revision = "2e541a1dcfed"
-branch_labels = None
-depends_on = None
-airflow_version = "1.6.0"
-
-
-def upgrade():
- op.add_column("dag_run", sa.Column("conf", sa.PickleType(), nullable=True))
-
-
-def downgrade():
- op.drop_column("dag_run", "conf")
diff --git a/airflow/migrations/versions/0010_1_6_2_add_password_column_to_user.py b/airflow/migrations/versions/0010_1_6_2_add_password_column_to_user.py
deleted file mode 100644
index 5c7d251c20..0000000000
--- a/airflow/migrations/versions/0010_1_6_2_add_password_column_to_user.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# 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 ``password`` column to ``user`` table.
-
-Revision ID: 561833c1c74b
-Revises: 40e67319e3a9
-Create Date: 2015-11-30 06:51:25.872557
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "561833c1c74b"
-down_revision = "40e67319e3a9"
-branch_labels = None
-depends_on = None
-airflow_version = "1.6.2"
-
-
-def upgrade():
- op.add_column("user", sa.Column("password", sa.String(255)))
-
-
-def downgrade():
- op.drop_column("user", "password")
diff --git a/airflow/migrations/versions/0011_1_6_2_dagrun_start_end.py b/airflow/migrations/versions/0011_1_6_2_dagrun_start_end.py
deleted file mode 100644
index 32649f91aa..0000000000
--- a/airflow/migrations/versions/0011_1_6_2_dagrun_start_end.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# 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 ``start_date`` and ``end_date`` in ``dag_run`` table.
-
-Revision ID: 4446e08588
-Revises: 561833c1c74b
-Create Date: 2015-12-10 11:26:18.439223
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "4446e08588"
-down_revision = "561833c1c74b"
-branch_labels = None
-depends_on = None
-airflow_version = "1.6.2"
-
-
-def upgrade():
- op.add_column("dag_run", sa.Column("end_date", sa.DateTime(), nullable=True))
- op.add_column("dag_run", sa.Column("start_date", sa.DateTime(), nullable=True))
-
-
-def downgrade():
- op.drop_column("dag_run", "start_date")
- op.drop_column("dag_run", "end_date")
diff --git a/airflow/migrations/versions/0012_1_7_0_add_notification_sent_column_to_sla_miss.py b/airflow/migrations/versions/0012_1_7_0_add_notification_sent_column_to_sla_miss.py
deleted file mode 100644
index d9790ad711..0000000000
--- a/airflow/migrations/versions/0012_1_7_0_add_notification_sent_column_to_sla_miss.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# 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 ``notification_sent`` column to ``sla_miss`` table.
-
-Revision ID: bbc73705a13e
-Revises: 4446e08588
-Create Date: 2016-01-14 18:05:54.871682
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "bbc73705a13e"
-down_revision = "4446e08588"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.0"
-
-
-def upgrade():
- op.add_column("sla_miss", sa.Column("notification_sent", sa.Boolean, default=False))
-
-
-def downgrade():
- op.drop_column("sla_miss", "notification_sent")
diff --git a/airflow/migrations/versions/0013_1_7_0_add_a_column_to_track_the_encryption_.py b/airflow/migrations/versions/0013_1_7_0_add_a_column_to_track_the_encryption_.py
deleted file mode 100644
index d5e7e7a4e8..0000000000
--- a/airflow/migrations/versions/0013_1_7_0_add_a_column_to_track_the_encryption_.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# 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 a column to track the encryption state of the 'Extra' field in connection.
-
-Revision ID: bba5a7cfc896
-Revises: bbc73705a13e
-Create Date: 2016-01-29 15:10:32.656425
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "bba5a7cfc896"
-down_revision = "bbc73705a13e"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.0"
-
-
-def upgrade():
- op.add_column("connection", sa.Column("is_extra_encrypted", sa.Boolean, default=False))
-
-
-def downgrade():
- op.drop_column("connection", "is_extra_encrypted")
diff --git a/airflow/migrations/versions/0014_1_7_0_add_is_encrypted_column_to_variable_.py b/airflow/migrations/versions/0014_1_7_0_add_is_encrypted_column_to_variable_.py
deleted file mode 100644
index 6d2f922c60..0000000000
--- a/airflow/migrations/versions/0014_1_7_0_add_is_encrypted_column_to_variable_.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# 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 ``is_encrypted`` column to variable table.
-
-Revision ID: 1968acfc09e3
-Revises: bba5a7cfc896
-Create Date: 2016-02-02 17:20:55.692295
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "1968acfc09e3"
-down_revision = "bba5a7cfc896"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.0"
-
-
-def upgrade():
- op.add_column("variable", sa.Column("is_encrypted", sa.Boolean, default=False))
-
-
-def downgrade():
- op.drop_column("variable", "is_encrypted")
diff --git a/airflow/migrations/versions/0015_1_7_1_rename_user_table.py b/airflow/migrations/versions/0015_1_7_1_rename_user_table.py
deleted file mode 100644
index 14df410915..0000000000
--- a/airflow/migrations/versions/0015_1_7_1_rename_user_table.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# 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.
-"""
-Rename user table.
-
-Revision ID: 2e82aab8ef20
-Revises: 1968acfc09e3
-Create Date: 2016-04-02 19:28:15.211915
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "2e82aab8ef20"
-down_revision = "1968acfc09e3"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.1"
-
-
-def upgrade():
- op.rename_table("user", "users")
-
-
-def downgrade():
- op.rename_table("users", "user")
diff --git a/airflow/migrations/versions/0016_1_7_1_add_ti_state_index.py b/airflow/migrations/versions/0016_1_7_1_add_ti_state_index.py
deleted file mode 100644
index cb3d846088..0000000000
--- a/airflow/migrations/versions/0016_1_7_1_add_ti_state_index.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# 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 TI state index.
-
-Revision ID: 211e584da130
-Revises: 2e82aab8ef20
-Create Date: 2016-06-30 10:54:24.323588
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "211e584da130"
-down_revision = "2e82aab8ef20"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.1.3"
-
-
-def upgrade():
- op.create_index("ti_state", "task_instance", ["state"], unique=False)
-
-
-def downgrade():
- op.drop_index("ti_state", table_name="task_instance")
diff --git a/airflow/migrations/versions/0017_1_7_1_add_task_fails_journal_table.py b/airflow/migrations/versions/0017_1_7_1_add_task_fails_journal_table.py
deleted file mode 100644
index 92b6e3a006..0000000000
--- a/airflow/migrations/versions/0017_1_7_1_add_task_fails_journal_table.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#
-# 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 ``task_fail`` table.
-
-Revision ID: 64de9cddf6c9
-Revises: 211e584da130
-Create Date: 2016-08-03 14:02:59.203021
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.migrations.db_types import StringID
-
-# revision identifiers, used by Alembic.
-revision = "64de9cddf6c9"
-down_revision = "211e584da130"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.1.3"
-
-
-def upgrade():
- op.create_table(
- "task_fail",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("task_id", StringID(), nullable=False),
- sa.Column("dag_id", StringID(), nullable=False),
- sa.Column("execution_date", sa.DateTime(), nullable=False),
- sa.Column("start_date", sa.DateTime(), nullable=True),
- sa.Column("end_date", sa.DateTime(), nullable=True),
- sa.Column("duration", sa.Integer(), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- )
-
-
-def downgrade():
- op.drop_table("task_fail")
diff --git a/airflow/migrations/versions/0018_1_7_1_add_dag_stats_table.py b/airflow/migrations/versions/0018_1_7_1_add_dag_stats_table.py
deleted file mode 100644
index f10d595d87..0000000000
--- a/airflow/migrations/versions/0018_1_7_1_add_dag_stats_table.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#
-# 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 ``dag_stats`` table.
-
-Revision ID: f2ca10b85618
-Revises: 64de9cddf6c9
-Create Date: 2016-07-20 15:08:28.247537
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.migrations.db_types import StringID
-
-# revision identifiers, used by Alembic.
-revision = "f2ca10b85618"
-down_revision = "64de9cddf6c9"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.1.3"
-
-
-def upgrade():
- op.create_table(
- "dag_stats",
- sa.Column("dag_id", StringID(), nullable=False),
- sa.Column("state", sa.String(length=50), nullable=False),
- sa.Column("count", sa.Integer(), nullable=False, default=0),
- sa.Column("dirty", sa.Boolean(), nullable=False, default=False),
- sa.PrimaryKeyConstraint("dag_id", "state"),
- )
-
-
-def downgrade():
- op.drop_table("dag_stats")
diff --git a/airflow/migrations/versions/0019_1_7_1_add_fractional_seconds_to_mysql_tables.py b/airflow/migrations/versions/0019_1_7_1_add_fractional_seconds_to_mysql_tables.py
deleted file mode 100644
index bed856f390..0000000000
--- a/airflow/migrations/versions/0019_1_7_1_add_fractional_seconds_to_mysql_tables.py
+++ /dev/null
@@ -1,124 +0,0 @@
-#
-# 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 fractional seconds to MySQL tables.
-
-Revision ID: 4addfa1236f1
-Revises: f2ca10b85618
-Create Date: 2016-09-11 13:39:18.592072
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-from sqlalchemy.dialects import mysql
-
-# revision identifiers, used by Alembic.
-revision = "4addfa1236f1"
-down_revision = "f2ca10b85618"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.1.3"
-
-
-def upgrade():
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- op.alter_column(table_name="dag", column_name="last_scheduler_run", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="dag", column_name="last_pickled", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="dag", column_name="last_expired", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(table_name="dag_pickle", column_name="created_dttm", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(table_name="dag_run", column_name="execution_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="dag_run", column_name="start_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="dag_run", column_name="end_date", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(table_name="import_error", column_name="timestamp", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(table_name="job", column_name="start_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="job", column_name="end_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="job", column_name="latest_heartbeat", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(table_name="log", column_name="dttm", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="log", column_name="execution_date", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(
- table_name="sla_miss", column_name="execution_date", type_=mysql.DATETIME(fsp=6), nullable=False
- )
- op.alter_column(table_name="sla_miss", column_name="timestamp", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(table_name="task_fail", column_name="execution_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="task_fail", column_name="start_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="task_fail", column_name="end_date", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(
- table_name="task_instance",
- column_name="execution_date",
- type_=mysql.DATETIME(fsp=6),
- nullable=False,
- )
- op.alter_column(table_name="task_instance", column_name="start_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="task_instance", column_name="end_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="task_instance", column_name="queued_dttm", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(table_name="xcom", column_name="timestamp", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="xcom", column_name="execution_date", type_=mysql.DATETIME(fsp=6))
-
-
-def downgrade():
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- op.alter_column(table_name="dag", column_name="last_scheduler_run", type_=mysql.DATETIME())
- op.alter_column(table_name="dag", column_name="last_pickled", type_=mysql.DATETIME())
- op.alter_column(table_name="dag", column_name="last_expired", type_=mysql.DATETIME())
-
- op.alter_column(table_name="dag_pickle", column_name="created_dttm", type_=mysql.DATETIME())
-
- op.alter_column(table_name="dag_run", column_name="execution_date", type_=mysql.DATETIME())
- op.alter_column(table_name="dag_run", column_name="start_date", type_=mysql.DATETIME())
- op.alter_column(table_name="dag_run", column_name="end_date", type_=mysql.DATETIME())
-
- op.alter_column(table_name="import_error", column_name="timestamp", type_=mysql.DATETIME())
-
- op.alter_column(table_name="job", column_name="start_date", type_=mysql.DATETIME())
- op.alter_column(table_name="job", column_name="end_date", type_=mysql.DATETIME())
- op.alter_column(table_name="job", column_name="latest_heartbeat", type_=mysql.DATETIME())
-
- op.alter_column(table_name="log", column_name="dttm", type_=mysql.DATETIME())
- op.alter_column(table_name="log", column_name="execution_date", type_=mysql.DATETIME())
-
- op.alter_column(
- table_name="sla_miss", column_name="execution_date", type_=mysql.DATETIME(), nullable=False
- )
- op.alter_column(table_name="sla_miss", column_name="timestamp", type_=mysql.DATETIME())
-
- op.alter_column(table_name="task_fail", column_name="execution_date", type_=mysql.DATETIME())
- op.alter_column(table_name="task_fail", column_name="start_date", type_=mysql.DATETIME())
- op.alter_column(table_name="task_fail", column_name="end_date", type_=mysql.DATETIME())
-
- op.alter_column(
- table_name="task_instance", column_name="execution_date", type_=mysql.DATETIME(), nullable=False
- )
- op.alter_column(table_name="task_instance", column_name="start_date", type_=mysql.DATETIME())
- op.alter_column(table_name="task_instance", column_name="end_date", type_=mysql.DATETIME())
- op.alter_column(table_name="task_instance", column_name="queued_dttm", type_=mysql.DATETIME())
-
- op.alter_column(table_name="xcom", column_name="timestamp", type_=mysql.DATETIME())
- op.alter_column(table_name="xcom", column_name="execution_date", type_=mysql.DATETIME())
diff --git a/airflow/migrations/versions/0020_1_7_1_xcom_dag_task_indices.py b/airflow/migrations/versions/0020_1_7_1_xcom_dag_task_indices.py
deleted file mode 100644
index 1f073b3d69..0000000000
--- a/airflow/migrations/versions/0020_1_7_1_xcom_dag_task_indices.py
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-# 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 indices on ``xcom`` table.
-
-Revision ID: 8504051e801b
-Revises: 4addfa1236f1
-Create Date: 2016-11-29 08:13:03.253312
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "8504051e801b"
-down_revision = "4addfa1236f1"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.1.3"
-
-
-def upgrade():
- """Create Index."""
- op.create_index("idx_xcom_dag_task_date", "xcom", ["dag_id", "task_id", "execution_date"], unique=False)
-
-
-def downgrade():
- """Drop Index."""
- op.drop_index("idx_xcom_dag_task_date", table_name="xcom")
diff --git a/airflow/migrations/versions/0021_1_7_1_add_pid_field_to_taskinstance.py b/airflow/migrations/versions/0021_1_7_1_add_pid_field_to_taskinstance.py
deleted file mode 100644
index a27a758b0f..0000000000
--- a/airflow/migrations/versions/0021_1_7_1_add_pid_field_to_taskinstance.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# 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 ``pid`` field to ``TaskInstance``.
-
-Revision ID: 5e7d17757c7a
-Revises: 8504051e801b
-Create Date: 2016-12-07 15:51:37.119478
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "5e7d17757c7a"
-down_revision = "8504051e801b"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.1.3"
-
-
-def upgrade():
- """Add pid column to task_instance table."""
- op.add_column("task_instance", sa.Column("pid", sa.Integer))
-
-
-def downgrade():
- """Drop pid column from task_instance table."""
- op.drop_column("task_instance", "pid")
diff --git a/airflow/migrations/versions/0022_1_7_1_add_dag_id_state_index_on_dag_run_table.py b/airflow/migrations/versions/0022_1_7_1_add_dag_id_state_index_on_dag_run_table.py
deleted file mode 100644
index 5dbaaf58ea..0000000000
--- a/airflow/migrations/versions/0022_1_7_1_add_dag_id_state_index_on_dag_run_table.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# 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 ``dag_id``/``state`` index on ``dag_run`` table.
-
-Revision ID: 127d2bf2dfa7
-Revises: 5e7d17757c7a
-Create Date: 2017-01-25 11:43:51.635667
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "127d2bf2dfa7"
-down_revision = "5e7d17757c7a"
-branch_labels = None
-depends_on = None
-airflow_version = "1.7.1.3"
-
-
-def upgrade():
- op.create_index("dag_id_state", "dag_run", ["dag_id", "state"], unique=False)
-
-
-def downgrade():
- op.drop_index("dag_id_state", table_name="dag_run")
diff --git a/airflow/migrations/versions/0023_1_8_2_add_max_tries_column_to_task_instance.py b/airflow/migrations/versions/0023_1_8_2_add_max_tries_column_to_task_instance.py
deleted file mode 100644
index d69e6c22bb..0000000000
--- a/airflow/migrations/versions/0023_1_8_2_add_max_tries_column_to_task_instance.py
+++ /dev/null
@@ -1,128 +0,0 @@
-# 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 ``max_tries`` column to ``task_instance``.
-
-Revision ID: cc1e65623dc7
-Revises: 127d2bf2dfa7
-Create Date: 2017-06-19 16:53:12.851141
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import Column, Integer, String, inspect
-from sqlalchemy.orm import declarative_base
-
-from airflow import settings
-from airflow.models import DagBag
-
-# revision identifiers, used by Alembic.
-revision = "cc1e65623dc7"
-down_revision = "127d2bf2dfa7"
-branch_labels = None
-depends_on = None
-airflow_version = "1.8.2"
-
-Base = declarative_base()
-BATCH_SIZE = 5000
-
-
-class TaskInstance(Base): # type: ignore
- """Task Instance class."""
-
- __tablename__ = "task_instance"
-
- task_id = Column(String(), primary_key=True)
- dag_id = Column(String(), primary_key=True)
- execution_date = Column(sa.DateTime, primary_key=True)
- max_tries = Column(Integer)
- try_number = Column(Integer, default=0)
-
-
-def upgrade():
- op.add_column("task_instance", sa.Column("max_tries", sa.Integer, server_default="-1"))
- # Check if table task_instance exist before data migration. This check is
- # needed for database that does not create table until migration finishes.
- # Checking task_instance table exists prevent the error of querying
- # non-existing task_instance table.
- connection = op.get_bind()
- inspector = inspect(connection)
- tables = inspector.get_table_names()
-
- if "task_instance" in tables:
- # Get current session
- sessionmaker = sa.orm.sessionmaker()
- session = sessionmaker(bind=connection)
- if not bool(session.query(TaskInstance).first()):
- return
- dagbag = DagBag(settings.DAGS_FOLDER)
- query = session.query(sa.func.count(TaskInstance.max_tries)).filter(TaskInstance.max_tries == -1)
- # Separate db query in batch to prevent loading entire table
- # into memory and cause out of memory error.
- while query.scalar():
- tis = session.query(TaskInstance).filter(TaskInstance.max_tries == -1).limit(BATCH_SIZE).all()
- for ti in tis:
- dag = dagbag.get_dag(ti.dag_id)
- if not dag or not dag.has_task(ti.task_id):
- # task_instance table might not have the up-to-date
- # information, i.e dag or task might be modified or
- # deleted in dagbag but is reflected in task instance
- # table. In this case we do not retry the task that can't
- # be parsed.
- ti.max_tries = ti.try_number
- else:
- task = dag.get_task(ti.task_id)
- if task.retries:
- ti.max_tries = task.retries
- else:
- ti.max_tries = ti.try_number
- session.merge(ti)
-
- session.commit()
- # Commit the current session.
- session.commit()
-
-
-def downgrade():
- engine = settings.engine
- connection = op.get_bind()
- if engine.dialect.has_table(connection, "task_instance"):
- sessionmaker = sa.orm.sessionmaker()
- session = sessionmaker(bind=connection)
- dagbag = DagBag(settings.DAGS_FOLDER)
- query = session.query(sa.func.count(TaskInstance.max_tries)).filter(TaskInstance.max_tries != -1)
- while query.scalar():
- tis = session.query(TaskInstance).filter(TaskInstance.max_tries != -1).limit(BATCH_SIZE).all()
- for ti in tis:
- dag = dagbag.get_dag(ti.dag_id)
- if not dag or not dag.has_task(ti.task_id):
- ti.try_number = 0
- else:
- task = dag.get_task(ti.task_id)
- # max_tries - try_number is number of times a task instance
- # left to retry by itself. So the current try_number should be
- # max number of self retry (task.retries) minus number of
- # times left for task instance to try the task.
- ti.try_number = max(0, task.retries - (ti.max_tries - ti.try_number))
- ti.max_tries = -1
- session.merge(ti)
- session.commit()
- session.commit()
- op.drop_column("task_instance", "max_tries")
diff --git a/airflow/migrations/versions/0024_1_8_2_make_xcom_value_column_a_large_binary.py b/airflow/migrations/versions/0024_1_8_2_make_xcom_value_column_a_large_binary.py
deleted file mode 100644
index 679374f580..0000000000
--- a/airflow/migrations/versions/0024_1_8_2_make_xcom_value_column_a_large_binary.py
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# 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.
-"""
-Make xcom value column a large binary.
-
-Revision ID: bdaa763e6c56
-Revises: cc1e65623dc7
-Create Date: 2017-08-14 16:06:31.568971
-
-"""
-
-from __future__ import annotations
-
-import dill
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "bdaa763e6c56"
-down_revision = "cc1e65623dc7"
-branch_labels = None
-depends_on = None
-airflow_version = "1.8.2"
-
-
-def upgrade():
- # There can be data truncation here as LargeBinary can be smaller than the pickle
- # type.
- # use batch_alter_table to support SQLite workaround
- with op.batch_alter_table("xcom") as batch_op:
- batch_op.alter_column("value", type_=sa.LargeBinary())
-
-
-def downgrade():
- # use batch_alter_table to support SQLite workaround
- with op.batch_alter_table("xcom") as batch_op:
- batch_op.alter_column("value", type_=sa.PickleType(pickler=dill))
diff --git a/airflow/migrations/versions/0025_1_8_2_add_ti_job_id_index.py b/airflow/migrations/versions/0025_1_8_2_add_ti_job_id_index.py
deleted file mode 100644
index 22034be200..0000000000
--- a/airflow/migrations/versions/0025_1_8_2_add_ti_job_id_index.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# 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.
-"""
-Create index on ``job_id`` column in ``task_instance`` table.
-
-Revision ID: 947454bf1dff
-Revises: bdaa763e6c56
-Create Date: 2017-08-15 15:12:13.845074
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "947454bf1dff"
-down_revision = "bdaa763e6c56"
-branch_labels = None
-depends_on = None
-airflow_version = "1.8.2"
-
-
-def upgrade():
- op.create_index("ti_job_id", "task_instance", ["job_id"], unique=False)
-
-
-def downgrade():
- op.drop_index("ti_job_id", table_name="task_instance")
diff --git a/airflow/migrations/versions/0026_1_8_2_increase_text_size_for_mysql.py b/airflow/migrations/versions/0026_1_8_2_increase_text_size_for_mysql.py
deleted file mode 100644
index 1e4371e4da..0000000000
--- a/airflow/migrations/versions/0026_1_8_2_increase_text_size_for_mysql.py
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# 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.
-"""
-Increase text size for MySQL (not relevant for other DBs' text types).
-
-Revision ID: d2ae31099d61
-Revises: 947454bf1dff
-Create Date: 2017-08-18 17:07:16.686130
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-from sqlalchemy.dialects import mysql
-
-# revision identifiers, used by Alembic.
-revision = "d2ae31099d61"
-down_revision = "947454bf1dff"
-branch_labels = None
-depends_on = None
-airflow_version = "1.8.2"
-
-
-def upgrade():
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- op.alter_column(table_name="variable", column_name="val", type_=mysql.MEDIUMTEXT)
-
-
-def downgrade():
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- op.alter_column(table_name="variable", column_name="val", type_=mysql.TEXT)
diff --git a/airflow/migrations/versions/0027_1_10_0_add_time_zone_awareness.py b/airflow/migrations/versions/0027_1_10_0_add_time_zone_awareness.py
deleted file mode 100644
index 78aaa0889f..0000000000
--- a/airflow/migrations/versions/0027_1_10_0_add_time_zone_awareness.py
+++ /dev/null
@@ -1,430 +0,0 @@
-# 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 time zone awareness.
-
-Revision ID: 0e2a74e0fc9f
-Revises: d2ae31099d61
-Create Date: 2017-11-10 22:22:31.326152
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import text
-from sqlalchemy.dialects import mysql
-
-from airflow.exceptions import AirflowException
-
-# revision identifiers, used by Alembic.
-revision = "0e2a74e0fc9f"
-down_revision = "d2ae31099d61"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.0"
-
-
-def upgrade():
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- conn.execute(text("SET time_zone = '+00:00'"))
- cur = conn.execute(text("SELECT @@explicit_defaults_for_timestamp"))
- res = cur.fetchall()
- if res[0][0] == 0:
- raise AirflowException(
- "Global variable explicit_defaults_for_timestamp needs to be on (1) for mysql"
- )
-
- op.alter_column(
- table_name="chart",
- column_name="last_modified",
- type_=mysql.TIMESTAMP(fsp=6),
- )
-
- op.alter_column(
- table_name="dag",
- column_name="last_scheduler_run",
- type_=mysql.TIMESTAMP(fsp=6),
- )
- op.alter_column(table_name="dag", column_name="last_pickled", type_=mysql.TIMESTAMP(fsp=6))
- op.alter_column(table_name="dag", column_name="last_expired", type_=mysql.TIMESTAMP(fsp=6))
-
- op.alter_column(
- table_name="dag_pickle",
- column_name="created_dttm",
- type_=mysql.TIMESTAMP(fsp=6),
- )
-
- op.alter_column(
- table_name="dag_run",
- column_name="execution_date",
- type_=mysql.TIMESTAMP(fsp=6),
- )
- op.alter_column(table_name="dag_run", column_name="start_date", type_=mysql.TIMESTAMP(fsp=6))
- op.alter_column(table_name="dag_run", column_name="end_date", type_=mysql.TIMESTAMP(fsp=6))
-
- op.alter_column(
- table_name="import_error",
- column_name="timestamp",
- type_=mysql.TIMESTAMP(fsp=6),
- )
-
- op.alter_column(table_name="job", column_name="start_date", type_=mysql.TIMESTAMP(fsp=6))
- op.alter_column(table_name="job", column_name="end_date", type_=mysql.TIMESTAMP(fsp=6))
- op.alter_column(
- table_name="job",
- column_name="latest_heartbeat",
- type_=mysql.TIMESTAMP(fsp=6),
- )
-
- op.alter_column(table_name="log", column_name="dttm", type_=mysql.TIMESTAMP(fsp=6))
- op.alter_column(table_name="log", column_name="execution_date", type_=mysql.TIMESTAMP(fsp=6))
-
- op.alter_column(
- table_name="sla_miss",
- column_name="execution_date",
- type_=mysql.TIMESTAMP(fsp=6),
- nullable=False,
- )
- op.alter_column(table_name="sla_miss", column_name="timestamp", type_=mysql.TIMESTAMP(fsp=6))
-
- op.alter_column(
- table_name="task_fail",
- column_name="execution_date",
- type_=mysql.TIMESTAMP(fsp=6),
- )
- op.alter_column(
- table_name="task_fail",
- column_name="start_date",
- type_=mysql.TIMESTAMP(fsp=6),
- )
- op.alter_column(table_name="task_fail", column_name="end_date", type_=mysql.TIMESTAMP(fsp=6))
-
- op.alter_column(
- table_name="task_instance",
- column_name="execution_date",
- type_=mysql.TIMESTAMP(fsp=6),
- nullable=False,
- )
- op.alter_column(
- table_name="task_instance",
- column_name="start_date",
- type_=mysql.TIMESTAMP(fsp=6),
- )
- op.alter_column(
- table_name="task_instance",
- column_name="end_date",
- type_=mysql.TIMESTAMP(fsp=6),
- )
- op.alter_column(
- table_name="task_instance",
- column_name="queued_dttm",
- type_=mysql.TIMESTAMP(fsp=6),
- )
-
- op.alter_column(table_name="xcom", column_name="timestamp", type_=mysql.TIMESTAMP(fsp=6))
- op.alter_column(
- table_name="xcom",
- column_name="execution_date",
- type_=mysql.TIMESTAMP(fsp=6),
- )
- else:
- # sqlite and mssql datetime are fine as is. Therefore, not converting
- if conn.dialect.name in ("sqlite", "mssql"):
- return
-
- # we try to be database agnostic, but not every db (e.g. sqlserver)
- # supports per session time zones
- if conn.dialect.name == "postgresql":
- conn.execute(text("set timezone=UTC"))
-
- op.alter_column(
- table_name="chart",
- column_name="last_modified",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
- op.alter_column(
- table_name="dag",
- column_name="last_scheduler_run",
- type_=sa.TIMESTAMP(timezone=True),
- )
- op.alter_column(
- table_name="dag",
- column_name="last_pickled",
- type_=sa.TIMESTAMP(timezone=True),
- )
- op.alter_column(
- table_name="dag",
- column_name="last_expired",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
- op.alter_column(
- table_name="dag_pickle",
- column_name="created_dttm",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
- op.alter_column(
- table_name="dag_run",
- column_name="execution_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
- op.alter_column(
- table_name="dag_run",
- column_name="start_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
- op.alter_column(
- table_name="dag_run",
- column_name="end_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
- op.alter_column(
- table_name="import_error",
- column_name="timestamp",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
- op.alter_column(
- table_name="job",
- column_name="start_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
- op.alter_column(table_name="job", column_name="end_date", type_=sa.TIMESTAMP(timezone=True))
- op.alter_column(
- table_name="job",
- column_name="latest_heartbeat",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
- op.alter_column(table_name="log", column_name="dttm", type_=sa.TIMESTAMP(timezone=True))
- op.alter_column(
- table_name="log",
- column_name="execution_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
- op.alter_column(
- table_name="sla_miss",
- column_name="execution_date",
- type_=sa.TIMESTAMP(timezone=True),
- nullable=False,
- )
- op.alter_column(
- table_name="sla_miss",
- column_name="timestamp",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
- op.alter_column(
- table_name="task_fail",
- column_name="execution_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
- op.alter_column(
- table_name="task_fail",
- column_name="start_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
- op.alter_column(
- table_name="task_fail",
- column_name="end_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
- op.alter_column(
- table_name="task_instance",
- column_name="execution_date",
- type_=sa.TIMESTAMP(timezone=True),
- nullable=False,
- )
- op.alter_column(
- table_name="task_instance",
- column_name="start_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
- op.alter_column(
- table_name="task_instance",
- column_name="end_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
- op.alter_column(
- table_name="task_instance",
- column_name="queued_dttm",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
- op.alter_column(
- table_name="xcom",
- column_name="timestamp",
- type_=sa.TIMESTAMP(timezone=True),
- )
- op.alter_column(
- table_name="xcom",
- column_name="execution_date",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
-
-def downgrade():
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- conn.execute(text("SET time_zone = '+00:00'"))
- op.alter_column(table_name="chart", column_name="last_modified", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(
- table_name="dag",
- column_name="last_scheduler_run",
- type_=mysql.DATETIME(fsp=6),
- )
- op.alter_column(table_name="dag", column_name="last_pickled", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="dag", column_name="last_expired", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(
- table_name="dag_pickle",
- column_name="created_dttm",
- type_=mysql.DATETIME(fsp=6),
- )
-
- op.alter_column(
- table_name="dag_run",
- column_name="execution_date",
- type_=mysql.DATETIME(fsp=6),
- )
- op.alter_column(table_name="dag_run", column_name="start_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="dag_run", column_name="end_date", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(
- table_name="import_error",
- column_name="timestamp",
- type_=mysql.DATETIME(fsp=6),
- )
-
- op.alter_column(table_name="job", column_name="start_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="job", column_name="end_date", type_=mysql.DATETIME(fsp=6))
- op.alter_column(
- table_name="job",
- column_name="latest_heartbeat",
- type_=mysql.DATETIME(fsp=6),
- )
-
- op.alter_column(table_name="log", column_name="dttm", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="log", column_name="execution_date", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(
- table_name="sla_miss",
- column_name="execution_date",
- type_=mysql.DATETIME(fsp=6),
- nullable=False,
- )
- op.alter_column(table_name="sla_miss", column_name="timestamp", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(
- table_name="task_fail",
- column_name="execution_date",
- type_=mysql.DATETIME(fsp=6),
- )
- op.alter_column(
- table_name="task_fail",
- column_name="start_date",
- type_=mysql.DATETIME(fsp=6),
- )
- op.alter_column(table_name="task_fail", column_name="end_date", type_=mysql.DATETIME(fsp=6))
-
- op.alter_column(
- table_name="task_instance",
- column_name="execution_date",
- type_=mysql.DATETIME(fsp=6),
- nullable=False,
- )
- op.alter_column(
- table_name="task_instance",
- column_name="start_date",
- type_=mysql.DATETIME(fsp=6),
- )
- op.alter_column(
- table_name="task_instance",
- column_name="end_date",
- type_=mysql.DATETIME(fsp=6),
- )
- op.alter_column(
- table_name="task_instance",
- column_name="queued_dttm",
- type_=mysql.DATETIME(fsp=6),
- )
-
- op.alter_column(table_name="xcom", column_name="timestamp", type_=mysql.DATETIME(fsp=6))
- op.alter_column(table_name="xcom", column_name="execution_date", type_=mysql.DATETIME(fsp=6))
- else:
- if conn.dialect.name in ("sqlite", "mssql"):
- return
-
- # we try to be database agnostic, but not every db (e.g. sqlserver)
- # supports per session time zones
- if conn.dialect.name == "postgresql":
- conn.execute(text("set timezone=UTC"))
-
- op.alter_column(table_name="chart", column_name="last_modified", type_=sa.DateTime())
-
- op.alter_column(table_name="dag", column_name="last_scheduler_run", type_=sa.DateTime())
- op.alter_column(table_name="dag", column_name="last_pickled", type_=sa.DateTime())
- op.alter_column(table_name="dag", column_name="last_expired", type_=sa.DateTime())
-
- op.alter_column(table_name="dag_pickle", column_name="created_dttm", type_=sa.DateTime())
-
- op.alter_column(table_name="dag_run", column_name="execution_date", type_=sa.DateTime())
- op.alter_column(table_name="dag_run", column_name="start_date", type_=sa.DateTime())
- op.alter_column(table_name="dag_run", column_name="end_date", type_=sa.DateTime())
-
- op.alter_column(table_name="import_error", column_name="timestamp", type_=sa.DateTime())
-
- op.alter_column(table_name="job", column_name="start_date", type_=sa.DateTime())
- op.alter_column(table_name="job", column_name="end_date", type_=sa.DateTime())
- op.alter_column(table_name="job", column_name="latest_heartbeat", type_=sa.DateTime())
-
- op.alter_column(table_name="log", column_name="dttm", type_=sa.DateTime())
- op.alter_column(table_name="log", column_name="execution_date", type_=sa.DateTime())
-
- op.alter_column(
- table_name="sla_miss",
- column_name="execution_date",
- type_=sa.DateTime(),
- nullable=False,
- )
- op.alter_column(table_name="sla_miss", column_name="timestamp", type_=sa.DateTime())
-
- op.alter_column(table_name="task_fail", column_name="execution_date", type_=sa.DateTime())
- op.alter_column(table_name="task_fail", column_name="start_date", type_=sa.DateTime())
- op.alter_column(table_name="task_fail", column_name="end_date", type_=sa.DateTime())
-
- op.alter_column(
- table_name="task_instance",
- column_name="execution_date",
- type_=sa.DateTime(),
- nullable=False,
- )
- op.alter_column(table_name="task_instance", column_name="start_date", type_=sa.DateTime())
- op.alter_column(table_name="task_instance", column_name="end_date", type_=sa.DateTime())
- op.alter_column(table_name="task_instance", column_name="queued_dttm", type_=sa.DateTime())
-
- op.alter_column(table_name="xcom", column_name="timestamp", type_=sa.DateTime())
- op.alter_column(table_name="xcom", column_name="execution_date", type_=sa.DateTime())
diff --git a/airflow/migrations/versions/0028_1_10_0_add_kubernetes_resource_checkpointing.py b/airflow/migrations/versions/0028_1_10_0_add_kubernetes_resource_checkpointing.py
deleted file mode 100644
index 93932b3447..0000000000
--- a/airflow/migrations/versions/0028_1_10_0_add_kubernetes_resource_checkpointing.py
+++ /dev/null
@@ -1,71 +0,0 @@
-# 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 Kubernetes resource check-pointing.
-
-Revision ID: 33ae817a1ff4
-Revises: d2ae31099d61
-Create Date: 2017-09-11 15:26:47.598494
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import inspect
-
-# revision identifiers, used by Alembic.
-revision = "33ae817a1ff4"
-down_revision = "d2ae31099d61"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.0"
-
-RESOURCE_TABLE = "kube_resource_version"
-
-
-def upgrade():
- conn = op.get_bind()
- inspector = inspect(conn)
-
- if RESOURCE_TABLE not in inspector.get_table_names():
- columns_and_constraints = [
- sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
- sa.Column("resource_version", sa.String(255)),
- ]
-
- # alembic creates an invalid SQL for mssql and mysql dialects
- if conn.dialect.name in {"mysql"}:
- columns_and_constraints.append(
- sa.CheckConstraint("one_row_id<>0", name="kube_resource_version_one_row_id")
- )
- elif conn.dialect.name not in {"mssql"}:
- columns_and_constraints.append(
- sa.CheckConstraint("one_row_id", name="kube_resource_version_one_row_id")
- )
-
- table = op.create_table(RESOURCE_TABLE, *columns_and_constraints)
- op.bulk_insert(table, [{"resource_version": ""}])
-
-
-def downgrade():
- conn = op.get_bind()
- inspector = inspect(conn)
-
- if RESOURCE_TABLE in inspector.get_table_names():
- op.drop_table(RESOURCE_TABLE)
diff --git a/airflow/migrations/versions/0029_1_10_0_add_executor_config_to_task_instance.py b/airflow/migrations/versions/0029_1_10_0_add_executor_config_to_task_instance.py
deleted file mode 100644
index 31f1a1800b..0000000000
--- a/airflow/migrations/versions/0029_1_10_0_add_executor_config_to_task_instance.py
+++ /dev/null
@@ -1,48 +0,0 @@
-# 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 ``executor_config`` column to ``task_instance`` table.
-
-Revision ID: 27c6a30d7c24
-Revises: 33ae817a1ff4
-Create Date: 2017-09-11 15:26:47.598494
-
-"""
-
-from __future__ import annotations
-
-import dill
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "27c6a30d7c24"
-down_revision = "33ae817a1ff4"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.0"
-
-TASK_INSTANCE_TABLE = "task_instance"
-NEW_COLUMN = "executor_config"
-
-
-def upgrade():
- op.add_column(TASK_INSTANCE_TABLE, sa.Column(NEW_COLUMN, sa.PickleType(pickler=dill)))
-
-
-def downgrade():
- op.drop_column(TASK_INSTANCE_TABLE, NEW_COLUMN)
diff --git a/airflow/migrations/versions/0030_1_10_0_add_kubernetes_scheduler_uniqueness.py b/airflow/migrations/versions/0030_1_10_0_add_kubernetes_scheduler_uniqueness.py
deleted file mode 100644
index c0a91e4e87..0000000000
--- a/airflow/migrations/versions/0030_1_10_0_add_kubernetes_scheduler_uniqueness.py
+++ /dev/null
@@ -1,61 +0,0 @@
-# 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 kubernetes scheduler uniqueness.
-
-Revision ID: 86770d1215c0
-Revises: 27c6a30d7c24
-Create Date: 2018-04-03 15:31:20.814328
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "86770d1215c0"
-down_revision = "27c6a30d7c24"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.0"
-
-RESOURCE_TABLE = "kube_worker_uuid"
-
-
-def upgrade():
- columns_and_constraints = [
- sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
- sa.Column("worker_uuid", sa.String(255)),
- ]
-
- conn = op.get_bind()
-
- # alembic creates an invalid SQL for mssql and mysql dialects
- if conn.dialect.name in {"mysql"}:
- columns_and_constraints.append(sa.CheckConstraint("one_row_id<>0", name="kube_worker_one_row_id"))
- elif conn.dialect.name not in {"mssql"}:
- columns_and_constraints.append(sa.CheckConstraint("one_row_id", name="kube_worker_one_row_id"))
-
- table = op.create_table(RESOURCE_TABLE, *columns_and_constraints)
-
- op.bulk_insert(table, [{"worker_uuid": ""}])
-
-
-def downgrade():
- op.drop_table(RESOURCE_TABLE)
diff --git a/airflow/migrations/versions/0031_1_10_0_merge_heads.py b/airflow/migrations/versions/0031_1_10_0_merge_heads.py
deleted file mode 100644
index 81fe6440d9..0000000000
--- a/airflow/migrations/versions/0031_1_10_0_merge_heads.py
+++ /dev/null
@@ -1,41 +0,0 @@
-# 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.
-"""
-Merge migrations Heads.
-
-Revision ID: 05f30312d566
-Revises: 86770d1215c0, 0e2a74e0fc9f
-Create Date: 2018-06-17 10:47:23.339972
-
-"""
-
-from __future__ import annotations
-
-# revision identifiers, used by Alembic.
-revision = "05f30312d566"
-down_revision = ("86770d1215c0", "0e2a74e0fc9f")
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.0"
-
-
-def upgrade():
- pass
-
-
-def downgrade():
- pass
diff --git a/airflow/migrations/versions/0032_1_10_0_fix_mysql_not_null_constraint.py b/airflow/migrations/versions/0032_1_10_0_fix_mysql_not_null_constraint.py
deleted file mode 100644
index 7d612385e0..0000000000
--- a/airflow/migrations/versions/0032_1_10_0_fix_mysql_not_null_constraint.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# 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.
-"""
-Fix MySQL not null constraint.
-
-Revision ID: f23433877c24
-Revises: 05f30312d566
-Create Date: 2018-06-17 10:16:31.412131
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-from sqlalchemy import text
-from sqlalchemy.dialects import mysql
-
-# revision identifiers, used by Alembic.
-revision = "f23433877c24"
-down_revision = "05f30312d566"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.0"
-
-
-def upgrade():
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- conn.execute(text("SET time_zone = '+00:00'"))
- op.alter_column("task_fail", "execution_date", existing_type=mysql.TIMESTAMP(fsp=6), nullable=False)
- op.alter_column("xcom", "execution_date", existing_type=mysql.TIMESTAMP(fsp=6), nullable=False)
- op.alter_column("xcom", "timestamp", existing_type=mysql.TIMESTAMP(fsp=6), nullable=False)
-
-
-def downgrade():
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- conn.execute(text("SET time_zone = '+00:00'"))
- op.alter_column("xcom", "timestamp", existing_type=mysql.TIMESTAMP(fsp=6), nullable=True)
- op.alter_column("xcom", "execution_date", existing_type=mysql.TIMESTAMP(fsp=6), nullable=True)
- op.alter_column("task_fail", "execution_date", existing_type=mysql.TIMESTAMP(fsp=6), nullable=True)
diff --git a/airflow/migrations/versions/0033_1_10_0_fix_sqlite_foreign_key.py b/airflow/migrations/versions/0033_1_10_0_fix_sqlite_foreign_key.py
deleted file mode 100644
index 8a149c44e2..0000000000
--- a/airflow/migrations/versions/0033_1_10_0_fix_sqlite_foreign_key.py
+++ /dev/null
@@ -1,75 +0,0 @@
-# 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.
-"""
-Fix Sqlite foreign key.
-
-Revision ID: 856955da8476
-Revises: f23433877c24
-Create Date: 2018-06-17 15:54:53.844230
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "856955da8476"
-down_revision = "f23433877c24"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.0"
-
-
-def upgrade():
- """Fix broken foreign-key constraint for existing SQLite DBs."""
- conn = op.get_bind()
- if conn.dialect.name == "sqlite":
- # Fix broken foreign-key constraint for existing SQLite DBs.
- #
- # Re-define tables and use copy_from to avoid reflection
- # which would fail because referenced user table doesn't exist.
- #
- # Use batch_alter_table to support SQLite workaround.
- chart_table = sa.Table(
- "chart",
- sa.MetaData(),
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("label", sa.String(length=200), nullable=True),
- sa.Column("conn_id", sa.String(length=250), nullable=False),
- sa.Column("user_id", sa.Integer(), nullable=True),
- sa.Column("chart_type", sa.String(length=100), nullable=True),
- sa.Column("sql_layout", sa.String(length=50), nullable=True),
- sa.Column("sql", sa.Text(), nullable=True),
- sa.Column("y_log_scale", sa.Boolean(), nullable=True),
- sa.Column("show_datatable", sa.Boolean(), nullable=True),
- sa.Column("show_sql", sa.Boolean(), nullable=True),
- sa.Column("height", sa.Integer(), nullable=True),
- sa.Column("default_params", sa.String(length=5000), nullable=True),
- sa.Column("x_is_date", sa.Boolean(), nullable=True),
- sa.Column("iteration_no", sa.Integer(), nullable=True),
- sa.Column("last_modified", sa.DateTime(), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- )
- with op.batch_alter_table("chart", copy_from=chart_table) as batch_op:
- batch_op.create_foreign_key("chart_user_id_fkey", "users", ["user_id"], ["id"])
-
-
-def downgrade():
- # Downgrade would fail because the broken FK constraint can't be re-created.
- pass
diff --git a/airflow/migrations/versions/0034_1_10_0_index_taskfail.py b/airflow/migrations/versions/0034_1_10_0_index_taskfail.py
deleted file mode 100644
index 4853d6a9e7..0000000000
--- a/airflow/migrations/versions/0034_1_10_0_index_taskfail.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# 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.
-"""
-Create index on ``task_fail`` table.
-
-Revision ID: 9635ae0956e7
-Revises: 856955da8476
-Create Date: 2018-06-17 21:40:01.963540
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "9635ae0956e7"
-down_revision = "856955da8476"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.0"
-
-
-def upgrade():
- op.create_index(
- "idx_task_fail_dag_task_date", "task_fail", ["dag_id", "task_id", "execution_date"], unique=False
- )
-
-
-def downgrade():
- op.drop_index("idx_task_fail_dag_task_date", table_name="task_fail")
diff --git a/airflow/migrations/versions/0035_1_10_2_add_idx_log_dag.py b/airflow/migrations/versions/0035_1_10_2_add_idx_log_dag.py
deleted file mode 100644
index eab5d518cc..0000000000
--- a/airflow/migrations/versions/0035_1_10_2_add_idx_log_dag.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# 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 ``log`` table.
-
-Revision ID: dd25f486b8ea
-Revises: 9635ae0956e7
-Create Date: 2018-08-07 06:41:41.028249
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "dd25f486b8ea"
-down_revision = "9635ae0956e7"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.2"
-
-
-def upgrade():
- op.create_index("idx_log_dag", "log", ["dag_id"], unique=False)
-
-
-def downgrade():
- op.drop_index("idx_log_dag", table_name="log")
diff --git a/airflow/migrations/versions/0036_1_10_2_add_index_to_taskinstance.py b/airflow/migrations/versions/0036_1_10_2_add_index_to_taskinstance.py
deleted file mode 100644
index fd2031ae8c..0000000000
--- a/airflow/migrations/versions/0036_1_10_2_add_index_to_taskinstance.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# 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 to ``task_instance`` table.
-
-Revision ID: bf00311e1990
-Revises: dd25f486b8ea
-Create Date: 2018-09-12 09:53:52.007433
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "bf00311e1990"
-down_revision = "dd25f486b8ea"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.2"
-
-
-def upgrade():
- op.create_index("ti_dag_date", "task_instance", ["dag_id", "execution_date"], unique=False)
-
-
-def downgrade():
- op.drop_index("ti_dag_date", table_name="task_instance")
diff --git a/airflow/migrations/versions/0037_1_10_2_add_task_reschedule_table.py b/airflow/migrations/versions/0037_1_10_2_add_task_reschedule_table.py
deleted file mode 100644
index 4ac4f9c904..0000000000
--- a/airflow/migrations/versions/0037_1_10_2_add_task_reschedule_table.py
+++ /dev/null
@@ -1,75 +0,0 @@
-# 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 ``task_reschedule`` table.
-
-Revision ID: 0a2a5b66e19d
-Revises: 9635ae0956e7
-Create Date: 2018-06-17 22:50:00.053620
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.migrations.db_types import TIMESTAMP, StringID
-
-# revision identifiers, used by Alembic.
-revision = "0a2a5b66e19d"
-down_revision = "9635ae0956e7"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.2"
-
-TABLE_NAME = "task_reschedule"
-INDEX_NAME = "idx_" + TABLE_NAME + "_dag_task_date"
-
-
-def upgrade():
- # See 0e2a74e0fc9f_add_time_zone_awareness
- timestamp = TIMESTAMP
- if op.get_bind().dialect.name == "mssql":
- # We need to keep this as it was for this old migration on mssql
- timestamp = sa.DateTime()
-
- op.create_table(
- TABLE_NAME,
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("task_id", StringID(), nullable=False),
- sa.Column("dag_id", StringID(), nullable=False),
- # use explicit server_default=None otherwise mysql implies defaults for first timestamp column
- sa.Column("execution_date", timestamp, nullable=False, server_default=None),
- sa.Column("try_number", sa.Integer(), nullable=False),
- sa.Column("start_date", timestamp, nullable=False),
- sa.Column("end_date", timestamp, nullable=False),
- sa.Column("duration", sa.Integer(), nullable=False),
- sa.Column("reschedule_date", timestamp, nullable=False),
- sa.PrimaryKeyConstraint("id"),
- sa.ForeignKeyConstraint(
- ["task_id", "dag_id", "execution_date"],
- ["task_instance.task_id", "task_instance.dag_id", "task_instance.execution_date"],
- name="task_reschedule_dag_task_date_fkey",
- ),
- )
- op.create_index(INDEX_NAME, TABLE_NAME, ["dag_id", "task_id", "execution_date"], unique=False)
-
-
-def downgrade():
- op.drop_index(INDEX_NAME, table_name=TABLE_NAME)
- op.drop_table(TABLE_NAME)
diff --git a/airflow/migrations/versions/0038_1_10_2_add_sm_dag_index.py b/airflow/migrations/versions/0038_1_10_2_add_sm_dag_index.py
deleted file mode 100644
index bf8541c300..0000000000
--- a/airflow/migrations/versions/0038_1_10_2_add_sm_dag_index.py
+++ /dev/null
@@ -1,43 +0,0 @@
-# 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.
-"""
-Merge migrations Heads.
-
-Revision ID: 03bc53e68815
-Revises: 0a2a5b66e19d, bf00311e1990
-Create Date: 2018-11-24 20:21:46.605414
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "03bc53e68815"
-down_revision = ("0a2a5b66e19d", "bf00311e1990")
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.2"
-
-
-def upgrade():
- op.create_index("sm_dag", "sla_miss", ["dag_id"], unique=False)
-
-
-def downgrade():
- op.drop_index("sm_dag", table_name="sla_miss")
diff --git a/airflow/migrations/versions/0039_1_10_2_add_superuser_field.py b/airflow/migrations/versions/0039_1_10_2_add_superuser_field.py
deleted file mode 100644
index fbc76535d7..0000000000
--- a/airflow/migrations/versions/0039_1_10_2_add_superuser_field.py
+++ /dev/null
@@ -1,44 +0,0 @@
-# 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 superuser field.
-
-Revision ID: 41f5f12752f8
-Revises: 03bc53e68815
-Create Date: 2018-12-04 15:50:04.456875
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "41f5f12752f8"
-down_revision = "03bc53e68815"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.2"
-
-
-def upgrade():
- op.add_column("users", sa.Column("superuser", sa.Boolean(), default=False))
-
-
-def downgrade():
- op.drop_column("users", "superuser")
diff --git a/airflow/migrations/versions/0040_1_10_3_add_fields_to_dag.py b/airflow/migrations/versions/0040_1_10_3_add_fields_to_dag.py
deleted file mode 100644
index fd13164499..0000000000
--- a/airflow/migrations/versions/0040_1_10_3_add_fields_to_dag.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# 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 ``description`` and ``default_view`` column to ``dag`` table.
-
-Revision ID: c8ffec048a3b
-Revises: 41f5f12752f8
-Create Date: 2018-12-23 21:55:46.463634
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "c8ffec048a3b"
-down_revision = "41f5f12752f8"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.3"
-
-
-def upgrade():
- op.add_column("dag", sa.Column("description", sa.Text(), nullable=True))
- op.add_column("dag", sa.Column("default_view", sa.String(25), nullable=True))
-
-
-def downgrade():
- op.drop_column("dag", "description")
- op.drop_column("dag", "default_view")
diff --git a/airflow/migrations/versions/0041_1_10_3_add_schedule_interval_to_dag.py b/airflow/migrations/versions/0041_1_10_3_add_schedule_interval_to_dag.py
deleted file mode 100644
index 40002530e9..0000000000
--- a/airflow/migrations/versions/0041_1_10_3_add_schedule_interval_to_dag.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# 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 schedule interval to dag.
-
-Revision ID: dd4ecb8fbee3
-Revises: c8ffec048a3b
-Create Date: 2018-12-27 18:39:25.748032
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "dd4ecb8fbee3"
-down_revision = "c8ffec048a3b"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.3"
-
-
-def upgrade():
- op.add_column("dag", sa.Column("schedule_interval", sa.Text(), nullable=True))
-
-
-def downgrade():
- op.drop_column("dag", "schedule_interval")
diff --git a/airflow/migrations/versions/0042_1_10_3_task_reschedule_fk_on_cascade_delete.py b/airflow/migrations/versions/0042_1_10_3_task_reschedule_fk_on_cascade_delete.py
deleted file mode 100644
index 4fbbe353a6..0000000000
--- a/airflow/migrations/versions/0042_1_10_3_task_reschedule_fk_on_cascade_delete.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# 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.
-"""
-task reschedule foreign key on cascade delete.
-
-Revision ID: 939bb1e647c8
-Revises: dd4ecb8fbee3
-Create Date: 2019-02-04 20:21:50.669751
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "939bb1e647c8"
-down_revision = "dd4ecb8fbee3"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.3"
-
-
-def upgrade():
- with op.batch_alter_table("task_reschedule") as batch_op:
- batch_op.drop_constraint("task_reschedule_dag_task_date_fkey", type_="foreignkey")
- batch_op.create_foreign_key(
- "task_reschedule_dag_task_date_fkey",
- "task_instance",
- ["task_id", "dag_id", "execution_date"],
- ["task_id", "dag_id", "execution_date"],
- ondelete="CASCADE",
- )
-
-
-def downgrade():
- with op.batch_alter_table("task_reschedule") as batch_op:
- batch_op.drop_constraint("task_reschedule_dag_task_date_fkey", type_="foreignkey")
- batch_op.create_foreign_key(
- "task_reschedule_dag_task_date_fkey",
- "task_instance",
- ["task_id", "dag_id", "execution_date"],
- ["task_id", "dag_id", "execution_date"],
- )
diff --git a/airflow/migrations/versions/0043_1_10_4_make_taskinstance_pool_not_nullable.py b/airflow/migrations/versions/0043_1_10_4_make_taskinstance_pool_not_nullable.py
deleted file mode 100644
index e3e4b699ad..0000000000
--- a/airflow/migrations/versions/0043_1_10_4_make_taskinstance_pool_not_nullable.py
+++ /dev/null
@@ -1,108 +0,0 @@
-#
-# 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.
-"""
-Make ``TaskInstance.pool`` not nullable.
-
-Revision ID: 6e96a59344a4
-Revises: 939bb1e647c8
-Create Date: 2019-06-13 21:51:32.878437
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import Column, String
-from sqlalchemy.orm import declarative_base
-
-from airflow.utils.session import create_session
-from airflow.utils.sqlalchemy import UtcDateTime
-
-# revision identifiers, used by Alembic.
-revision = "6e96a59344a4"
-down_revision = "939bb1e647c8"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.4"
-
-Base = declarative_base()
-ID_LEN = 250
-
-
-class TaskInstance(Base): # type: ignore
- """Minimal model definition for migrations."""
-
- __tablename__ = "task_instance"
-
- task_id = Column(String(), primary_key=True)
- dag_id = Column(String(), primary_key=True)
- execution_date = Column(UtcDateTime, primary_key=True)
- pool = Column(String(50), nullable=False)
-
-
-def upgrade():
- """Make TaskInstance.pool field not nullable."""
- with create_session() as session:
- session.query(TaskInstance).filter(TaskInstance.pool.is_(None)).update(
- {TaskInstance.pool: "default_pool"}, synchronize_session=False
- ) # Avoid select updated rows
- session.commit()
-
- conn = op.get_bind()
- if conn.dialect.name == "mssql":
- op.drop_index(index_name="ti_pool", table_name="task_instance")
-
- # use batch_alter_table to support SQLite workaround
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.alter_column(
- column_name="pool",
- type_=sa.String(50),
- nullable=False,
- )
-
- if conn.dialect.name == "mssql":
- op.create_index(
- index_name="ti_pool", table_name="task_instance", columns=["pool", "state", "priority_weight"]
- )
-
-
-def downgrade():
- """Make TaskInstance.pool field nullable."""
- conn = op.get_bind()
- if conn.dialect.name == "mssql":
- op.drop_index(index_name="ti_pool", table_name="task_instance")
-
- # use batch_alter_table to support SQLite workaround
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.alter_column(
- column_name="pool",
- type_=sa.String(50),
- nullable=True,
- )
-
- if conn.dialect.name == "mssql":
- op.create_index(
- index_name="ti_pool", table_name="task_instance", columns=["pool", "state", "priority_weight"]
- )
-
- with create_session() as session:
- session.query(TaskInstance).filter(TaskInstance.pool == "default_pool").update(
- {TaskInstance.pool: None}, synchronize_session=False
- ) # Avoid select updated rows
- session.commit()
diff --git a/airflow/migrations/versions/0044_1_10_7_add_serialized_dag_table.py b/airflow/migrations/versions/0044_1_10_7_add_serialized_dag_table.py
deleted file mode 100644
index fde6ff6b5f..0000000000
--- a/airflow/migrations/versions/0044_1_10_7_add_serialized_dag_table.py
+++ /dev/null
@@ -1,103 +0,0 @@
-#
-# 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 ``serialized_dag`` table.
-
-Revision ID: d38e04c12aa2
-Revises: 6e96a59344a4
-Create Date: 2019-08-01 14:39:35.616417
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import text
-from sqlalchemy.dialects import mysql
-
-from airflow.exceptions import AirflowException
-from airflow.migrations.db_types import StringID
-
-# revision identifiers, used by Alembic.
-revision = "d38e04c12aa2"
-down_revision = "6e96a59344a4"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.7"
-
-
-def upgrade():
- """Upgrade version."""
- json_type = sa.JSON
- conn = op.get_bind()
-
- if conn.dialect.name != "postgresql":
- # Mysql 5.7+/MariaDB 10.2.3 has JSON support. Rather than checking for
- # versions, check for the function existing.
- try:
- conn.execute(text("SELECT JSON_VALID(1)")).fetchone()
- except (sa.exc.OperationalError, sa.exc.ProgrammingError):
- json_type = sa.Text
-
- op.create_table(
- "serialized_dag",
- sa.Column("dag_id", StringID(), nullable=False),
- sa.Column("fileloc", sa.String(length=2000), nullable=False),
- sa.Column("fileloc_hash", sa.Integer(), nullable=False),
- sa.Column("data", json_type(), nullable=False),
- sa.Column("last_updated", sa.DateTime(), nullable=False),
- sa.PrimaryKeyConstraint("dag_id"),
- )
- op.create_index("idx_fileloc_hash", "serialized_dag", ["fileloc_hash"])
-
- if conn.dialect.name == "mysql":
- conn.execute(text("SET time_zone = '+00:00'"))
- cur = conn.execute(text("SELECT @@explicit_defaults_for_timestamp"))
- res = cur.fetchall()
- if res[0][0] == 0:
- raise AirflowException(
- "Global variable explicit_defaults_for_timestamp needs to be on (1) for mysql"
- )
-
- op.alter_column(
- table_name="serialized_dag",
- column_name="last_updated",
- type_=mysql.TIMESTAMP(fsp=6),
- nullable=False,
- )
- else:
- # sqlite and mssql datetime are fine as is. Therefore, not converting
- if conn.dialect.name in ("sqlite", "mssql"):
- return
-
- # we try to be database agnostic, but not every db (e.g. sqlserver)
- # supports per session time zones
- if conn.dialect.name == "postgresql":
- conn.execute(text("set timezone=UTC"))
-
- op.alter_column(
- table_name="serialized_dag",
- column_name="last_updated",
- type_=sa.TIMESTAMP(timezone=True),
- )
-
-
-def downgrade():
- """Downgrade version."""
- op.drop_table("serialized_dag")
diff --git a/airflow/migrations/versions/0045_1_10_7_add_root_dag_id_to_dag.py b/airflow/migrations/versions/0045_1_10_7_add_root_dag_id_to_dag.py
deleted file mode 100644
index ce31fd3894..0000000000
--- a/airflow/migrations/versions/0045_1_10_7_add_root_dag_id_to_dag.py
+++ /dev/null
@@ -1,51 +0,0 @@
-#
-# 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 ``root_dag_id`` to ``DAG``.
-
-Revision ID: b3b105409875
-Revises: d38e04c12aa2
-Create Date: 2019-09-28 23:20:01.744775
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.migrations.db_types import StringID
-
-# revision identifiers, used by Alembic.
-revision = "b3b105409875"
-down_revision = "d38e04c12aa2"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.7"
-
-
-def upgrade():
- """Apply Add ``root_dag_id`` to ``DAG``."""
- op.add_column("dag", sa.Column("root_dag_id", StringID(), nullable=True))
- op.create_index("idx_root_dag_id", "dag", ["root_dag_id"], unique=False)
-
-
-def downgrade():
- """Unapply Add ``root_dag_id`` to ``DAG``."""
- op.drop_index("idx_root_dag_id", table_name="dag")
- op.drop_column("dag", "root_dag_id")
diff --git a/airflow/migrations/versions/0046_1_10_5_change_datetime_to_datetime2_6_on_mssql_.py b/airflow/migrations/versions/0046_1_10_5_change_datetime_to_datetime2_6_on_mssql_.py
deleted file mode 100644
index 6d8d30db49..0000000000
--- a/airflow/migrations/versions/0046_1_10_5_change_datetime_to_datetime2_6_on_mssql_.py
+++ /dev/null
@@ -1,356 +0,0 @@
-#
-# 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.
-"""
-change datetime to datetime2(6) on MSSQL tables.
-
-Revision ID: 74effc47d867
-Revises: 6e96a59344a4
-Create Date: 2019-08-01 15:19:57.585620
-
-"""
-
-from __future__ import annotations
-
-from collections import defaultdict
-
-from alembic import op
-from sqlalchemy import text
-from sqlalchemy.dialects import mssql
-
-# revision identifiers, used by Alembic.
-revision = "74effc47d867"
-down_revision = "6e96a59344a4"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.5"
-
-
-def upgrade():
- """Change datetime to datetime2(6) when using MSSQL as backend."""
- conn = op.get_bind()
- if conn.dialect.name == "mssql":
- result = conn.execute(
- text(
- """SELECT CASE WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion'))
- like '8%' THEN '2000' WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion'))
- like '9%' THEN '2005' ELSE '2005Plus' END AS MajorVersion"""
- )
- ).fetchone()
- mssql_version = result[0]
- if mssql_version in ("2000", "2005"):
- return
-
- with op.batch_alter_table("task_reschedule") as task_reschedule_batch_op:
- task_reschedule_batch_op.drop_index("idx_task_reschedule_dag_task_date")
- task_reschedule_batch_op.drop_constraint("task_reschedule_dag_task_date_fkey", type_="foreignkey")
- task_reschedule_batch_op.alter_column(
- column_name="execution_date",
- type_=mssql.DATETIME2(precision=6),
- nullable=False,
- )
- task_reschedule_batch_op.alter_column(
- column_name="start_date", type_=mssql.DATETIME2(precision=6)
- )
- task_reschedule_batch_op.alter_column(column_name="end_date", type_=mssql.DATETIME2(precision=6))
- task_reschedule_batch_op.alter_column(
- column_name="reschedule_date", type_=mssql.DATETIME2(precision=6)
- )
-
- with op.batch_alter_table("task_instance") as task_instance_batch_op:
- task_instance_batch_op.drop_index("ti_state_lkp")
- task_instance_batch_op.drop_index("ti_dag_date")
- modify_execution_date_with_constraint(
- conn, task_instance_batch_op, "task_instance", mssql.DATETIME2(precision=6), False
- )
- task_instance_batch_op.alter_column(column_name="start_date", type_=mssql.DATETIME2(precision=6))
- task_instance_batch_op.alter_column(column_name="end_date", type_=mssql.DATETIME2(precision=6))
- task_instance_batch_op.alter_column(column_name="queued_dttm", type_=mssql.DATETIME2(precision=6))
- task_instance_batch_op.create_index(
- "ti_state_lkp", ["dag_id", "task_id", "execution_date"], unique=False
- )
- task_instance_batch_op.create_index("ti_dag_date", ["dag_id", "execution_date"], unique=False)
-
- with op.batch_alter_table("task_reschedule") as task_reschedule_batch_op:
- task_reschedule_batch_op.create_foreign_key(
- "task_reschedule_dag_task_date_fkey",
- "task_instance",
- ["task_id", "dag_id", "execution_date"],
- ["task_id", "dag_id", "execution_date"],
- ondelete="CASCADE",
- )
- task_reschedule_batch_op.create_index(
- "idx_task_reschedule_dag_task_date", ["dag_id", "task_id", "execution_date"], unique=False
- )
-
- with op.batch_alter_table("dag_run") as dag_run_batch_op:
- modify_execution_date_with_constraint(
- conn, dag_run_batch_op, "dag_run", mssql.DATETIME2(precision=6), None
- )
- dag_run_batch_op.alter_column(column_name="start_date", type_=mssql.DATETIME2(precision=6))
- dag_run_batch_op.alter_column(column_name="end_date", type_=mssql.DATETIME2(precision=6))
-
- op.alter_column(table_name="log", column_name="execution_date", type_=mssql.DATETIME2(precision=6))
- op.alter_column(table_name="log", column_name="dttm", type_=mssql.DATETIME2(precision=6))
-
- with op.batch_alter_table("sla_miss") as sla_miss_batch_op:
- modify_execution_date_with_constraint(
- conn, sla_miss_batch_op, "sla_miss", mssql.DATETIME2(precision=6), False
- )
- sla_miss_batch_op.alter_column(column_name="timestamp", type_=mssql.DATETIME2(precision=6))
-
- op.drop_index("idx_task_fail_dag_task_date", table_name="task_fail")
- op.alter_column(
- table_name="task_fail", column_name="execution_date", type_=mssql.DATETIME2(precision=6)
- )
- op.alter_column(table_name="task_fail", column_name="start_date", type_=mssql.DATETIME2(precision=6))
- op.alter_column(table_name="task_fail", column_name="end_date", type_=mssql.DATETIME2(precision=6))
- op.create_index(
- "idx_task_fail_dag_task_date", "task_fail", ["dag_id", "task_id", "execution_date"], unique=False
- )
-
- op.drop_index("idx_xcom_dag_task_date", table_name="xcom")
- op.alter_column(table_name="xcom", column_name="execution_date", type_=mssql.DATETIME2(precision=6))
- op.alter_column(table_name="xcom", column_name="timestamp", type_=mssql.DATETIME2(precision=6))
- op.create_index(
- "idx_xcom_dag_task_date", "xcom", ["dag_id", "task_id", "execution_date"], unique=False
- )
-
- op.alter_column(
- table_name="dag", column_name="last_scheduler_run", type_=mssql.DATETIME2(precision=6)
- )
- op.alter_column(table_name="dag", column_name="last_pickled", type_=mssql.DATETIME2(precision=6))
- op.alter_column(table_name="dag", column_name="last_expired", type_=mssql.DATETIME2(precision=6))
-
- op.alter_column(
- table_name="dag_pickle", column_name="created_dttm", type_=mssql.DATETIME2(precision=6)
- )
-
- op.alter_column(
- table_name="import_error", column_name="timestamp", type_=mssql.DATETIME2(precision=6)
- )
-
- op.drop_index("job_type_heart", table_name="job")
- op.drop_index("idx_job_state_heartbeat", table_name="job")
- op.alter_column(table_name="job", column_name="start_date", type_=mssql.DATETIME2(precision=6))
- op.alter_column(table_name="job", column_name="end_date", type_=mssql.DATETIME2(precision=6))
- op.alter_column(table_name="job", column_name="latest_heartbeat", type_=mssql.DATETIME2(precision=6))
- op.create_index("idx_job_state_heartbeat", "job", ["state", "latest_heartbeat"], unique=False)
- op.create_index("job_type_heart", "job", ["job_type", "latest_heartbeat"], unique=False)
-
-
-def downgrade():
- """Change datetime2(6) back to datetime."""
- conn = op.get_bind()
- if conn.dialect.name == "mssql":
- result = conn.execute(
- text(
- """SELECT CASE WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion'))
- like '8%' THEN '2000' WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion'))
- like '9%' THEN '2005' ELSE '2005Plus' END AS MajorVersion"""
- )
- ).fetchone()
- mssql_version = result[0]
- if mssql_version in ("2000", "2005"):
- return
-
- with op.batch_alter_table("task_reschedule") as task_reschedule_batch_op:
- task_reschedule_batch_op.drop_index("idx_task_reschedule_dag_task_date")
- task_reschedule_batch_op.drop_constraint("task_reschedule_dag_task_date_fkey", type_="foreignkey")
- task_reschedule_batch_op.alter_column(
- column_name="execution_date", type_=mssql.DATETIME, nullable=False
- )
- task_reschedule_batch_op.alter_column(column_name="start_date", type_=mssql.DATETIME)
- task_reschedule_batch_op.alter_column(column_name="end_date", type_=mssql.DATETIME)
- task_reschedule_batch_op.alter_column(column_name="reschedule_date", type_=mssql.DATETIME)
-
- with op.batch_alter_table("task_instance") as task_instance_batch_op:
- task_instance_batch_op.drop_index("ti_state_lkp")
- task_instance_batch_op.drop_index("ti_dag_date")
- modify_execution_date_with_constraint(
- conn, task_instance_batch_op, "task_instance", mssql.DATETIME, False
- )
- task_instance_batch_op.alter_column(column_name="start_date", type_=mssql.DATETIME)
- task_instance_batch_op.alter_column(column_name="end_date", type_=mssql.DATETIME)
- task_instance_batch_op.alter_column(column_name="queued_dttm", type_=mssql.DATETIME)
- task_instance_batch_op.create_index(
- "ti_state_lkp", ["dag_id", "task_id", "execution_date"], unique=False
- )
- task_instance_batch_op.create_index("ti_dag_date", ["dag_id", "execution_date"], unique=False)
-
- with op.batch_alter_table("task_reschedule") as task_reschedule_batch_op:
- task_reschedule_batch_op.create_foreign_key(
- "task_reschedule_dag_task_date_fkey",
- "task_instance",
- ["task_id", "dag_id", "execution_date"],
- ["task_id", "dag_id", "execution_date"],
- ondelete="CASCADE",
- )
- task_reschedule_batch_op.create_index(
- "idx_task_reschedule_dag_task_date", ["dag_id", "task_id", "execution_date"], unique=False
- )
-
- with op.batch_alter_table("dag_run") as dag_run_batch_op:
- modify_execution_date_with_constraint(conn, dag_run_batch_op, "dag_run", mssql.DATETIME, None)
- dag_run_batch_op.alter_column(column_name="start_date", type_=mssql.DATETIME)
- dag_run_batch_op.alter_column(column_name="end_date", type_=mssql.DATETIME)
-
- op.alter_column(table_name="log", column_name="execution_date", type_=mssql.DATETIME)
- op.alter_column(table_name="log", column_name="dttm", type_=mssql.DATETIME)
-
- with op.batch_alter_table("sla_miss") as sla_miss_batch_op:
- modify_execution_date_with_constraint(conn, sla_miss_batch_op, "sla_miss", mssql.DATETIME, False)
- sla_miss_batch_op.alter_column(column_name="timestamp", type_=mssql.DATETIME)
-
- op.drop_index("idx_task_fail_dag_task_date", table_name="task_fail")
- op.alter_column(table_name="task_fail", column_name="execution_date", type_=mssql.DATETIME)
- op.alter_column(table_name="task_fail", column_name="start_date", type_=mssql.DATETIME)
- op.alter_column(table_name="task_fail", column_name="end_date", type_=mssql.DATETIME)
- op.create_index(
- "idx_task_fail_dag_task_date", "task_fail", ["dag_id", "task_id", "execution_date"], unique=False
- )
-
- op.drop_index("idx_xcom_dag_task_date", table_name="xcom")
- op.alter_column(table_name="xcom", column_name="execution_date", type_=mssql.DATETIME)
- op.alter_column(table_name="xcom", column_name="timestamp", type_=mssql.DATETIME)
- op.create_index(
- "idx_xcom_dag_task_date", "xcom", ["dag_id", "task_ild", "execution_date"], unique=False
- )
-
- op.alter_column(table_name="dag", column_name="last_scheduler_run", type_=mssql.DATETIME)
- op.alter_column(table_name="dag", column_name="last_pickled", type_=mssql.DATETIME)
- op.alter_column(table_name="dag", column_name="last_expired", type_=mssql.DATETIME)
-
- op.alter_column(table_name="dag_pickle", column_name="created_dttm", type_=mssql.DATETIME)
-
- op.alter_column(table_name="import_error", column_name="timestamp", type_=mssql.DATETIME)
-
- op.drop_index("job_type_heart", table_name="job")
- op.drop_index("idx_job_state_heartbeat", table_name="job")
- op.alter_column(table_name="job", column_name="start_date", type_=mssql.DATETIME)
- op.alter_column(table_name="job", column_name="end_date", type_=mssql.DATETIME)
- op.alter_column(table_name="job", column_name="latest_heartbeat", type_=mssql.DATETIME)
- op.create_index("idx_job_state_heartbeat", "job", ["state", "latest_heartbeat"], unique=False)
- op.create_index("job_type_heart", "job", ["job_type", "latest_heartbeat"], unique=False)
-
-
-def get_table_constraints(conn, table_name) -> dict[tuple[str, str], list[str]]:
- """
- Return primary and unique constraint along with column name.
-
- This function return primary and unique constraint
- along with column name. some tables like task_instance
- is missing primary key constraint name and the name is
- auto-generated by sql server. so this function helps to
- retrieve any primary or unique constraint name.
-
- :param conn: sql connection object
- :param table_name: table name
- :return: a dictionary of ((constraint name, constraint type), column name) of table
- """
- query = text(
- f"""SELECT tc.CONSTRAINT_NAME , tc.CONSTRAINT_TYPE, ccu.COLUMN_NAME
- FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
- JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu ON ccu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
- WHERE tc.TABLE_NAME = '{table_name}' AND
- (tc.CONSTRAINT_TYPE = 'PRIMARY KEY' or UPPER(tc.CONSTRAINT_TYPE) = 'UNIQUE')
- """
- )
- result = conn.execute(query).fetchall()
- constraint_dict = defaultdict(list)
- for constraint, constraint_type, column in result:
- constraint_dict[(constraint, constraint_type)].append(column)
- return constraint_dict
-
-
-def reorder_columns(columns):
- """
- Reorder the columns for creating constraint.
-
- Preserve primary key ordering
- ``['task_id', 'dag_id', 'execution_date']``
-
- :param columns: columns retrieved from DB related to constraint
- :return: ordered column
- """
- ordered_columns = []
- for column in ["task_id", "dag_id", "execution_date"]:
- if column in columns:
- ordered_columns.append(column)
-
- for column in columns:
- if column not in ["task_id", "dag_id", "execution_date"]:
- ordered_columns.append(column)
-
- return ordered_columns
-
-
-def drop_constraint(operator, constraint_dict):
- """
- Drop a primary key or unique constraint.
-
- :param operator: batch_alter_table for the table
- :param constraint_dict: a dictionary of ((constraint name, constraint type), column name) of table
- """
- for constraint, columns in constraint_dict.items():
- if "execution_date" in columns:
- if constraint[1].lower().startswith("primary"):
- operator.drop_constraint(constraint[0], type_="primary")
- elif constraint[1].lower().startswith("unique"):
- operator.drop_constraint(constraint[0], type_="unique")
-
-
-def create_constraint(operator, constraint_dict):
- """
- Create a primary key or unique constraint.
-
- :param operator: batch_alter_table for the table
- :param constraint_dict: a dictionary of ((constraint name, constraint type), column name) of table
- """
- for constraint, columns in constraint_dict.items():
- if "execution_date" in columns:
- if constraint[1].lower().startswith("primary"):
- operator.create_primary_key(constraint_name=constraint[0], columns=reorder_columns(columns))
- elif constraint[1].lower().startswith("unique"):
- operator.create_unique_constraint(
- constraint_name=constraint[0], columns=reorder_columns(columns)
- )
-
-
-def modify_execution_date_with_constraint(conn, batch_operator, table_name, type_, nullable) -> None:
- """
- Change type of column execution_date.
-
- Helper function changes type of column execution_date by
- dropping and recreating any primary/unique constraint associated with
- the column
-
- :param conn: sql connection object
- :param batch_operator: batch_alter_table for the table
- :param table_name: table name
- :param type_: DB column type
- :param nullable: nullable (boolean)
- :return: a dictionary of ((constraint name, constraint type), column name) of table
- """
- constraint_dict = get_table_constraints(conn, table_name)
- drop_constraint(batch_operator, constraint_dict)
- batch_operator.alter_column(
- column_name="execution_date",
- type_=type_,
- nullable=nullable,
- )
- create_constraint(batch_operator, constraint_dict)
diff --git a/airflow/migrations/versions/0047_1_10_4_increase_queue_name_size_limit.py b/airflow/migrations/versions/0047_1_10_4_increase_queue_name_size_limit.py
deleted file mode 100644
index 61f3932feb..0000000000
--- a/airflow/migrations/versions/0047_1_10_4_increase_queue_name_size_limit.py
+++ /dev/null
@@ -1,55 +0,0 @@
-#
-# 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.
-"""
-Increase queue name size limit.
-
-Revision ID: 004c1210f153
-Revises: 939bb1e647c8
-Create Date: 2019-06-07 07:46:04.262275
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "004c1210f153"
-down_revision = "939bb1e647c8"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.4"
-
-
-def upgrade():
- """
- Increase column size from 50 to 256 characters.
-
- Broker backends might use unusually large queue names.
- """
- # use batch_alter_table to support SQLite workaround
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.alter_column("queue", type_=sa.String(256))
-
-
-def downgrade():
- """Revert column size from 256 to 50 characters, might result in data loss."""
- # use batch_alter_table to support SQLite workaround
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.alter_column("queue", type_=sa.String(50))
diff --git a/airflow/migrations/versions/0048_1_10_3_remove_dag_stat_table.py b/airflow/migrations/versions/0048_1_10_3_remove_dag_stat_table.py
deleted file mode 100644
index bc7084fce4..0000000000
--- a/airflow/migrations/versions/0048_1_10_3_remove_dag_stat_table.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#
-# 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 ``dag_stat`` table.
-
-Revision ID: a56c9515abdc
-Revises: c8ffec048a3b
-Create Date: 2018-12-27 10:27:59.715872
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "a56c9515abdc"
-down_revision = "c8ffec048a3b"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.3"
-
-
-def upgrade():
- """Drop dag_stats table."""
- op.drop_table("dag_stats")
-
-
-def downgrade():
- """Create dag_stats table."""
- op.create_table(
- "dag_stats",
- sa.Column("dag_id", sa.String(length=250), nullable=False),
- sa.Column("state", sa.String(length=50), nullable=False),
- sa.Column("count", sa.Integer(), nullable=False, default=0),
- sa.Column("dirty", sa.Boolean(), nullable=False, default=False),
- sa.PrimaryKeyConstraint("dag_id", "state"),
- )
diff --git a/airflow/migrations/versions/0049_1_10_7_merge_heads.py b/airflow/migrations/versions/0049_1_10_7_merge_heads.py
deleted file mode 100644
index 98048327e0..0000000000
--- a/airflow/migrations/versions/0049_1_10_7_merge_heads.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# 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.
-"""
-Straighten out the migrations.
-
-Revision ID: 08364691d074
-Revises: a56c9515abdc, 004c1210f153, 74effc47d867, b3b105409875
-Create Date: 2019-11-19 22:05:11.752222
-
-"""
-
-from __future__ import annotations
-
-# revision identifiers, used by Alembic.
-revision = "08364691d074"
-down_revision = ("a56c9515abdc", "004c1210f153", "74effc47d867", "b3b105409875")
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.7"
-
-
-def upgrade():
- pass
-
-
-def downgrade():
- pass
diff --git a/airflow/migrations/versions/0050_1_10_7_increase_length_for_connection_password.py b/airflow/migrations/versions/0050_1_10_7_increase_length_for_connection_password.py
deleted file mode 100644
index e9d6361e5b..0000000000
--- a/airflow/migrations/versions/0050_1_10_7_increase_length_for_connection_password.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# 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.
-"""
-Increase length for connection password.
-
-Revision ID: fe461863935f
-Revises: 08364691d074
-Create Date: 2019-12-08 09:47:09.033009
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "fe461863935f"
-down_revision = "08364691d074"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.7"
-
-
-def upgrade():
- """Apply Increase length for connection password."""
- with op.batch_alter_table("connection", schema=None) as batch_op:
- batch_op.alter_column(
- "password",
- existing_type=sa.VARCHAR(length=500),
- type_=sa.String(length=5000),
- existing_nullable=True,
- )
-
-
-def downgrade():
- """Unapply Increase length for connection password."""
- with op.batch_alter_table("connection", schema=None) as batch_op:
- batch_op.alter_column(
- "password",
- existing_type=sa.String(length=5000),
- type_=sa.VARCHAR(length=500),
- existing_nullable=True,
- )
diff --git a/airflow/migrations/versions/0051_1_10_8_add_dagtags_table.py b/airflow/migrations/versions/0051_1_10_8_add_dagtags_table.py
deleted file mode 100644
index 301748ca94..0000000000
--- a/airflow/migrations/versions/0051_1_10_8_add_dagtags_table.py
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# 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 ``DagTags`` table.
-
-Revision ID: 7939bcff74ba
-Revises: fe461863935f
-Create Date: 2020-01-07 19:39:01.247442
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.migrations.db_types import StringID
-
-# revision identifiers, used by Alembic.
-revision = "7939bcff74ba"
-down_revision = "fe461863935f"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.8"
-
-
-def upgrade():
- """Apply Add ``DagTags`` table."""
- op.create_table(
- "dag_tag",
- sa.Column("name", sa.String(length=100), nullable=False),
- sa.Column("dag_id", StringID(), nullable=False),
- sa.ForeignKeyConstraint(
- ["dag_id"],
- ["dag.dag_id"],
- ),
- sa.PrimaryKeyConstraint("name", "dag_id"),
- )
-
-
-def downgrade():
- """Unapply Add ``DagTags`` table."""
- op.drop_table("dag_tag")
diff --git a/airflow/migrations/versions/0052_1_10_10_add_pool_slots_field_to_task_instance.py b/airflow/migrations/versions/0052_1_10_10_add_pool_slots_field_to_task_instance.py
deleted file mode 100644
index b4fe66baaf..0000000000
--- a/airflow/migrations/versions/0052_1_10_10_add_pool_slots_field_to_task_instance.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# 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 ``pool_slots`` field to ``task_instance``.
-
-Revision ID: a4c2fd67d16b
-Revises: 7939bcff74ba
-Create Date: 2020-01-14 03:35:01.161519
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "a4c2fd67d16b"
-down_revision = "7939bcff74ba"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.10"
-
-
-def upgrade():
- op.add_column("task_instance", sa.Column("pool_slots", sa.Integer, default=1))
-
-
-def downgrade():
- op.drop_column("task_instance", "pool_slots")
diff --git a/airflow/migrations/versions/0053_1_10_10_add_rendered_task_instance_fields_table.py b/airflow/migrations/versions/0053_1_10_10_add_rendered_task_instance_fields_table.py
deleted file mode 100644
index 779b74bf9e..0000000000
--- a/airflow/migrations/versions/0053_1_10_10_add_rendered_task_instance_fields_table.py
+++ /dev/null
@@ -1,70 +0,0 @@
-#
-# 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 ``RenderedTaskInstanceFields`` table.
-
-Revision ID: 852ae6c715af
-Revises: a4c2fd67d16b
-Create Date: 2020-03-10 22:19:18.034961
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import text
-
-from airflow.migrations.db_types import StringID
-
-# revision identifiers, used by Alembic.
-revision = "852ae6c715af"
-down_revision = "a4c2fd67d16b"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.10"
-
-TABLE_NAME = "rendered_task_instance_fields"
-
-
-def upgrade():
- """Apply Add ``RenderedTaskInstanceFields`` table."""
- json_type = sa.JSON
- conn = op.get_bind()
-
- if conn.dialect.name != "postgresql":
- # Mysql 5.7+/MariaDB 10.2.3 has JSON support. Rather than checking for
- # versions, check for the function existing.
- try:
- conn.execute(text("SELECT JSON_VALID(1)")).fetchone()
- except (sa.exc.OperationalError, sa.exc.ProgrammingError):
- json_type = sa.Text
-
- op.create_table(
- TABLE_NAME,
- sa.Column("dag_id", StringID(), nullable=False),
- sa.Column("task_id", StringID(), nullable=False),
- sa.Column("execution_date", sa.TIMESTAMP(timezone=True), nullable=False),
- sa.Column("rendered_fields", json_type(), nullable=False),
- sa.PrimaryKeyConstraint("dag_id", "task_id", "execution_date"),
- )
-
-
-def downgrade():
- """Drop RenderedTaskInstanceFields table."""
- op.drop_table(TABLE_NAME)
diff --git a/airflow/migrations/versions/0054_1_10_10_add_dag_code_table.py b/airflow/migrations/versions/0054_1_10_10_add_dag_code_table.py
deleted file mode 100644
index 63556cf7fc..0000000000
--- a/airflow/migrations/versions/0054_1_10_10_add_dag_code_table.py
+++ /dev/null
@@ -1,89 +0,0 @@
-#
-# 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 ``dag_code`` table.
-
-Revision ID: 952da73b5eff
-Revises: 852ae6c715af
-Create Date: 2020-03-12 12:39:01.797462
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.models.dagcode import DagCode
-
-# revision identifiers, used by Alembic.
-revision = "952da73b5eff"
-down_revision = "852ae6c715af"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.10"
-
-
-def upgrade():
- """Create DagCode Table."""
- from sqlalchemy.orm import declarative_base
-
- Base = declarative_base()
-
- class SerializedDagModel(Base):
- __tablename__ = "serialized_dag"
-
- # There are other columns here, but these are the only ones we need for the SELECT/UPDATE we are doing
- dag_id = sa.Column(sa.String(250), primary_key=True)
- fileloc = sa.Column(sa.String(2000), nullable=False)
- fileloc_hash = sa.Column(sa.BigInteger, nullable=False)
-
- """Apply add source code table"""
- op.create_table(
- "dag_code",
- sa.Column("fileloc_hash", sa.BigInteger(), nullable=False, primary_key=True, autoincrement=False),
- sa.Column("fileloc", sa.String(length=2000), nullable=False),
- sa.Column("source_code", sa.UnicodeText(), nullable=False),
- sa.Column("last_updated", sa.TIMESTAMP(timezone=True), nullable=False),
- )
-
- conn = op.get_bind()
- if conn.dialect.name != "sqlite":
- if conn.dialect.name == "mssql":
- op.drop_index(index_name="idx_fileloc_hash", table_name="serialized_dag")
-
- op.alter_column(
- table_name="serialized_dag", column_name="fileloc_hash", type_=sa.BigInteger(), nullable=False
- )
- if conn.dialect.name == "mssql":
- op.create_index(
- index_name="idx_fileloc_hash", table_name="serialized_dag", columns=["fileloc_hash"]
- )
-
- sessionmaker = sa.orm.sessionmaker()
- session = sessionmaker(bind=conn)
- serialized_dags = session.query(SerializedDagModel).all()
- for dag in serialized_dags:
- dag.fileloc_hash = DagCode.dag_fileloc_hash(dag.fileloc)
- session.merge(dag)
- session.commit()
-
-
-def downgrade():
- """Unapply add source code table."""
- op.drop_table("dag_code")
diff --git a/airflow/migrations/versions/0055_1_10_11_add_precision_to_execution_date_in_mysql.py b/airflow/migrations/versions/0055_1_10_11_add_precision_to_execution_date_in_mysql.py
deleted file mode 100644
index 01eecc2d85..0000000000
--- a/airflow/migrations/versions/0055_1_10_11_add_precision_to_execution_date_in_mysql.py
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# 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 Precision to ``execution_date`` in ``RenderedTaskInstanceFields`` table.
-
-Revision ID: a66efa278eea
-Revises: 952da73b5eff
-Create Date: 2020-06-16 21:44:02.883132
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-from sqlalchemy.dialects import mysql
-
-# revision identifiers, used by Alembic.
-revision = "a66efa278eea"
-down_revision = "952da73b5eff"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.11"
-
-TABLE_NAME = "rendered_task_instance_fields"
-COLUMN_NAME = "execution_date"
-
-
-def upgrade():
- """Add Precision to ``execution_date`` in ``RenderedTaskInstanceFields`` table for MySQL."""
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- op.alter_column(
- table_name=TABLE_NAME, column_name=COLUMN_NAME, type_=mysql.TIMESTAMP(fsp=6), nullable=False
- )
-
-
-def downgrade():
- """Unapply Add Precision to ``execution_date`` in ``RenderedTaskInstanceFields`` table."""
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- op.alter_column(
- table_name=TABLE_NAME, column_name=COLUMN_NAME, type_=mysql.TIMESTAMP(), nullable=False
- )
diff --git a/airflow/migrations/versions/0056_1_10_12_add_dag_hash_column_to_serialized_dag_.py b/airflow/migrations/versions/0056_1_10_12_add_dag_hash_column_to_serialized_dag_.py
deleted file mode 100644
index 683cc51847..0000000000
--- a/airflow/migrations/versions/0056_1_10_12_add_dag_hash_column_to_serialized_dag_.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#
-# 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 ``dag_hash`` Column to ``serialized_dag`` table.
-
-Revision ID: da3f683c3a5a
-Revises: a66efa278eea
-Create Date: 2020-08-07 20:52:09.178296
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "da3f683c3a5a"
-down_revision = "a66efa278eea"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.12"
-
-
-def upgrade():
- """Apply Add ``dag_hash`` Column to ``serialized_dag`` table."""
- op.add_column(
- "serialized_dag",
- sa.Column("dag_hash", sa.String(32), nullable=False, server_default="Hash not calculated yet"),
- )
-
-
-def downgrade():
- """Unapply Add ``dag_hash`` Column to ``serialized_dag`` table."""
- op.drop_column("serialized_dag", "dag_hash")
diff --git a/airflow/migrations/versions/0057_1_10_13_add_fab_tables.py b/airflow/migrations/versions/0057_1_10_13_add_fab_tables.py
deleted file mode 100644
index b40543e6b4..0000000000
--- a/airflow/migrations/versions/0057_1_10_13_add_fab_tables.py
+++ /dev/null
@@ -1,185 +0,0 @@
-#
-# 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.
-"""
-Create FAB Tables.
-
-Revision ID: 92c57b58940d
-Revises: da3f683c3a5a
-Create Date: 2020-11-13 19:27:10.161814
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import inspect
-
-# revision identifiers, used by Alembic.
-revision = "92c57b58940d"
-down_revision = "da3f683c3a5a"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.13"
-
-
-def upgrade():
- """Create FAB Tables."""
- conn = op.get_bind()
- inspector = inspect(conn)
- tables = inspector.get_table_names()
- if "ab_permission" not in tables:
- op.create_table(
- "ab_permission",
- sa.Column("id", sa.Integer(), nullable=False, primary_key=True),
- sa.Column("name", sa.String(length=100), nullable=False),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("name"),
- )
-
- if "ab_view_menu" not in tables:
- op.create_table(
- "ab_view_menu",
- sa.Column("id", sa.Integer(), nullable=False, primary_key=True),
- sa.Column("name", sa.String(length=100), nullable=False),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("name"),
- )
-
- if "ab_role" not in tables:
- op.create_table(
- "ab_role",
- sa.Column("id", sa.Integer(), nullable=False, primary_key=True),
- sa.Column("name", sa.String(length=64), nullable=False),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("name"),
- )
-
- if "ab_permission_view" not in tables:
- op.create_table(
- "ab_permission_view",
- sa.Column("id", sa.Integer(), nullable=False, primary_key=True),
- sa.Column("permission_id", sa.Integer(), nullable=True),
- sa.Column("view_menu_id", sa.Integer(), nullable=True),
- sa.ForeignKeyConstraint(["permission_id"], ["ab_permission.id"]),
- sa.ForeignKeyConstraint(["view_menu_id"], ["ab_view_menu.id"]),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("permission_id", "view_menu_id"),
- )
-
- if "ab_permission_view_role" not in tables:
- op.create_table(
- "ab_permission_view_role",
- sa.Column("id", sa.Integer(), nullable=False, primary_key=True),
- sa.Column("permission_view_id", sa.Integer(), nullable=True),
- sa.Column("role_id", sa.Integer(), nullable=True),
- sa.ForeignKeyConstraint(["permission_view_id"], ["ab_permission_view.id"]),
- sa.ForeignKeyConstraint(["role_id"], ["ab_role.id"]),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("permission_view_id", "role_id"),
- )
-
- if "ab_user" not in tables:
- op.create_table(
- "ab_user",
- sa.Column("id", sa.Integer(), nullable=False, primary_key=True),
- sa.Column("first_name", sa.String(length=64), nullable=False),
- sa.Column("last_name", sa.String(length=64), nullable=False),
- sa.Column("username", sa.String(length=64), nullable=False),
- sa.Column("password", sa.String(length=256), nullable=True),
- sa.Column("active", sa.Boolean(), nullable=True),
- sa.Column("email", sa.String(length=64), nullable=False),
- sa.Column("last_login", sa.DateTime(), nullable=True),
- sa.Column("login_count", sa.Integer(), nullable=True),
- sa.Column("fail_login_count", sa.Integer(), nullable=True),
- sa.Column("created_on", sa.DateTime(), nullable=True),
- sa.Column("changed_on", sa.DateTime(), nullable=True),
- sa.Column("created_by_fk", sa.Integer(), nullable=True),
- sa.Column("changed_by_fk", sa.Integer(), nullable=True),
- sa.ForeignKeyConstraint(["changed_by_fk"], ["ab_user.id"]),
- sa.ForeignKeyConstraint(["created_by_fk"], ["ab_user.id"]),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("email"),
- sa.UniqueConstraint("username"),
- )
-
- if "ab_user_role" not in tables:
- op.create_table(
- "ab_user_role",
- sa.Column("id", sa.Integer(), nullable=False, primary_key=True),
- sa.Column("user_id", sa.Integer(), nullable=True),
- sa.Column("role_id", sa.Integer(), nullable=True),
- sa.ForeignKeyConstraint(
- ["role_id"],
- ["ab_role.id"],
- ),
- sa.ForeignKeyConstraint(
- ["user_id"],
- ["ab_user.id"],
- ),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("user_id", "role_id"),
- )
-
- if "ab_register_user" not in tables:
- op.create_table(
- "ab_register_user",
- sa.Column("id", sa.Integer(), nullable=False, primary_key=True),
- sa.Column("first_name", sa.String(length=64), nullable=False),
- sa.Column("last_name", sa.String(length=64), nullable=False),
- sa.Column("username", sa.String(length=64), nullable=False),
- sa.Column("password", sa.String(length=256), nullable=True),
- sa.Column("email", sa.String(length=64), nullable=False),
- sa.Column("registration_date", sa.DateTime(), nullable=True),
- sa.Column("registration_hash", sa.String(length=256), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("username"),
- )
-
-
-def downgrade():
- """Drop FAB Tables."""
- conn = op.get_bind()
- inspector = inspect(conn)
- tables = inspector.get_table_names()
- fab_tables = [
- "ab_permission",
- "ab_view_menu",
- "ab_role",
- "ab_permission_view",
- "ab_permission_view_role",
- "ab_user",
- "ab_user_role",
- "ab_register_user",
- ]
-
- for table in fab_tables:
- if table in tables:
- indexes = inspector.get_foreign_keys(table)
- for index in indexes:
- if conn.dialect.name != "sqlite":
- op.drop_constraint(index.get("name"), table, type_="foreignkey")
-
- for table in fab_tables:
- if table in tables:
- if conn.dialect.name == "sqlite":
- op.execute("PRAGMA foreign_keys=off")
- op.drop_table(table)
- op.execute("PRAGMA foreign_keys=on")
- else:
- op.drop_table(table)
diff --git a/airflow/migrations/versions/0058_1_10_13_increase_length_of_fab_ab_view_menu_.py b/airflow/migrations/versions/0058_1_10_13_increase_length_of_fab_ab_view_menu_.py
deleted file mode 100644
index b0fd6e24a5..0000000000
--- a/airflow/migrations/versions/0058_1_10_13_increase_length_of_fab_ab_view_menu_.py
+++ /dev/null
@@ -1,98 +0,0 @@
-#
-# 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.
-"""
-Increase length of ``Flask-AppBuilder`` ``ab_view_menu.name`` column.
-
-Revision ID: 03afc6b6f902
-Revises: 92c57b58940d
-Create Date: 2020-11-13 22:21:41.619565
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import inspect
-
-from airflow.migrations.db_types import StringID
-
-# revision identifiers, used by Alembic.
-revision = "03afc6b6f902"
-down_revision = "92c57b58940d"
-branch_labels = None
-depends_on = None
-airflow_version = "1.10.13"
-
-
-def upgrade():
- """Apply Increase length of ``Flask-AppBuilder`` ``ab_view_menu.name`` column."""
- conn = op.get_bind()
- inspector = inspect(conn)
- tables = inspector.get_table_names()
-
- if "ab_view_menu" in tables:
- if conn.dialect.name == "sqlite":
- op.execute("PRAGMA foreign_keys=off")
- op.execute(
- """
- CREATE TABLE IF NOT EXISTS ab_view_menu_dg_tmp
- (
- id INTEGER NOT NULL PRIMARY KEY,
- name VARCHAR(250) NOT NULL UNIQUE
- );
- """
- )
- op.execute("INSERT INTO ab_view_menu_dg_tmp(id, name) select id, name from ab_view_menu;")
- op.execute("DROP TABLE ab_view_menu")
- op.execute("ALTER TABLE ab_view_menu_dg_tmp rename to ab_view_menu;")
- op.execute("PRAGMA foreign_keys=on")
- else:
- op.alter_column(
- table_name="ab_view_menu",
- column_name="name",
- type_=StringID(length=250),
- nullable=False,
- )
-
-
-def downgrade():
- """Unapply Increase length of ``Flask-AppBuilder`` ``ab_view_menu.name`` column."""
- conn = op.get_bind()
- inspector = inspect(conn)
- tables = inspector.get_table_names()
- if "ab_view_menu" in tables:
- if conn.dialect.name == "sqlite":
- op.execute("PRAGMA foreign_keys=off")
- op.execute(
- """
- CREATE TABLE IF NOT EXISTS ab_view_menu_dg_tmp
- (
- id INTEGER NOT NULL PRIMARY KEY,
- name VARCHAR(100) NOT NULL UNIQUE
- );
- """
- )
- op.execute("INSERT INTO ab_view_menu_dg_tmp(id, name) select id, name from ab_view_menu;")
- op.execute("DROP TABLE ab_view_menu")
- op.execute("ALTER TABLE ab_view_menu_dg_tmp rename to ab_view_menu;")
- op.execute("PRAGMA foreign_keys=on")
- else:
- op.alter_column(
- table_name="ab_view_menu", column_name="name", type_=sa.String(length=100), nullable=False
- )
diff --git a/airflow/migrations/versions/0059_2_0_0_drop_user_and_chart.py b/airflow/migrations/versions/0059_2_0_0_drop_user_and_chart.py
deleted file mode 100644
index 3f01342c55..0000000000
--- a/airflow/migrations/versions/0059_2_0_0_drop_user_and_chart.py
+++ /dev/null
@@ -1,115 +0,0 @@
-# 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.
-"""
-Drop ``user`` and ``chart`` table.
-
-Revision ID: cf5dc11e79ad
-Revises: 03afc6b6f902
-Create Date: 2019-01-24 15:30:35.834740
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import inspect, text
-from sqlalchemy.dialects import mysql
-
-# revision identifiers, used by Alembic.
-revision = "cf5dc11e79ad"
-down_revision = "03afc6b6f902"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- # We previously had a KnownEvent's table, but we deleted the table without
- # a down migration to remove it (so we didn't delete anyone's data if they
- # were happening to use the feature.
- #
- # But before we can delete the users table we need to drop the FK
-
- conn = op.get_bind()
- inspector = inspect(conn)
- tables = inspector.get_table_names()
-
- if "known_event" in tables:
- for fkey in inspector.get_foreign_keys(table_name="known_event", referred_table="users"):
- if fkey["name"]:
- with op.batch_alter_table(table_name="known_event") as bop:
- bop.drop_constraint(fkey["name"], type_="foreignkey")
-
- if "chart" in tables:
- op.drop_table(
- "chart",
- )
-
- if "users" in tables:
- op.drop_table("users")
-
-
-def downgrade():
- conn = op.get_bind()
-
- op.create_table(
- "users",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("username", sa.String(length=250), nullable=True),
- sa.Column("email", sa.String(length=500), nullable=True),
- sa.Column("password", sa.String(255)),
- sa.Column("superuser", sa.Boolean(), default=False),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("username"),
- )
-
- op.create_table(
- "chart",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("label", sa.String(length=200), nullable=True),
- sa.Column("conn_id", sa.String(length=250), nullable=False),
- sa.Column("user_id", sa.Integer(), nullable=True),
- sa.Column("chart_type", sa.String(length=100), nullable=True),
- sa.Column("sql_layout", sa.String(length=50), nullable=True),
- sa.Column("sql", sa.Text(), nullable=True),
- sa.Column("y_log_scale", sa.Boolean(), nullable=True),
- sa.Column("show_datatable", sa.Boolean(), nullable=True),
- sa.Column("show_sql", sa.Boolean(), nullable=True),
- sa.Column("height", sa.Integer(), nullable=True),
- sa.Column("default_params", sa.String(length=5000), nullable=True),
- sa.Column("x_is_date", sa.Boolean(), nullable=True),
- sa.Column("iteration_no", sa.Integer(), nullable=True),
- sa.Column("last_modified", sa.DateTime(), nullable=True),
- sa.ForeignKeyConstraint(
- ["user_id"],
- ["users.id"],
- ),
- sa.PrimaryKeyConstraint("id"),
- )
-
- if conn.dialect.name == "mysql":
- conn.execute(text("SET time_zone = '+00:00'"))
- op.alter_column(table_name="chart", column_name="last_modified", type_=mysql.TIMESTAMP(fsp=6))
- else:
- if conn.dialect.name in ("sqlite", "mssql"):
- return
-
- if conn.dialect.name == "postgresql":
- conn.execute(text("set timezone=UTC"))
-
- op.alter_column(table_name="chart", column_name="last_modified", type_=sa.TIMESTAMP(timezone=True))
diff --git a/airflow/migrations/versions/0060_2_0_0_remove_id_column_from_xcom.py b/airflow/migrations/versions/0060_2_0_0_remove_id_column_from_xcom.py
deleted file mode 100644
index 11359e4984..0000000000
--- a/airflow/migrations/versions/0060_2_0_0_remove_id_column_from_xcom.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#
-# 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 id column from xcom.
-
-Revision ID: bbf4a7ad0465
-Revises: cf5dc11e79ad
-Create Date: 2019-10-29 13:53:09.445943
-
-"""
-
-from __future__ import annotations
-
-from collections import defaultdict
-
-from alembic import op
-from sqlalchemy import Column, Integer, inspect, text
-
-# revision identifiers, used by Alembic.
-revision = "bbf4a7ad0465"
-down_revision = "cf5dc11e79ad"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def get_table_constraints(conn, table_name) -> dict[tuple[str, str], list[str]]:
- """
- Get tables primary and unique constraints.
-
- This function return primary and unique constraint
- along with column name. Some tables like `task_instance`
- is missing the primary key constraint name and the name is
- auto-generated by the SQL server. so this function helps to
- retrieve any primary or unique constraint name.
-
- :param conn: sql connection object
- :param table_name: table name
- :return: a dictionary of ((constraint name, constraint type), column name) of table
- """
- query = text(
- f"""SELECT tc.CONSTRAINT_NAME , tc.CONSTRAINT_TYPE, ccu.COLUMN_NAME
- FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
- JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu ON ccu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
- WHERE tc.TABLE_NAME = '{table_name}' AND
- (tc.CONSTRAINT_TYPE = 'PRIMARY KEY' or UPPER(tc.CONSTRAINT_TYPE) = 'UNIQUE')
- """
- )
- result = conn.execute(query).fetchall()
- constraint_dict = defaultdict(list)
- for constraint, constraint_type, column in result:
- constraint_dict[(constraint, constraint_type)].append(column)
- return constraint_dict
-
-
-def drop_column_constraints(operator, column_name, constraint_dict):
- """
- Drop a primary key or unique constraint.
-
- :param operator: batch_alter_table for the table
- :param constraint_dict: a dictionary of ((constraint name, constraint type), column name) of table
- """
- for constraint, columns in constraint_dict.items():
- if column_name in columns:
- if constraint[1].lower().startswith("primary"):
- operator.drop_constraint(constraint[0], type_="primary")
- elif constraint[1].lower().startswith("unique"):
- operator.drop_constraint(constraint[0], type_="unique")
-
-
-def create_constraints(operator, column_name, constraint_dict):
- """
- Create a primary key or unique constraint.
-
- :param operator: batch_alter_table for the table
- :param constraint_dict: a dictionary of ((constraint name, constraint type), column name) of table
- """
- for constraint, columns in constraint_dict.items():
- if column_name in columns:
- if constraint[1].lower().startswith("primary"):
- operator.create_primary_key(constraint_name=constraint[0], columns=columns)
- elif constraint[1].lower().startswith("unique"):
- operator.create_unique_constraint(constraint_name=constraint[0], columns=columns)
-
-
-def upgrade():
- """Apply Remove id column from xcom."""
- conn = op.get_bind()
- inspector = inspect(conn)
-
- with op.batch_alter_table("xcom") as bop:
- xcom_columns = [col.get("name") for col in inspector.get_columns("xcom")]
- if "id" in xcom_columns:
- if conn.dialect.name == "mssql":
- constraint_dict = get_table_constraints(conn, "xcom")
- drop_column_constraints(operator=bop, column_name="id", constraint_dict=constraint_dict)
- bop.drop_column("id")
- bop.drop_index("idx_xcom_dag_task_date")
- # mssql doesn't allow primary keys with nullable columns
- if conn.dialect.name != "mssql":
- bop.create_primary_key("pk_xcom", ["dag_id", "task_id", "key", "execution_date"])
-
-
-def downgrade():
- """Unapply Remove id column from xcom."""
- conn = op.get_bind()
- with op.batch_alter_table("xcom") as bop:
- if conn.dialect.name != "mssql":
- bop.drop_constraint("pk_xcom", type_="primary")
- bop.add_column(Column("id", Integer, nullable=False))
- bop.create_primary_key("id", ["id"])
- bop.create_index("idx_xcom_dag_task_date", ["dag_id", "task_id", "key", "execution_date"])
diff --git a/airflow/migrations/versions/0061_2_0_0_increase_length_of_pool_name.py b/airflow/migrations/versions/0061_2_0_0_increase_length_of_pool_name.py
deleted file mode 100644
index 4fe7762948..0000000000
--- a/airflow/migrations/versions/0061_2_0_0_increase_length_of_pool_name.py
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# 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.
-"""
-Increase length of pool name.
-
-Revision ID: b25a55525161
-Revises: bbf4a7ad0465
-Create Date: 2020-03-09 08:48:14.534700
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.models.base import COLLATION_ARGS
-
-# revision identifiers, used by Alembic.
-revision = "b25a55525161"
-down_revision = "bbf4a7ad0465"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- """Increase column length of pool name from 50 to 256 characters."""
- # use batch_alter_table to support SQLite workaround
- with op.batch_alter_table("slot_pool", table_args=sa.UniqueConstraint("pool")) as batch_op:
- batch_op.alter_column("pool", type_=sa.String(256, **COLLATION_ARGS))
-
-
-def downgrade():
- """Revert Increased length of pool name from 256 to 50 characters."""
- with op.batch_alter_table("slot_pool", table_args=sa.UniqueConstraint("pool")) as batch_op:
- batch_op.alter_column("pool", type_=sa.String(50))
diff --git a/airflow/migrations/versions/0062_2_0_0_add_dagrun_run_type.py b/airflow/migrations/versions/0062_2_0_0_add_dagrun_run_type.py
deleted file mode 100644
index be367febc8..0000000000
--- a/airflow/migrations/versions/0062_2_0_0_add_dagrun_run_type.py
+++ /dev/null
@@ -1,92 +0,0 @@
-#
-# 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 ``run_type`` column in ``dag_run`` table.
-
-Revision ID: 3c20cacc0044
-Revises: b25a55525161
-Create Date: 2020-04-08 13:35:25.671327
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import Column, Integer, String, inspect
-from sqlalchemy.orm import declarative_base
-
-from airflow.utils.types import DagRunType
-
-# revision identifiers, used by Alembic.
-revision = "3c20cacc0044"
-down_revision = "b25a55525161"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-Base = declarative_base()
-
-
-class DagRun(Base): # type: ignore
- """Minimal model definition for migrations."""
-
- __tablename__ = "dag_run"
-
- id = Column(Integer, primary_key=True)
- run_id = Column(String())
- run_type = Column(String(50), nullable=False)
-
-
-def upgrade():
- """Apply Add ``run_type`` column in ``dag_run`` table."""
- run_type_col_type = sa.String(length=50)
-
- conn = op.get_bind()
- inspector = inspect(conn)
- dag_run_columns = [col.get("name") for col in inspector.get_columns("dag_run")]
-
- if "run_type" not in dag_run_columns:
- # Add nullable column
- with op.batch_alter_table("dag_run") as batch_op:
- batch_op.add_column(sa.Column("run_type", run_type_col_type, nullable=True))
-
- # Generate run type for existing records
- sessionmaker = sa.orm.sessionmaker()
- session = sessionmaker(bind=conn)
-
- for run_type in DagRunType:
- session.query(DagRun).filter(DagRun.run_id.like(f"{run_type.value}__%")).update(
- {DagRun.run_type: run_type.value}, synchronize_session=False
- )
-
- session.query(DagRun).filter(DagRun.run_type.is_(None)).update(
- {DagRun.run_type: DagRunType.MANUAL.value}, synchronize_session=False
- )
- session.commit()
-
- # Make run_type not nullable
- with op.batch_alter_table("dag_run") as batch_op:
- batch_op.alter_column(
- "run_type", existing_type=run_type_col_type, type_=run_type_col_type, nullable=False
- )
-
-
-def downgrade():
- """Unapply Add ``run_type`` column in ``dag_run`` table."""
- op.drop_column("dag_run", "run_type")
diff --git a/airflow/migrations/versions/0063_2_0_0_set_conn_type_as_non_nullable.py b/airflow/migrations/versions/0063_2_0_0_set_conn_type_as_non_nullable.py
deleted file mode 100644
index 69b5780392..0000000000
--- a/airflow/migrations/versions/0063_2_0_0_set_conn_type_as_non_nullable.py
+++ /dev/null
@@ -1,70 +0,0 @@
-#
-# 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.
-"""
-Set ``conn_type`` as non-nullable.
-
-Revision ID: 8f966b9c467a
-Revises: 3c20cacc0044
-Create Date: 2020-06-08 22:36:34.534121
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy.orm import declarative_base
-
-# revision identifiers, used by Alembic.
-revision = "8f966b9c467a"
-down_revision = "3c20cacc0044"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- """Apply Set ``conn_type`` as non-nullable."""
- Base = declarative_base()
-
- class Connection(Base):
- __tablename__ = "connection"
-
- id = sa.Column(sa.Integer(), primary_key=True)
- conn_id = sa.Column(sa.String(250))
- conn_type = sa.Column(sa.String(500))
-
- # Generate run type for existing records
- connection = op.get_bind()
- sessionmaker = sa.orm.sessionmaker()
- session = sessionmaker(bind=connection)
-
- # imap_default was missing it's type, let's fix that up
- session.query(Connection).filter_by(conn_id="imap_default", conn_type=None).update(
- {Connection.conn_type: "imap"}, synchronize_session=False
- )
- session.commit()
-
- with op.batch_alter_table("connection", schema=None) as batch_op:
- batch_op.alter_column("conn_type", existing_type=sa.VARCHAR(length=500), nullable=False)
-
-
-def downgrade():
- """Unapply Set ``conn_type`` as non-nullable."""
- with op.batch_alter_table("connection", schema=None) as batch_op:
- batch_op.alter_column("conn_type", existing_type=sa.VARCHAR(length=500), nullable=True)
diff --git a/airflow/migrations/versions/0064_2_0_0_add_unique_constraint_to_conn_id.py b/airflow/migrations/versions/0064_2_0_0_add_unique_constraint_to_conn_id.py
deleted file mode 100644
index b0c9cacbce..0000000000
--- a/airflow/migrations/versions/0064_2_0_0_add_unique_constraint_to_conn_id.py
+++ /dev/null
@@ -1,60 +0,0 @@
-#
-# 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 unique constraint to ``conn_id``.
-
-Revision ID: 8d48763f6d53
-Revises: 8f966b9c467a
-Create Date: 2020-05-03 16:55:01.834231
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.exceptions import AirflowException
-from airflow.models.base import COLLATION_ARGS
-
-# revision identifiers, used by Alembic.
-revision = "8d48763f6d53"
-down_revision = "8f966b9c467a"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- """Apply Add unique constraint to ``conn_id`` and set it as non-nullable."""
- try:
- with op.batch_alter_table("connection") as batch_op:
- batch_op.alter_column("conn_id", nullable=False, existing_type=sa.String(250, **COLLATION_ARGS))
- batch_op.create_unique_constraint(constraint_name="unique_conn_id", columns=["conn_id"])
- except sa.exc.IntegrityError:
- raise AirflowException(
- "Make sure there are no duplicate connections with the same conn_id or null values"
- )
-
-
-def downgrade():
- """Unapply Add unique constraint to ``conn_id`` and set it as non-nullable."""
- with op.batch_alter_table("connection") as batch_op:
- batch_op.drop_constraint(constraint_name="unique_conn_id", type_="unique")
-
- batch_op.alter_column("conn_id", nullable=True, existing_type=sa.String(250))
diff --git a/airflow/migrations/versions/0065_2_0_0_update_schema_for_smart_sensor.py b/airflow/migrations/versions/0065_2_0_0_update_schema_for_smart_sensor.py
deleted file mode 100644
index ec17677cfd..0000000000
--- a/airflow/migrations/versions/0065_2_0_0_update_schema_for_smart_sensor.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#
-# 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 ``sensor_instance`` table.
-
-Revision ID: e38be357a868
-Revises: 8d48763f6d53
-Create Date: 2019-06-07 04:03:17.003939
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import func, inspect
-
-from airflow.migrations.db_types import TIMESTAMP, StringID
-
-# revision identifiers, used by Alembic.
-revision = "e38be357a868"
-down_revision = "8d48763f6d53"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- conn = op.get_bind()
- inspector = inspect(conn)
- tables = inspector.get_table_names()
- if "sensor_instance" in tables:
- return
-
- op.create_table(
- "sensor_instance",
- sa.Column("id", sa.Integer(), nullable=False),
- sa.Column("task_id", StringID(), nullable=False),
- sa.Column("dag_id", StringID(), nullable=False),
- sa.Column("execution_date", TIMESTAMP, nullable=False),
- sa.Column("state", sa.String(length=20), nullable=True),
- sa.Column("try_number", sa.Integer(), nullable=True),
- sa.Column("start_date", TIMESTAMP, nullable=True),
- sa.Column("operator", sa.String(length=1000), nullable=False),
- sa.Column("op_classpath", sa.String(length=1000), nullable=False),
- sa.Column("hashcode", sa.BigInteger(), nullable=False),
- sa.Column("shardcode", sa.Integer(), nullable=False),
- sa.Column("poke_context", sa.Text(), nullable=False),
- sa.Column("execution_context", sa.Text(), nullable=True),
- sa.Column("created_at", TIMESTAMP, default=func.now, nullable=False),
- sa.Column("updated_at", TIMESTAMP, default=func.now, nullable=False),
- sa.PrimaryKeyConstraint("id"),
- )
- op.create_index("ti_primary_key", "sensor_instance", ["dag_id", "task_id", "execution_date"], unique=True)
- op.create_index("si_hashcode", "sensor_instance", ["hashcode"], unique=False)
- op.create_index("si_shardcode", "sensor_instance", ["shardcode"], unique=False)
- op.create_index("si_state_shard", "sensor_instance", ["state", "shardcode"], unique=False)
- op.create_index("si_updated_at", "sensor_instance", ["updated_at"], unique=False)
-
-
-def downgrade():
- conn = op.get_bind()
- inspector = inspect(conn)
- tables = inspector.get_table_names()
- if "sensor_instance" in tables:
- op.drop_table("sensor_instance")
diff --git a/airflow/migrations/versions/0066_2_0_0_add_queued_by_job_id_to_ti.py b/airflow/migrations/versions/0066_2_0_0_add_queued_by_job_id_to_ti.py
deleted file mode 100644
index db6f53d35f..0000000000
--- a/airflow/migrations/versions/0066_2_0_0_add_queued_by_job_id_to_ti.py
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# 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 queued by Job ID to TI.
-
-Revision ID: b247b1e3d1ed
-Revises: e38be357a868
-Create Date: 2020-09-04 11:53:00.978882
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "b247b1e3d1ed"
-down_revision = "e38be357a868"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- """Apply Add queued by Job ID to TI."""
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.add_column(sa.Column("queued_by_job_id", sa.Integer(), nullable=True))
-
-
-def downgrade():
- """Unapply Add queued by Job ID to TI."""
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.drop_column("queued_by_job_id")
diff --git a/airflow/migrations/versions/0067_2_0_0_add_external_executor_id_to_ti.py b/airflow/migrations/versions/0067_2_0_0_add_external_executor_id_to_ti.py
deleted file mode 100644
index 306b293447..0000000000
--- a/airflow/migrations/versions/0067_2_0_0_add_external_executor_id_to_ti.py
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# 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 external executor ID to TI.
-
-Revision ID: e1a11ece99cc
-Revises: b247b1e3d1ed
-Create Date: 2020-09-12 08:23:45.698865
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "e1a11ece99cc"
-down_revision = "b247b1e3d1ed"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- """Apply Add external executor ID to TI."""
- with op.batch_alter_table("task_instance", schema=None) as batch_op:
- batch_op.add_column(sa.Column("external_executor_id", sa.String(length=250), nullable=True))
-
-
-def downgrade():
- """Unapply Add external executor ID to TI."""
- with op.batch_alter_table("task_instance", schema=None) as batch_op:
- batch_op.drop_column("external_executor_id")
diff --git a/airflow/migrations/versions/0068_2_0_0_drop_kuberesourceversion_and_.py b/airflow/migrations/versions/0068_2_0_0_drop_kuberesourceversion_and_.py
deleted file mode 100644
index 296abf0917..0000000000
--- a/airflow/migrations/versions/0068_2_0_0_drop_kuberesourceversion_and_.py
+++ /dev/null
@@ -1,108 +0,0 @@
-#
-# 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.
-"""
-Drop ``KubeResourceVersion`` and ``KubeWorkerId``.
-
-Revision ID: bef4f3d11e8b
-Revises: e1a11ece99cc
-Create Date: 2020-09-22 18:45:28.011654
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import inspect
-
-# revision identifiers, used by Alembic.
-revision = "bef4f3d11e8b"
-down_revision = "e1a11ece99cc"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-WORKER_UUID_TABLE = "kube_worker_uuid"
-WORKER_RESOURCEVERSION_TABLE = "kube_resource_version"
-
-
-def upgrade():
- """Apply Drop ``KubeResourceVersion`` and ``KubeWorkerId``entifier tables."""
- conn = op.get_bind()
- inspector = inspect(conn)
- tables = inspector.get_table_names()
-
- if WORKER_UUID_TABLE in tables:
- op.drop_table(WORKER_UUID_TABLE)
- if WORKER_RESOURCEVERSION_TABLE in tables:
- op.drop_table(WORKER_RESOURCEVERSION_TABLE)
-
-
-def downgrade():
- """Unapply Drop ``KubeResourceVersion`` and ``KubeWorkerId``entifier tables."""
- conn = op.get_bind()
- inspector = inspect(conn)
- tables = inspector.get_table_names()
-
- if WORKER_UUID_TABLE not in tables:
- _add_worker_uuid_table()
- if WORKER_RESOURCEVERSION_TABLE not in tables:
- _add_resource_table()
-
-
-def _add_worker_uuid_table():
- columns_and_constraints = [
- sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
- sa.Column("worker_uuid", sa.String(255)),
- ]
-
- conn = op.get_bind()
-
- # alembic creates an invalid SQL for mssql and mysql dialects
- if conn.dialect.name in {"mysql"}:
- columns_and_constraints.append(sa.CheckConstraint("one_row_id<>0", name="kube_worker_one_row_id"))
- elif conn.dialect.name not in {"mssql"}:
- columns_and_constraints.append(sa.CheckConstraint("one_row_id", name="kube_worker_one_row_id"))
-
- table = op.create_table(WORKER_UUID_TABLE, *columns_and_constraints)
-
- op.bulk_insert(table, [{"worker_uuid": ""}])
-
-
-def _add_resource_table():
- columns_and_constraints = [
- sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
- sa.Column("resource_version", sa.String(255)),
- ]
-
- conn = op.get_bind()
-
- # alembic creates an invalid SQL for mssql and mysql dialects
- if conn.dialect.name in {"mysql"}:
- columns_and_constraints.append(
- sa.CheckConstraint("one_row_id<>0", name="kube_resource_version_one_row_id")
- )
- elif conn.dialect.name not in {"mssql"}:
- columns_and_constraints.append(
- sa.CheckConstraint("one_row_id", name="kube_resource_version_one_row_id")
- )
-
- table = op.create_table(WORKER_RESOURCEVERSION_TABLE, *columns_and_constraints)
-
- op.bulk_insert(table, [{"resource_version": ""}])
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
deleted file mode 100644
index b04f8518bf..0000000000
--- a/airflow/migrations/versions/0069_2_0_0_add_scheduling_decision_to_dagrun_and_.py
+++ /dev/null
@@ -1,113 +0,0 @@
-#
-# 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 ``scheduling_decision`` to ``DagRun`` and ``DAG``.
-
-Revision ID: 98271e7606e2
-Revises: bef4f3d11e8b
-Create Date: 2020-10-01 12:13:32.968148
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.migrations.db_types import TIMESTAMP
-
-# revision identifiers, used by Alembic.
-revision = "98271e7606e2"
-down_revision = "bef4f3d11e8b"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- """Apply Add ``scheduling_decision`` to ``DagRun`` and ``DAG``."""
- conn = op.get_bind()
- is_sqlite = bool(conn.dialect.name == "sqlite")
- is_mssql = bool(conn.dialect.name == "mssql")
-
- if is_sqlite:
- op.execute("PRAGMA foreign_keys=off")
-
- 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)
- batch_op.add_column(sa.Column("dag_hash", sa.String(32), nullable=True))
-
- with op.batch_alter_table("dag", schema=None) as batch_op:
- batch_op.add_column(sa.Column("next_dagrun", TIMESTAMP, nullable=True))
- batch_op.add_column(sa.Column("next_dagrun_create_after", TIMESTAMP, nullable=True))
- # Create with nullable and no default, then ALTER to set values, to avoid table level lock
- batch_op.add_column(sa.Column("concurrency", sa.Integer(), nullable=True))
- batch_op.add_column(sa.Column("has_task_concurrency_limits", sa.Boolean(), nullable=True))
-
- batch_op.create_index("idx_next_dagrun_create_after", ["next_dagrun_create_after"], unique=False)
-
- try:
- from airflow.configuration import conf
-
- concurrency = conf.getint("core", "max_active_tasks_per_dag", fallback=16)
- except Exception:
- concurrency = 16
-
- # Set it to true here as it makes us take the slow/more complete path, and when it's next parsed by the
- # DagParser it will get set to correct value.
-
- op.execute(
- f"""
- UPDATE dag SET
- concurrency={concurrency},
- has_task_concurrency_limits={1 if is_sqlite or is_mssql else sa.true()}
- where concurrency IS NULL
- """
- )
-
- with op.batch_alter_table("dag", schema=None) as batch_op:
- batch_op.alter_column("concurrency", type_=sa.Integer(), nullable=False)
- batch_op.alter_column("has_task_concurrency_limits", type_=sa.Boolean(), nullable=False)
-
- if is_sqlite:
- op.execute("PRAGMA foreign_keys=on")
-
-
-def downgrade():
- """Unapply Add ``scheduling_decision`` to ``DagRun`` and ``DAG``."""
- conn = op.get_bind()
- is_sqlite = bool(conn.dialect.name == "sqlite")
-
- if is_sqlite:
- op.execute("PRAGMA foreign_keys=off")
-
- 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")
-
- with op.batch_alter_table("dag", schema=None) as batch_op:
- batch_op.drop_index("idx_next_dagrun_create_after")
- batch_op.drop_column("next_dagrun_create_after")
- batch_op.drop_column("next_dagrun")
- batch_op.drop_column("concurrency")
- batch_op.drop_column("has_task_concurrency_limits")
-
- if is_sqlite:
- op.execute("PRAGMA foreign_keys=on")
diff --git a/airflow/migrations/versions/0070_2_0_0_fix_mssql_exec_date_rendered_task_instance.py b/airflow/migrations/versions/0070_2_0_0_fix_mssql_exec_date_rendered_task_instance.py
deleted file mode 100644
index 45b5eccbba..0000000000
--- a/airflow/migrations/versions/0070_2_0_0_fix_mssql_exec_date_rendered_task_instance.py
+++ /dev/null
@@ -1,74 +0,0 @@
-#
-# 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.
-"""
-fix_mssql_exec_date_rendered_task_instance_fields_for_MSSQL.
-
-Revision ID: 52d53670a240
-Revises: 98271e7606e2
-Create Date: 2020-10-13 15:13:24.911486
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy.dialects import mssql
-
-# revision identifiers, used by Alembic.
-revision = "52d53670a240"
-down_revision = "98271e7606e2"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-TABLE_NAME = "rendered_task_instance_fields"
-
-
-def upgrade():
- """In MSSQL, change execution_date column type to datetime2."""
- conn = op.get_bind()
- if conn.dialect.name == "mssql":
- json_type = sa.Text
- op.drop_table(TABLE_NAME)
-
- op.create_table(
- TABLE_NAME,
- sa.Column("dag_id", sa.String(length=250), nullable=False),
- sa.Column("task_id", sa.String(length=250), nullable=False),
- sa.Column("execution_date", mssql.DATETIME2, nullable=False),
- sa.Column("rendered_fields", json_type(), nullable=False),
- sa.PrimaryKeyConstraint("dag_id", "task_id", "execution_date"),
- )
-
-
-def downgrade():
- """In MSSQL, change execution_date column type to timestamp."""
- conn = op.get_bind()
- if conn.dialect.name == "mssql":
- json_type = sa.Text
- op.drop_table(TABLE_NAME)
-
- op.create_table(
- TABLE_NAME,
- sa.Column("dag_id", sa.String(length=250), nullable=False),
- sa.Column("task_id", sa.String(length=250), nullable=False),
- sa.Column("execution_date", sa.TIMESTAMP, nullable=False),
- sa.Column("rendered_fields", json_type(), nullable=False),
- sa.PrimaryKeyConstraint("dag_id", "task_id", "execution_date"),
- )
diff --git a/airflow/migrations/versions/0071_2_0_0_add_job_id_to_dagrun_table.py b/airflow/migrations/versions/0071_2_0_0_add_job_id_to_dagrun_table.py
deleted file mode 100644
index 3df6888ce5..0000000000
--- a/airflow/migrations/versions/0071_2_0_0_add_job_id_to_dagrun_table.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# 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 ``creating_job_id`` to ``DagRun`` table.
-
-Revision ID: 364159666cbd
-Revises: 52d53670a240
-Create Date: 2020-10-10 09:08:07.332456
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "364159666cbd"
-down_revision = "52d53670a240"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- """Apply Add ``creating_job_id`` to ``DagRun`` table."""
- op.add_column("dag_run", sa.Column("creating_job_id", sa.Integer))
-
-
-def downgrade():
- """Unapply Add job_id to DagRun table."""
- op.drop_column("dag_run", "creating_job_id")
diff --git a/airflow/migrations/versions/0072_2_0_0_add_k8s_yaml_to_rendered_templates.py b/airflow/migrations/versions/0072_2_0_0_add_k8s_yaml_to_rendered_templates.py
deleted file mode 100644
index 1fe3f1fdae..0000000000
--- a/airflow/migrations/versions/0072_2_0_0_add_k8s_yaml_to_rendered_templates.py
+++ /dev/null
@@ -1,55 +0,0 @@
-#
-# 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-k8s-yaml-to-rendered-templates.
-
-Revision ID: 45ba3f1493b9
-Revises: 364159666cbd
-Create Date: 2020-10-23 23:01:52.471442
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy_jsonfield
-from alembic import op
-from sqlalchemy import Column
-
-from airflow.settings import json
-
-# revision identifiers, used by Alembic.
-revision = "45ba3f1493b9"
-down_revision = "364159666cbd"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-__tablename__ = "rendered_task_instance_fields"
-k8s_pod_yaml = Column("k8s_pod_yaml", sqlalchemy_jsonfield.JSONField(json=json), nullable=True)
-
-
-def upgrade():
- """Apply add-k8s-yaml-to-rendered-templates."""
- with op.batch_alter_table(__tablename__, schema=None) as batch_op:
- batch_op.add_column(k8s_pod_yaml)
-
-
-def downgrade():
- """Unapply add-k8s-yaml-to-rendered-templates."""
- with op.batch_alter_table(__tablename__, schema=None) as batch_op:
- batch_op.drop_column("k8s_pod_yaml")
diff --git a/airflow/migrations/versions/0073_2_0_0_prefix_dag_permissions.py b/airflow/migrations/versions/0073_2_0_0_prefix_dag_permissions.py
deleted file mode 100644
index 4a0ff8f2da..0000000000
--- a/airflow/migrations/versions/0073_2_0_0_prefix_dag_permissions.py
+++ /dev/null
@@ -1,241 +0,0 @@
-#
-# 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.
-"""
-Prefix DAG permissions.
-
-Revision ID: 849da589634d
-Revises: 45ba3f1493b9
-Create Date: 2020-10-01 17:25:10.006322
-
-"""
-
-from __future__ import annotations
-
-from flask_appbuilder import SQLA
-
-from airflow import settings
-from airflow.providers.fab.auth_manager.models import Action, Permission, Resource
-from airflow.security import permissions
-
-# revision identifiers, used by Alembic.
-revision = "849da589634d"
-down_revision = "45ba3f1493b9"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def prefix_individual_dag_permissions(session):
- dag_perms = ["can_dag_read", "can_dag_edit"]
- prefix = "DAG:"
- perms = (
- session.query(Permission)
- .join(Action)
- .filter(Action.name.in_(dag_perms))
- .join(Resource)
- .filter(Resource.name != "all_dags")
- .filter(Resource.name.notlike(prefix + "%"))
- .all()
- )
- resource_ids = {permission.resource.id for permission in perms}
- vm_query = session.query(Resource).filter(Resource.id.in_(resource_ids))
- vm_query.update({Resource.name: prefix + Resource.name}, synchronize_session=False)
- session.commit()
-
-
-def remove_prefix_in_individual_dag_permissions(session):
- dag_perms = ["can_read", "can_edit"]
- prefix = "DAG:"
- perms = (
- session.query(Permission)
- .join(Action)
- .filter(Action.name.in_(dag_perms))
- .join(Resource)
- .filter(Resource.name.like(prefix + "%"))
- .all()
- )
- for permission in perms:
- permission.resource.name = permission.resource.name[len(prefix) :]
- session.commit()
-
-
-def get_or_create_dag_resource(session):
- dag_resource = get_resource_query(session, permissions.RESOURCE_DAG).first()
- if dag_resource:
- return dag_resource
-
- dag_resource = Resource()
- dag_resource.name = permissions.RESOURCE_DAG
- session.add(dag_resource)
- session.commit()
-
- return dag_resource
-
-
-def get_or_create_all_dag_resource(session):
- all_dag_resource = get_resource_query(session, "all_dags").first()
- if all_dag_resource:
- return all_dag_resource
-
- all_dag_resource = Resource()
- all_dag_resource.name = "all_dags"
- session.add(all_dag_resource)
- session.commit()
-
- return all_dag_resource
-
-
-def get_or_create_action(session, action_name):
- action = get_action_query(session, action_name).first()
- if action:
- return action
-
- action = Action()
- action.name = action_name
- session.add(action)
- session.commit()
-
- return action
-
-
-def get_resource_query(session, resource_name):
- return session.query(Resource).filter(Resource.name == resource_name)
-
-
-def get_action_query(session, action_name):
- return session.query(Action).filter(Action.name == action_name)
-
-
-def get_permission_with_action_query(session, action):
- return session.query(Permission).filter(Permission.action == action)
-
-
-def get_permission_with_resource_query(session, resource):
- return session.query(Permission).filter(Permission.resource_id == resource.id)
-
-
-def update_permission_action(session, permission_query, action):
- permission_query.update({Permission.action_id: action.id}, synchronize_session=False)
- session.commit()
-
-
-def get_permission(session, resource, action):
- return (
- session.query(Permission)
- .filter(Permission.resource == resource)
- .filter(Permission.action == action)
- .first()
- )
-
-
-def update_permission_resource(session, permission_query, resource):
- for permission in permission_query.all():
- if not get_permission(session, resource, permission.action):
- permission.resource = resource
- else:
- session.delete(permission)
-
- session.commit()
-
-
-def migrate_to_new_dag_permissions(db):
- # Prefix individual dag perms with `DAG:`
- prefix_individual_dag_permissions(db.session)
-
- # Update existing permissions to use `can_read` instead of `can_dag_read`
- can_dag_read_action = get_action_query(db.session, "can_dag_read").first()
- old_can_dag_read_permissions = get_permission_with_action_query(db.session, can_dag_read_action)
- can_read_action = get_or_create_action(db.session, "can_read")
- update_permission_action(db.session, old_can_dag_read_permissions, can_read_action)
-
- # Update existing permissions to use `can_edit` instead of `can_dag_edit`
- can_dag_edit_action = get_action_query(db.session, "can_dag_edit").first()
- old_can_dag_edit_permissions = get_permission_with_action_query(db.session, can_dag_edit_action)
- can_edit_action = get_or_create_action(db.session, "can_edit")
- update_permission_action(db.session, old_can_dag_edit_permissions, can_edit_action)
-
- # Update existing permissions for `all_dags` resource to use `DAGs` resource.
- all_dags_resource = get_resource_query(db.session, "all_dags").first()
- if all_dags_resource:
- old_all_dags_permission = get_permission_with_resource_query(db.session, all_dags_resource)
- dag_resource = get_or_create_dag_resource(db.session)
- update_permission_resource(db.session, old_all_dags_permission, dag_resource)
-
- # Delete the `all_dags` resource
- db.session.delete(all_dags_resource)
-
- # Delete `can_dag_read` action
- if can_dag_read_action:
- db.session.delete(can_dag_read_action)
-
- # Delete `can_dag_edit` action
- if can_dag_edit_action:
- db.session.delete(can_dag_edit_action)
-
- db.session.commit()
-
-
-def undo_migrate_to_new_dag_permissions(session):
- # Remove prefix from individual dag perms
- remove_prefix_in_individual_dag_permissions(session)
-
- # Update existing permissions to use `can_dag_read` instead of `can_read`
- can_read_action = get_action_query(session, "can_read").first()
- new_can_read_permissions = get_permission_with_action_query(session, can_read_action)
- can_dag_read_action = get_or_create_action(session, "can_dag_read")
- update_permission_action(session, new_can_read_permissions, can_dag_read_action)
-
- # Update existing permissions to use `can_dag_edit` instead of `can_edit`
- can_edit_action = get_action_query(session, "can_edit").first()
- new_can_edit_permissions = get_permission_with_action_query(session, can_edit_action)
- can_dag_edit_action = get_or_create_action(session, "can_dag_edit")
- update_permission_action(session, new_can_edit_permissions, can_dag_edit_action)
-
- # Update existing permissions for `DAGs` resource to use `all_dags` resource.
- dag_resource = get_resource_query(session, permissions.RESOURCE_DAG).first()
- if dag_resource:
- new_dag_permission = get_permission_with_resource_query(session, dag_resource)
- old_all_dag_resource = get_or_create_all_dag_resource(session)
- update_permission_resource(session, new_dag_permission, old_all_dag_resource)
-
- # Delete the `DAG` resource
- session.delete(dag_resource)
-
- # Delete `can_read` action
- if can_read_action:
- session.delete(can_read_action)
-
- # Delete `can_edit` action
- if can_edit_action:
- session.delete(can_edit_action)
-
- session.commit()
-
-
-def upgrade():
- db = SQLA()
- db.session = settings.Session
- migrate_to_new_dag_permissions(db)
- db.session.commit()
- db.session.close()
-
-
-def downgrade():
- db = SQLA()
- db.session = settings.Session
- undo_migrate_to_new_dag_permissions(db.session)
diff --git a/airflow/migrations/versions/0074_2_0_0_resource_based_permissions.py b/airflow/migrations/versions/0074_2_0_0_resource_based_permissions.py
deleted file mode 100644
index db6d0e78db..0000000000
--- a/airflow/migrations/versions/0074_2_0_0_resource_based_permissions.py
+++ /dev/null
@@ -1,354 +0,0 @@
-#
-# 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.
-"""
-Resource based permissions.
-
-Revision ID: 2c6edca13270
-Revises: 849da589634d
-Create Date: 2020-10-21 00:18:52.529438
-
-"""
-
-from __future__ import annotations
-
-import logging
-
-from airflow.security import permissions
-from airflow.www.app import cached_app
-
-# revision identifiers, used by Alembic.
-revision = "2c6edca13270"
-down_revision = "849da589634d"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-mapping = {
- ("Airflow", "can_blocked"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN),
- ],
- ("Airflow", "can_clear"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_code"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_CODE),
- ],
- ("Airflow", "can_dag_details"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN),
- ],
- ("Airflow", "can_dag_stats"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN),
- ],
- ("Airflow", "can_dagrun_clear"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_DAG_RUN),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_dagrun_failed"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG_RUN),
- ],
- ("Airflow", "can_dagrun_success"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG_RUN),
- ],
- ("Airflow", permissions.ACTION_CAN_DELETE): [
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_DAG),
- ],
- ("Airflow", "can_duration"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_extra_links"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_failed"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_gantt"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_get_logs_with_metadata"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_LOG),
- ],
- ("Airflow", "can_graph"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_LOG),
- ],
- ("Airflow", "can_index"): [(permissions.ACTION_CAN_READ, "Website")],
- ("Airflow", "can_landing_times"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_log"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_LOG),
- ],
- ("Airflow", "can_paused"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG),
- ],
- ("Airflow", "can_redirect_to_external_log"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_LOG),
- ],
- ("Airflow", "can_refresh"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG),
- ],
- ("Airflow", "can_refresh_all"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG),
- ],
- ("Airflow", "can_rendered"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_run"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_CREATE, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_success"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_task"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_task_instances"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_task_stats"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_last_dagruns"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN),
- ],
- ("Airflow", "can_tree"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_LOG),
- ],
- ("Airflow", "can_tries"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("Airflow", "can_trigger"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_CREATE, permissions.RESOURCE_DAG_RUN),
- ],
- ("Airflow", "can_xcom"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_XCOM),
- ],
- ("ConfigurationView", "can_conf"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_CONFIG)],
- ("Config", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_CONFIG)],
- ("DagModelView", "can_list"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG)],
- ("DagModelView", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG)],
- ("DagModelView", "can_show"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG)],
- ("DagModelView", "show"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG)],
- ("Dags", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG)],
- ("Dags", "can_edit"): [(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG)],
- ("DagRunModelView", "clear"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_TASK_INSTANCE),
- ],
- ("DagRunModelView", "can_add"): [(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_DAG_RUN)],
- ("DagRunModelView", "can_list"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN)],
- ("DagRunModelView", "muldelete"): [(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_DAG_RUN)],
- ("DagRunModelView", "set_running"): [(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG_RUN)],
- ("DagRunModelView", "set_failed"): [(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG_RUN)],
- ("DagRunModelView", "set_success"): [(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG_RUN)],
- ("DagRun", "can_create"): [(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_DAG_RUN)],
- ("DagRun", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN)],
- ("DagRun", "can_delete"): [(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_DAG_RUN)],
- ("JobModelView", "can_list"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_JOB)],
- ("LogModelView", "can_list"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_AUDIT_LOG),
- (permissions.ACTION_CAN_ACCESS_MENU, permissions.RESOURCE_AUDIT_LOG),
- ],
- ("Logs", permissions.ACTION_CAN_ACCESS_MENU): [
- (permissions.ACTION_CAN_ACCESS_MENU, permissions.RESOURCE_AUDIT_LOG)
- ],
- ("Log", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_LOG)],
- ("SlaMissModelView", "can_list"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_SLA_MISS)],
- ("TaskInstanceModelView", "can_list"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE)
- ],
- ("TaskInstanceModelView", "clear"): [(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_TASK_INSTANCE)],
- ("TaskInstanceModelView", "set_failed"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_TASK_INSTANCE)
- ],
- ("TaskInstanceModelView", "set_retry"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_TASK_INSTANCE)
- ],
- ("TaskInstanceModelView", "set_running"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_TASK_INSTANCE)
- ],
- ("TaskInstanceModelView", "set_success"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_TASK_INSTANCE)
- ],
- ("TaskRescheduleModelView", "can_list"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_RESCHEDULE)
- ],
- ("TaskInstance", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE)],
- ("Tasks", permissions.ACTION_CAN_CREATE): [
- (permissions.ACTION_CAN_CREATE, permissions.RESOURCE_TASK_INSTANCE)
- ],
- ("Tasks", permissions.ACTION_CAN_READ): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE)
- ],
- ("Tasks", permissions.ACTION_CAN_EDIT): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_TASK_INSTANCE)
- ],
- ("Tasks", permissions.ACTION_CAN_DELETE): [
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_TASK_INSTANCE)
- ],
- ("ConnectionModelView", "can_add"): [(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_CONNECTION)],
- ("ConnectionModelView", "can_list"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_CONNECTION)],
- ("ConnectionModelView", permissions.ACTION_CAN_EDIT): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_CONNECTION)
- ],
- ("ConnectionModelView", permissions.ACTION_CAN_DELETE): [
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_CONNECTION)
- ],
- ("ConnectionModelView", "muldelete"): [(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_CONNECTION)],
- ("Connection", "can_create"): [(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_CONNECTION)],
- ("Connection", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_CONNECTION)],
- ("Connection", "can_edit"): [(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_CONNECTION)],
- ("Connection", "can_delete"): [(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_CONNECTION)],
- ("DagCode", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN)],
- ("PluginView", "can_list"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_PLUGIN)],
- ("PoolModelView", "can_add"): [(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_POOL)],
- ("PoolModelView", "can_list"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_POOL)],
- ("PoolModelView", permissions.ACTION_CAN_EDIT): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_POOL)
- ],
- ("PoolModelView", permissions.ACTION_CAN_DELETE): [
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_POOL)
- ],
- ("PoolModelView", "muldelete"): [(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_POOL)],
- ("Pool", "can_create"): [(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_POOL)],
- ("Pool", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_POOL)],
- ("Pool", "can_edit"): [(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_POOL)],
- ("Pool", "can_delete"): [(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_POOL)],
- ("VariableModelView", "can_add"): [(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_VARIABLE)],
- ("VariableModelView", "can_list"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_VARIABLE)],
- ("VariableModelView", permissions.ACTION_CAN_EDIT): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_VARIABLE)
- ],
- ("VariableModelView", permissions.ACTION_CAN_DELETE): [
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_VARIABLE)
- ],
- ("VariableModelView", "can_varimport"): [(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_VARIABLE)],
- ("VariableModelView", "muldelete"): [(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_VARIABLE)],
- ("VariableModelView", "varexport"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_VARIABLE)],
- ("Variable", "can_create"): [(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_VARIABLE)],
- ("Variable", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_VARIABLE)],
- ("Variable", "can_edit"): [(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_VARIABLE)],
- ("Variable", "can_delete"): [(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_VARIABLE)],
- ("XComModelView", "can_list"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_XCOM)],
- ("XComModelView", permissions.ACTION_CAN_DELETE): [
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_XCOM)
- ],
- ("XComModelView", "muldelete"): [(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_XCOM)],
- ("XCom", "can_read"): [(permissions.ACTION_CAN_READ, permissions.RESOURCE_XCOM)],
-}
-
-
-def remap_permissions():
- """Apply Map Airflow permissions."""
- appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
- for old, new in mapping.items():
- (old_resource_name, old_action_name) = old
- old_permission = appbuilder.sm.get_permission(old_action_name, old_resource_name)
- if not old_permission:
- continue
- for new_action_name, new_resource_name in new:
- new_permission = appbuilder.sm.create_permission(new_action_name, new_resource_name)
- for role in appbuilder.sm.get_all_roles():
- if appbuilder.sm.permission_exists_in_one_or_more_roles(
- old_resource_name, old_action_name, [role.id]
- ):
- appbuilder.sm.add_permission_to_role(role, new_permission)
- appbuilder.sm.remove_permission_from_role(role, old_permission)
- appbuilder.sm.delete_permission(old_action_name, old_resource_name)
-
- if not appbuilder.sm.get_action(old_action_name):
- continue
- resources = appbuilder.sm.get_all_resources()
- if not any(appbuilder.sm.get_permission(old_action_name, resource.name) for resource in resources):
- appbuilder.sm.delete_action(old_action_name)
-
-
-def undo_remap_permissions():
- """Unapply Map Airflow permissions."""
- appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
- for old, new in mapping.items():
- (new_resource_name, new_action_name) = new[0]
- new_permission = appbuilder.sm.get_permission(new_action_name, new_resource_name)
- if not new_permission:
- continue
- for old_resource_name, old_action_name in old:
- old_permission = appbuilder.sm.create_permission(old_action_name, old_resource_name)
- for role in appbuilder.sm.get_all_roles():
- if appbuilder.sm.permission_exists_in_one_or_more_roles(
- new_resource_name, new_action_name, [role.id]
- ):
- appbuilder.sm.add_permission_to_role(role, old_permission)
- appbuilder.sm.remove_permission_from_role(role, new_permission)
- appbuilder.sm.delete_permission(new_action_name, new_resource_name)
-
- if not appbuilder.sm.get_action(new_action_name):
- continue
- resources = appbuilder.sm.get_all_resources()
- if not any(appbuilder.sm.get_permission(new_action_name, resource.name) for resource in resources):
- appbuilder.sm.delete_action(new_action_name)
-
-
-def upgrade():
- """Apply Resource based permissions."""
- log = logging.getLogger()
- handlers = log.handlers[:]
- remap_permissions()
- log.handlers = handlers
-
-
-def downgrade():
- """Unapply Resource based permissions."""
- log = logging.getLogger()
- handlers = log.handlers[:]
- undo_remap_permissions()
- log.handlers = handlers
diff --git a/airflow/migrations/versions/0075_2_0_0_add_description_field_to_connection.py b/airflow/migrations/versions/0075_2_0_0_add_description_field_to_connection.py
deleted file mode 100644
index 94e49d0cb5..0000000000
--- a/airflow/migrations/versions/0075_2_0_0_add_description_field_to_connection.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#
-# 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 description field to ``connection`` table.
-
-Revision ID: 61ec73d9401f
-Revises: 2c6edca13270
-Create Date: 2020-09-10 14:56:30.279248
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "61ec73d9401f"
-down_revision = "2c6edca13270"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- """Apply Add description field to ``connection`` table."""
- conn = op.get_bind()
-
- with op.batch_alter_table("connection") as batch_op:
- if conn.dialect.name == "mysql":
- # Handles case where on mysql with utf8mb4 this would exceed the size of row
- # We have to set text type in this migration even if originally it was string
- # This is permanently fixed in the follow-up migration 64a7d6477aae
- batch_op.add_column(sa.Column("description", sa.Text(length=5000), nullable=True))
- else:
- batch_op.add_column(sa.Column("description", sa.String(length=5000), nullable=True))
-
-
-def downgrade():
- """Unapply Add description field to ``connection`` table."""
- with op.batch_alter_table("connection", schema=None) as batch_op:
- batch_op.drop_column("description")
diff --git a/airflow/migrations/versions/0076_2_0_0_fix_description_field_in_connection_to_.py b/airflow/migrations/versions/0076_2_0_0_fix_description_field_in_connection_to_.py
deleted file mode 100644
index 1207edc2d3..0000000000
--- a/airflow/migrations/versions/0076_2_0_0_fix_description_field_in_connection_to_.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#
-# 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.
-"""
-Fix description field in ``connection`` to be ``text``.
-
-Revision ID: 64a7d6477aae
-Revises: 61ec73d9401f
-Create Date: 2020-11-25 08:56:11.866607
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "64a7d6477aae"
-down_revision = "61ec73d9401f"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- """Apply Fix description field in ``connection`` to be ``text``."""
- conn = op.get_bind()
- if conn.dialect.name == "sqlite":
- # in sqlite TEXT and STRING column types are the same
- return
- if conn.dialect.name == "mysql":
- op.alter_column(
- "connection",
- "description",
- existing_type=sa.String(length=5000),
- type_=sa.Text(length=5000),
- existing_nullable=True,
- )
- else:
- # postgres does not allow size modifier for text type
- op.alter_column("connection", "description", existing_type=sa.String(length=5000), type_=sa.Text())
-
-
-def downgrade():
- """Unapply Fix description field in ``connection`` to be ``text``."""
- conn = op.get_bind()
- if conn.dialect.name == "sqlite":
- # in sqlite TEXT and STRING column types are the same
- return
- if conn.dialect.name == "mysql":
- op.alter_column(
- "connection",
- "description",
- existing_type=sa.Text(5000),
- type_=sa.String(length=5000),
- existing_nullable=True,
- )
- else:
- # postgres does not allow size modifier for text type
- op.alter_column(
- "connection",
- "description",
- existing_type=sa.Text(),
- type_=sa.String(length=5000),
- existing_nullable=True,
- )
diff --git a/airflow/migrations/versions/0077_2_0_0_change_field_in_dagcode_to_mediumtext_.py b/airflow/migrations/versions/0077_2_0_0_change_field_in_dagcode_to_mediumtext_.py
deleted file mode 100644
index c04910db26..0000000000
--- a/airflow/migrations/versions/0077_2_0_0_change_field_in_dagcode_to_mediumtext_.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#
-# 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.
-"""
-Change field in ``DagCode`` to ``MEDIUMTEXT`` for MySql.
-
-Revision ID: e959f08ac86c
-Revises: 64a7d6477aae
-Create Date: 2020-12-07 16:31:43.982353
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-from sqlalchemy.dialects import mysql
-
-# revision identifiers, used by Alembic.
-revision = "e959f08ac86c"
-down_revision = "64a7d6477aae"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.0"
-
-
-def upgrade():
- conn = op.get_bind()
- if conn.dialect.name == "mysql":
- op.alter_column(
- table_name="dag_code", column_name="source_code", type_=mysql.MEDIUMTEXT, nullable=False
- )
-
-
-def downgrade():
- # Do not downgrade to TEXT as it will break data
- pass
diff --git a/airflow/migrations/versions/0078_2_0_1_remove_can_read_permission_on_config_.py b/airflow/migrations/versions/0078_2_0_1_remove_can_read_permission_on_config_.py
deleted file mode 100644
index 1997c0dac8..0000000000
--- a/airflow/migrations/versions/0078_2_0_1_remove_can_read_permission_on_config_.py
+++ /dev/null
@@ -1,74 +0,0 @@
-#
-# 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 ``can_read`` permission on config resource for ``User`` and ``Viewer`` role.
-
-Revision ID: 82b7c48c147f
-Revises: e959f08ac86c
-Create Date: 2021-02-04 12:45:58.138224
-
-"""
-
-from __future__ import annotations
-
-import logging
-
-from airflow.security import permissions
-from airflow.www.app import cached_app
-
-# revision identifiers, used by Alembic.
-revision = "82b7c48c147f"
-down_revision = "e959f08ac86c"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.1"
-
-
-def upgrade():
- """Remove can_read action from config resource for User and Viewer role."""
- log = logging.getLogger()
- handlers = log.handlers[:]
-
- appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
- roles_to_modify = [role for role in appbuilder.sm.get_all_roles() if role.name in ["User", "Viewer"]]
- can_read_on_config_perm = appbuilder.sm.get_permission(
- permissions.ACTION_CAN_READ, permissions.RESOURCE_CONFIG
- )
-
- for role in roles_to_modify:
- if appbuilder.sm.permission_exists_in_one_or_more_roles(
- permissions.RESOURCE_CONFIG, permissions.ACTION_CAN_READ, [role.id]
- ):
- appbuilder.sm.remove_permission_from_role(role, can_read_on_config_perm)
-
- log.handlers = handlers
-
-
-def downgrade():
- """Add can_read action on config resource for User and Viewer role."""
- appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
- roles_to_modify = [role for role in appbuilder.sm.get_all_roles() if role.name in ["User", "Viewer"]]
- can_read_on_config_perm = appbuilder.sm.get_permission(
- permissions.ACTION_CAN_READ, permissions.RESOURCE_CONFIG
- )
-
- for role in roles_to_modify:
- if not appbuilder.sm.permission_exists_in_one_or_more_roles(
- permissions.RESOURCE_CONFIG, permissions.ACTION_CAN_READ, [role.id]
- ):
- appbuilder.sm.add_permission_to_role(role, can_read_on_config_perm)
diff --git a/airflow/migrations/versions/0079_2_0_2_increase_size_of_connection_extra_field_.py b/airflow/migrations/versions/0079_2_0_2_increase_size_of_connection_extra_field_.py
deleted file mode 100644
index 8fa96ef2b0..0000000000
--- a/airflow/migrations/versions/0079_2_0_2_increase_size_of_connection_extra_field_.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# 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.
-"""
-Increase size of ``connection.extra`` field to handle multiple RSA keys.
-
-Revision ID: 449b4072c2da
-Revises: 82b7c48c147f
-Create Date: 2020-03-16 19:02:55.337710
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "449b4072c2da"
-down_revision = "82b7c48c147f"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.2"
-
-
-def upgrade():
- """Apply increase_length_for_connection_password."""
- with op.batch_alter_table("connection", schema=None) as batch_op:
- batch_op.alter_column(
- "extra",
- existing_type=sa.VARCHAR(length=5000),
- type_=sa.TEXT(),
- existing_nullable=True,
- )
-
-
-def downgrade():
- """Unapply increase_length_for_connection_password."""
- with op.batch_alter_table("connection", schema=None) as batch_op:
- batch_op.alter_column(
- "extra",
- existing_type=sa.TEXT(),
- type_=sa.VARCHAR(length=5000),
- existing_nullable=True,
- )
diff --git a/airflow/migrations/versions/0080_2_0_2_change_default_pool_slots_to_1.py b/airflow/migrations/versions/0080_2_0_2_change_default_pool_slots_to_1.py
deleted file mode 100644
index 41363afe3f..0000000000
--- a/airflow/migrations/versions/0080_2_0_2_change_default_pool_slots_to_1.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#
-# 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.
-"""
-Change default ``pool_slots`` to ``1``.
-
-Revision ID: 8646922c8a04
-Revises: 449b4072c2da
-Create Date: 2021-02-23 23:19:22.409973
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "8646922c8a04"
-down_revision = "449b4072c2da"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.2"
-
-
-def upgrade():
- """Change default ``pool_slots`` to ``1`` and make pool_slots not nullable."""
- op.execute("UPDATE task_instance SET pool_slots = 1 WHERE pool_slots IS NULL")
- with op.batch_alter_table("task_instance", schema=None) as batch_op:
- batch_op.alter_column("pool_slots", existing_type=sa.Integer, nullable=False, server_default="1")
-
-
-def downgrade():
- """Unapply Change default ``pool_slots`` to ``1``."""
- conn = op.get_bind()
- if conn.dialect.name == "mssql":
- inspector = sa.inspect(conn.engine)
- columns = inspector.get_columns("task_instance")
- for col in columns:
- if col["name"] == "pool_slots" and col["default"] == "('1')":
- with op.batch_alter_table("task_instance", schema=None) as batch_op:
- batch_op.alter_column(
- "pool_slots", existing_type=sa.Integer, nullable=True, server_default=None
- )
- else:
- with op.batch_alter_table("task_instance", schema=None) as batch_op:
- batch_op.alter_column("pool_slots", existing_type=sa.Integer, nullable=True, server_default=None)
diff --git a/airflow/migrations/versions/0081_2_0_2_rename_last_scheduler_run_column.py b/airflow/migrations/versions/0081_2_0_2_rename_last_scheduler_run_column.py
deleted file mode 100644
index 69b3c5c1d5..0000000000
--- a/airflow/migrations/versions/0081_2_0_2_rename_last_scheduler_run_column.py
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# 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.
-"""
-Rename ``last_scheduler_run`` column in ``DAG`` table to ``last_parsed_time``.
-
-Revision ID: 2e42bb497a22
-Revises: 8646922c8a04
-Create Date: 2021-03-04 19:50:38.880942
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy.dialects import mssql
-
-# revision identifiers, used by Alembic.
-revision = "2e42bb497a22"
-down_revision = "8646922c8a04"
-branch_labels = None
-depends_on = None
-airflow_version = "2.0.2"
-
-
-def upgrade():
- """Apply Rename ``last_scheduler_run`` column in ``DAG`` table to ``last_parsed_time``."""
- conn = op.get_bind()
- if conn.dialect.name == "mssql":
- with op.batch_alter_table("dag") as batch_op:
- batch_op.alter_column(
- "last_scheduler_run", new_column_name="last_parsed_time", type_=mssql.DATETIME2(precision=6)
- )
- else:
- with op.batch_alter_table("dag") as batch_op:
- batch_op.alter_column(
- "last_scheduler_run", new_column_name="last_parsed_time", type_=sa.TIMESTAMP(timezone=True)
- )
-
-
-def downgrade():
- """Unapply Rename ``last_scheduler_run`` column in ``DAG`` table to ``last_parsed_time``."""
- conn = op.get_bind()
- if conn.dialect.name == "mssql":
- with op.batch_alter_table("dag") as batch_op:
- batch_op.alter_column(
- "last_parsed_time", new_column_name="last_scheduler_run", type_=mssql.DATETIME2(precision=6)
- )
- else:
- with op.batch_alter_table("dag") as batch_op:
- batch_op.alter_column(
- "last_parsed_time", new_column_name="last_scheduler_run", type_=sa.TIMESTAMP(timezone=True)
- )
diff --git a/airflow/migrations/versions/0082_2_1_0_increase_pool_name_size_in_taskinstance.py b/airflow/migrations/versions/0082_2_1_0_increase_pool_name_size_in_taskinstance.py
deleted file mode 100644
index 86da0393e4..0000000000
--- a/airflow/migrations/versions/0082_2_1_0_increase_pool_name_size_in_taskinstance.py
+++ /dev/null
@@ -1,56 +0,0 @@
-#
-# 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.
-"""
-Increase maximum length of pool name in ``task_instance`` table to ``256`` characters.
-
-Revision ID: 90d1635d7b86
-Revises: 2e42bb497a22
-Create Date: 2021-04-05 09:37:54.848731
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "90d1635d7b86"
-down_revision = "2e42bb497a22"
-branch_labels = None
-depends_on = None
-airflow_version = "2.1.0"
-
-
-def upgrade():
- """Apply Increase maximum length of pool name in ``task_instance`` table to ``256`` characters."""
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.alter_column("pool", type_=sa.String(256), nullable=False)
-
-
-def downgrade():
- """Unapply Increase maximum length of pool name in ``task_instance`` table to ``256`` characters."""
- conn = op.get_bind()
- if conn.dialect.name == "mssql":
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.drop_index("ti_pool")
- batch_op.alter_column("pool", type_=sa.String(50), nullable=False)
- batch_op.create_index("ti_pool", ["pool"])
- else:
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.alter_column("pool", type_=sa.String(50), nullable=False)
diff --git a/airflow/migrations/versions/0083_2_1_0_add_description_field_to_variable.py b/airflow/migrations/versions/0083_2_1_0_add_description_field_to_variable.py
deleted file mode 100644
index f10886322e..0000000000
--- a/airflow/migrations/versions/0083_2_1_0_add_description_field_to_variable.py
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# 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 description field to ``Variable`` model.
-
-Revision ID: e165e7455d70
-Revises: 90d1635d7b86
-Create Date: 2021-04-11 22:28:02.107290
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "e165e7455d70"
-down_revision = "90d1635d7b86"
-branch_labels = None
-depends_on = None
-airflow_version = "2.1.0"
-
-
-def upgrade():
- """Apply Add description field to ``Variable`` model."""
- with op.batch_alter_table("variable", schema=None) as batch_op:
- batch_op.add_column(sa.Column("description", sa.Text(), nullable=True))
-
-
-def downgrade():
- """Unapply Add description field to ``Variable`` model."""
- with op.batch_alter_table("variable", schema=None) as batch_op:
- batch_op.drop_column("description")
diff --git a/airflow/migrations/versions/0084_2_1_0_resource_based_permissions_for_default_.py b/airflow/migrations/versions/0084_2_1_0_resource_based_permissions_for_default_.py
deleted file mode 100644
index 0cd88c7d9b..0000000000
--- a/airflow/migrations/versions/0084_2_1_0_resource_based_permissions_for_default_.py
+++ /dev/null
@@ -1,206 +0,0 @@
-#
-# 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.
-"""
-Resource based permissions for default ``Flask-AppBuilder`` views.
-
-Revision ID: a13f7613ad25
-Revises: e165e7455d70
-Create Date: 2021-03-20 21:23:05.793378
-
-"""
-
-from __future__ import annotations
-
-import logging
-
-from airflow.security import permissions
-from airflow.www.app import cached_app
-
-# revision identifiers, used by Alembic.
-revision = "a13f7613ad25"
-down_revision = "e165e7455d70"
-branch_labels = None
-depends_on = None
-airflow_version = "2.1.0"
-
-
-mapping = {
- ("PermissionModelView", "can_list"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_ACTION),
- ],
- ("PermissionViewModelView", "can_list"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_PERMISSION),
- ],
- ("ResetMyPasswordView", "can_this_form_get"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PASSWORD),
- ],
- ("ResetMyPasswordView", "can_this_form_post"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_MY_PASSWORD),
- ],
- ("ResetPasswordView", "can_this_form_get"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_PASSWORD),
- ],
- ("ResetPasswordView", "can_this_form_post"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_PASSWORD),
- ],
- ("RoleModelView", "can_delete"): [
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_ROLE),
- ],
- ("RoleModelView", "can_download"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_ROLE),
- ],
- ("RoleModelView", "can_show"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_ROLE),
- ],
- ("RoleModelView", "can_list"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_ROLE),
- ],
- ("RoleModelView", "can_edit"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_ROLE),
- ],
- ("RoleModelView", "can_add"): [
- (permissions.ACTION_CAN_CREATE, permissions.RESOURCE_ROLE),
- ],
- ("RoleModelView", "can_copyrole"): [
- (permissions.ACTION_CAN_CREATE, permissions.RESOURCE_ROLE),
- ],
- ("ViewMenuModelView", "can_list"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_RESOURCE),
- ],
- ("UserDBModelView", "can_add"): [
- (permissions.ACTION_CAN_CREATE, permissions.RESOURCE_RESOURCE),
- ],
- ("UserDBModelView", "can_userinfo"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PROFILE),
- ],
- ("UserDBModelView", "can_download"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_RESOURCE),
- ],
- ("UserDBModelView", "can_show"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_RESOURCE),
- ],
- ("UserDBModelView", "can_list"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_RESOURCE),
- ],
- ("UserDBModelView", "can_edit"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_RESOURCE),
- ],
- ("UserDBModelView", "resetmypassword"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PASSWORD),
- ],
- ("UserDBModelView", "resetpasswords"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_PASSWORD),
- ],
- ("UserDBModelView", "userinfoedit"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_MY_PROFILE),
- ],
- ("UserDBModelView", "can_delete"): [
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_RESOURCE),
- ],
- ("UserInfoEditView", "can_this_form_get"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PROFILE),
- ],
- ("UserInfoEditView", "can_this_form_post"): [
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_MY_PROFILE),
- ],
- ("UserStatsChartView", "can_chart"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_USER_STATS_CHART),
- ],
- ("UserLDAPModelView", "can_userinfo"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PROFILE),
- ],
- ("UserOAuthModelView", "can_userinfo"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PROFILE),
- ],
- ("UserOIDModelView", "can_userinfo"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PROFILE),
- ],
- ("UserRemoteUserModelView", "can_userinfo"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PROFILE),
- ],
- ("DagRunModelView", "can_clear"): [
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
- (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_TASK_INSTANCE),
- ],
-}
-
-
-def remap_permissions():
- """Apply Map Airflow permissions."""
- appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
- for old, new in mapping.items():
- (old_resource_name, old_action_name) = old
- old_permission = appbuilder.sm.get_permission(old_action_name, old_resource_name)
- if not old_permission:
- continue
- for new_action_name, new_resource_name in new:
- new_permission = appbuilder.sm.create_permission(new_action_name, new_resource_name)
- for role in appbuilder.sm.get_all_roles():
- if appbuilder.sm.permission_exists_in_one_or_more_roles(
- old_resource_name, old_action_name, [role.id]
- ):
- appbuilder.sm.add_permission_to_role(role, new_permission)
- appbuilder.sm.remove_permission_from_role(role, old_permission)
- appbuilder.sm.delete_permission(old_action_name, old_resource_name)
-
- if not appbuilder.sm.get_action(old_action_name):
- continue
- resources = appbuilder.sm.get_all_resources()
- if not any(appbuilder.sm.get_permission(old_action_name, resource.name) for resource in resources):
- appbuilder.sm.delete_action(old_action_name)
-
-
-def undo_remap_permissions():
- """Unapply Map Airflow permissions."""
- appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
- for old, new in mapping.items():
- (new_resource_name, new_action_name) = new[0]
- new_permission = appbuilder.sm.get_permission(new_action_name, new_resource_name)
- if not new_permission:
- continue
- for old_action_name, old_resource_name in old:
- old_permission = appbuilder.sm.create_permission(old_action_name, old_resource_name)
- for role in appbuilder.sm.get_all_roles():
- if appbuilder.sm.permission_exists_in_one_or_more_roles(
- new_resource_name, new_action_name, [role.id]
- ):
- appbuilder.sm.add_permission_to_role(role, old_permission)
- appbuilder.sm.remove_permission_from_role(role, new_permission)
- appbuilder.sm.delete_permission(new_action_name, new_resource_name)
-
- if not appbuilder.sm.get_action(new_action_name):
- continue
- resources = appbuilder.sm.get_all_resources()
- if not any(appbuilder.sm.get_permission(new_action_name, resource.name) for resource in resources):
- appbuilder.sm.delete_action(new_action_name)
-
-
-def upgrade():
- """Apply Resource based permissions."""
- log = logging.getLogger()
- handlers = log.handlers[:]
- remap_permissions()
- log.handlers = handlers
-
-
-def downgrade():
- """Unapply Resource based permissions."""
- log = logging.getLogger()
- handlers = log.handlers[:]
- undo_remap_permissions()
- log.handlers = handlers
diff --git a/airflow/migrations/versions/0085_2_1_3_add_queued_at_column_to_dagrun_table.py b/airflow/migrations/versions/0085_2_1_3_add_queued_at_column_to_dagrun_table.py
deleted file mode 100644
index 35e96c3204..0000000000
--- a/airflow/migrations/versions/0085_2_1_3_add_queued_at_column_to_dagrun_table.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#
-# 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 ``queued_at`` column in ``dag_run`` table.
-
-Revision ID: 97cdd93827b8
-Revises: a13f7613ad25
-Create Date: 2021-06-29 21:53:48.059438
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.migrations.db_types import TIMESTAMP
-
-# revision identifiers, used by Alembic.
-revision = "97cdd93827b8"
-down_revision = "a13f7613ad25"
-branch_labels = None
-depends_on = None
-airflow_version = "2.1.3"
-
-
-def upgrade():
- """Apply Add ``queued_at`` column in ``dag_run`` table."""
- op.add_column("dag_run", sa.Column("queued_at", TIMESTAMP, nullable=True))
-
-
-def downgrade():
- """Unapply Add ``queued_at`` column in ``dag_run`` table."""
- with op.batch_alter_table("dag_run") as batch_op:
- batch_op.drop_column("queued_at")
diff --git a/airflow/migrations/versions/0086_2_1_4_add_max_active_runs_column_to_dagmodel_.py b/airflow/migrations/versions/0086_2_1_4_add_max_active_runs_column_to_dagmodel_.py
deleted file mode 100644
index dbd9579ed4..0000000000
--- a/airflow/migrations/versions/0086_2_1_4_add_max_active_runs_column_to_dagmodel_.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#
-# 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 ``max_active_runs`` column to ``dag_model`` table.
-
-Revision ID: 092435bf5d12
-Revises: 97cdd93827b8
-Create Date: 2021-09-06 21:29:24.728923
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import text
-
-# revision identifiers, used by Alembic.
-revision = "092435bf5d12"
-down_revision = "97cdd93827b8"
-branch_labels = None
-depends_on = None
-airflow_version = "2.1.4"
-
-
-def upgrade():
- """Apply Add ``max_active_runs`` column to ``dag_model`` table."""
- op.add_column("dag", sa.Column("max_active_runs", sa.Integer(), nullable=True))
- with op.batch_alter_table("dag_run", schema=None) as batch_op:
- # Add index to dag_run.dag_id and also add index to dag_run.state where state==running
- batch_op.create_index("idx_dag_run_dag_id", ["dag_id"])
- batch_op.create_index(
- "idx_dag_run_running_dags",
- ["state", "dag_id"],
- postgresql_where=text("state='running'"),
- mssql_where=text("state='running'"),
- sqlite_where=text("state='running'"),
- )
-
-
-def downgrade():
- """Unapply Add ``max_active_runs`` column to ``dag_model`` table."""
- with op.batch_alter_table("dag") as batch_op:
- batch_op.drop_column("max_active_runs")
- with op.batch_alter_table("dag_run", schema=None) as batch_op:
- # Drop index to dag_run.dag_id and also drop index to dag_run.state where state==running
- batch_op.drop_index("idx_dag_run_dag_id")
- batch_op.drop_index("idx_dag_run_running_dags")
diff --git a/airflow/migrations/versions/0087_2_1_4_add_index_on_state_dag_id_for_queued_.py b/airflow/migrations/versions/0087_2_1_4_add_index_on_state_dag_id_for_queued_.py
deleted file mode 100644
index b6c12ec60e..0000000000
--- a/airflow/migrations/versions/0087_2_1_4_add_index_on_state_dag_id_for_queued_.py
+++ /dev/null
@@ -1,55 +0,0 @@
-#
-# 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 state, dag_id for queued ``dagrun``.
-
-Revision ID: ccde3e26fe78
-Revises: 092435bf5d12
-Create Date: 2021-09-08 16:35:34.867711
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-from sqlalchemy import text
-
-# revision identifiers, used by Alembic.
-revision = "ccde3e26fe78"
-down_revision = "092435bf5d12"
-branch_labels = None
-depends_on = None
-airflow_version = "2.1.4"
-
-
-def upgrade():
- """Apply Add index on state, dag_id for queued ``dagrun``."""
- with op.batch_alter_table("dag_run") as batch_op:
- batch_op.create_index(
- "idx_dag_run_queued_dags",
- ["state", "dag_id"],
- postgresql_where=text("state='queued'"),
- mssql_where=text("state='queued'"),
- sqlite_where=text("state='queued'"),
- )
-
-
-def downgrade():
- """Unapply Add index on state, dag_id for queued ``dagrun``."""
- with op.batch_alter_table("dag_run") as batch_op:
- batch_op.drop_index("idx_dag_run_queued_dags")
diff --git a/airflow/migrations/versions/0088_2_2_0_improve_mssql_compatibility.py b/airflow/migrations/versions/0088_2_2_0_improve_mssql_compatibility.py
deleted file mode 100644
index abe755f855..0000000000
--- a/airflow/migrations/versions/0088_2_2_0_improve_mssql_compatibility.py
+++ /dev/null
@@ -1,221 +0,0 @@
-#
-# 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.
-"""
-Improve MSSQL compatibility.
-
-Revision ID: 83f031fd9f1c
-Revises: ccde3e26fe78
-Create Date: 2021-04-06 12:22:02.197726
-
-"""
-
-from __future__ import annotations
-
-from collections import defaultdict
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import text
-from sqlalchemy.dialects import mssql
-
-from airflow.migrations.db_types import TIMESTAMP
-
-# revision identifiers, used by Alembic.
-revision = "83f031fd9f1c"
-down_revision = "ccde3e26fe78"
-branch_labels = None
-depends_on = None
-airflow_version = "2.2.0"
-
-
-def is_table_empty(conn, table_name):
- """
- Check if the MS SQL table is empty.
-
- :param conn: SQL connection object
- :param table_name: table name
- :return: Booelan indicating if the table is present
- """
- return conn.execute(text(f"select TOP 1 * from {table_name}")).first() is None
-
-
-def get_table_constraints(conn, table_name) -> dict[tuple[str, str], list[str]]:
- """
- Get tables primary and unique constraints.
-
- This function return primary and unique constraint
- along with column name. some tables like task_instance
- is missing primary key constraint name and the name is
- auto-generated by sql server. so this function helps to
- retrieve any primary or unique constraint name.
-
- :param conn: sql connection object
- :param table_name: table name
- :return: a dictionary of ((constraint name, constraint type), column name) of table
- """
- query = text(
- f"""SELECT tc.CONSTRAINT_NAME , tc.CONSTRAINT_TYPE, ccu.COLUMN_NAME
- FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
- JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu ON ccu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
- WHERE tc.TABLE_NAME = '{table_name}' AND
- (tc.CONSTRAINT_TYPE = 'PRIMARY KEY' or UPPER(tc.CONSTRAINT_TYPE) = 'UNIQUE')
- """
- )
- result = conn.execute(query).fetchall()
- constraint_dict = defaultdict(list)
- for constraint, constraint_type, column in result:
- constraint_dict[(constraint, constraint_type)].append(column)
- return constraint_dict
-
-
-def drop_column_constraints(operator, column_name, constraint_dict):
- """
- Drop a primary key or unique constraint.
-
- :param operator: batch_alter_table for the table
- :param constraint_dict: a dictionary of ((constraint name, constraint type), column name) of table
- """
- for constraint, columns in constraint_dict.items():
- if column_name in columns:
- if constraint[1].lower().startswith("primary"):
- operator.drop_constraint(constraint[0], type_="primary")
- elif constraint[1].lower().startswith("unique"):
- operator.drop_constraint(constraint[0], type_="unique")
-
-
-def create_constraints(operator, column_name, constraint_dict):
- """
- Create a primary key or unique constraint.
-
- :param operator: batch_alter_table for the table
- :param constraint_dict: a dictionary of ((constraint name, constraint type), column name) of table
- """
- for constraint, columns in constraint_dict.items():
- if column_name in columns:
- if constraint[1].lower().startswith("primary"):
- operator.create_primary_key(constraint_name=constraint[0], columns=columns)
- elif constraint[1].lower().startswith("unique"):
- operator.create_unique_constraint(constraint_name=constraint[0], columns=columns)
-
-
-def _is_timestamp(conn, table_name, column_name):
- query = text(
- f"""SELECT
- TYPE_NAME(C.USER_TYPE_ID) AS DATA_TYPE
- FROM SYS.COLUMNS C
- JOIN SYS.TYPES T
- ON C.USER_TYPE_ID=T.USER_TYPE_ID
- WHERE C.OBJECT_ID=OBJECT_ID('{table_name}') and C.NAME='{column_name}';
- """
- )
- column_type = conn.execute(query).fetchone()[0]
- return column_type == "timestamp"
-
-
-def recreate_mssql_ts_column(conn, op, table_name, column_name):
- """Drop the timestamp column and recreate it as datetime or datetime2(6)."""
- if _is_timestamp(conn, table_name, column_name) and is_table_empty(conn, table_name):
- with op.batch_alter_table(table_name) as batch_op:
- constraint_dict = get_table_constraints(conn, table_name)
- drop_column_constraints(batch_op, column_name, constraint_dict)
- batch_op.drop_column(column_name=column_name)
- batch_op.add_column(sa.Column(column_name, TIMESTAMP, nullable=False))
- create_constraints(batch_op, column_name, constraint_dict)
-
-
-def alter_mssql_datetime_column(conn, op, table_name, column_name, nullable):
- """Update the datetime column to datetime2(6)."""
- op.alter_column(
- table_name=table_name,
- column_name=column_name,
- type_=mssql.DATETIME2(precision=6),
- nullable=nullable,
- )
-
-
-def upgrade():
- """Improve compatibility with MSSQL backend."""
- conn = op.get_bind()
- if conn.dialect.name != "mssql":
- return
- recreate_mssql_ts_column(conn, op, "dag_code", "last_updated")
- recreate_mssql_ts_column(conn, op, "rendered_task_instance_fields", "execution_date")
- alter_mssql_datetime_column(conn, op, "serialized_dag", "last_updated", False)
- op.alter_column(table_name="xcom", column_name="timestamp", type_=TIMESTAMP, nullable=False)
- with op.batch_alter_table("task_reschedule") as task_reschedule_batch_op:
- task_reschedule_batch_op.alter_column(column_name="end_date", type_=TIMESTAMP, nullable=False)
- task_reschedule_batch_op.alter_column(column_name="reschedule_date", type_=TIMESTAMP, nullable=False)
- task_reschedule_batch_op.alter_column(column_name="start_date", type_=TIMESTAMP, nullable=False)
- with op.batch_alter_table("task_fail") as task_fail_batch_op:
- task_fail_batch_op.drop_index("idx_task_fail_dag_task_date")
- task_fail_batch_op.alter_column(column_name="execution_date", type_=TIMESTAMP, nullable=False)
- task_fail_batch_op.create_index(
- "idx_task_fail_dag_task_date", ["dag_id", "task_id", "execution_date"], unique=False
- )
- with op.batch_alter_table("task_instance") as task_instance_batch_op:
- task_instance_batch_op.drop_index("ti_state_lkp")
- task_instance_batch_op.create_index(
- "ti_state_lkp", ["dag_id", "task_id", "execution_date", "state"], unique=False
- )
- constraint_dict = get_table_constraints(conn, "dag_run")
- for constraint, columns in constraint_dict.items():
- if "dag_id" in columns:
- if constraint[1].lower().startswith("unique"):
- op.drop_constraint(constraint[0], "dag_run", type_="unique")
- # create filtered indexes
- conn.execute(
- text(
- """CREATE UNIQUE NONCLUSTERED INDEX idx_not_null_dag_id_execution_date
- ON dag_run(dag_id,execution_date)
- WHERE dag_id IS NOT NULL and execution_date is not null"""
- )
- )
- conn.execute(
- text(
- """CREATE UNIQUE NONCLUSTERED INDEX idx_not_null_dag_id_run_id
- ON dag_run(dag_id,run_id)
- WHERE dag_id IS NOT NULL and run_id is not null"""
- )
- )
-
-
-def downgrade():
- """Reverse MSSQL backend compatibility improvements."""
- conn = op.get_bind()
- if conn.dialect.name != "mssql":
- return
- op.alter_column(table_name="xcom", column_name="timestamp", type_=TIMESTAMP, nullable=True)
- with op.batch_alter_table("task_reschedule") as task_reschedule_batch_op:
- task_reschedule_batch_op.alter_column(column_name="end_date", type_=TIMESTAMP, nullable=True)
- task_reschedule_batch_op.alter_column(column_name="reschedule_date", type_=TIMESTAMP, nullable=True)
- task_reschedule_batch_op.alter_column(column_name="start_date", type_=TIMESTAMP, nullable=True)
- with op.batch_alter_table("task_fail") as task_fail_batch_op:
- task_fail_batch_op.drop_index("idx_task_fail_dag_task_date")
- task_fail_batch_op.alter_column(column_name="execution_date", type_=TIMESTAMP, nullable=False)
- task_fail_batch_op.create_index(
- "idx_task_fail_dag_task_date", ["dag_id", "task_id", "execution_date"], unique=False
- )
- with op.batch_alter_table("task_instance") as task_instance_batch_op:
- task_instance_batch_op.drop_index("ti_state_lkp")
- task_instance_batch_op.create_index(
- "ti_state_lkp", ["dag_id", "task_id", "execution_date"], unique=False
- )
- op.create_unique_constraint("UQ__dag_run__dag_id_run_id", "dag_run", ["dag_id", "run_id"])
- op.create_unique_constraint("UQ__dag_run__dag_id_execution_date", "dag_run", ["dag_id", "execution_date"])
- op.drop_index("idx_not_null_dag_id_execution_date", table_name="dag_run")
- op.drop_index("idx_not_null_dag_id_run_id", table_name="dag_run")
diff --git a/airflow/migrations/versions/0089_2_2_0_make_xcom_pkey_columns_non_nullable.py b/airflow/migrations/versions/0089_2_2_0_make_xcom_pkey_columns_non_nullable.py
deleted file mode 100644
index 7c3173044c..0000000000
--- a/airflow/migrations/versions/0089_2_2_0_make_xcom_pkey_columns_non_nullable.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#
-# 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.
-"""
-Make XCom primary key columns non-nullable.
-
-Revision ID: e9304a3141f0
-Revises: 83f031fd9f1c
-Create Date: 2021-04-06 13:22:02.197726
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-from airflow.migrations.db_types import TIMESTAMP, StringID
-
-# revision identifiers, used by Alembic.
-revision = "e9304a3141f0"
-down_revision = "83f031fd9f1c"
-branch_labels = None
-depends_on = None
-airflow_version = "2.2.0"
-
-
-def upgrade():
- """Apply Make XCom primary key columns non-nullable."""
- conn = op.get_bind()
- with op.batch_alter_table("xcom") as bop:
- bop.alter_column("key", type_=StringID(length=512), nullable=False)
- bop.alter_column("execution_date", type_=TIMESTAMP, nullable=False)
- if conn.dialect.name == "mssql":
- bop.create_primary_key(
- constraint_name="pk_xcom", columns=["dag_id", "task_id", "key", "execution_date"]
- )
-
-
-def downgrade():
- """Unapply Make XCom primary key columns non-nullable."""
- conn = op.get_bind()
- with op.batch_alter_table("xcom") as bop:
- # regardless of what the model defined, the `key` and `execution_date`
- # columns were always non-nullable for mysql, sqlite and postgres, so leave them alone
-
- if conn.dialect.name == "mssql":
- bop.drop_constraint("pk_xcom", type_="primary")
- # execution_date and key wasn't nullable in the other databases
- bop.alter_column("key", type_=StringID(length=512), nullable=True)
- bop.alter_column("execution_date", type_=TIMESTAMP, nullable=True)
diff --git a/airflow/migrations/versions/0090_2_2_0_rename_concurrency_column_in_dag_table_.py b/airflow/migrations/versions/0090_2_2_0_rename_concurrency_column_in_dag_table_.py
deleted file mode 100644
index 6eff4fd9c3..0000000000
--- a/airflow/migrations/versions/0090_2_2_0_rename_concurrency_column_in_dag_table_.py
+++ /dev/null
@@ -1,66 +0,0 @@
-#
-# 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.
-"""
-Rename ``concurrency`` column in ``dag`` table to`` max_active_tasks``.
-
-Revision ID: 30867afad44a
-Revises: e9304a3141f0
-Create Date: 2021-06-04 22:11:19.849981
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "30867afad44a"
-down_revision = "e9304a3141f0"
-branch_labels = None
-depends_on = None
-airflow_version = "2.2.0"
-
-
-def upgrade():
- """Apply Rename ``concurrency`` column in ``dag`` table to`` max_active_tasks``."""
- conn = op.get_bind()
- is_sqlite = bool(conn.dialect.name == "sqlite")
-
- if is_sqlite:
- op.execute("PRAGMA foreign_keys=off")
- with op.batch_alter_table("dag") as batch_op:
- batch_op.alter_column(
- "concurrency",
- new_column_name="max_active_tasks",
- type_=sa.Integer(),
- nullable=False,
- )
- if is_sqlite:
- op.execute("PRAGMA foreign_keys=on")
-
-
-def downgrade():
- """Unapply Rename ``concurrency`` column in ``dag`` table to`` max_active_tasks``."""
- with op.batch_alter_table("dag") as batch_op:
- batch_op.alter_column(
- "max_active_tasks",
- new_column_name="concurrency",
- type_=sa.Integer(),
- nullable=False,
- )
diff --git a/airflow/migrations/versions/0091_2_2_0_add_trigger_table_and_task_info.py b/airflow/migrations/versions/0091_2_2_0_add_trigger_table_and_task_info.py
deleted file mode 100644
index a1e2e3ca97..0000000000
--- a/airflow/migrations/versions/0091_2_2_0_add_trigger_table_and_task_info.py
+++ /dev/null
@@ -1,72 +0,0 @@
-#
-# 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.
-"""
-Adds ``trigger`` table and deferrable operator columns to task instance.
-
-Revision ID: 54bebd308c5f
-Revises: 30867afad44a
-Create Date: 2021-04-14 12:56:40.688260
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.utils.sqlalchemy import ExtendedJSON
-
-# revision identifiers, used by Alembic.
-revision = "54bebd308c5f"
-down_revision = "30867afad44a"
-branch_labels = None
-depends_on = None
-airflow_version = "2.2.0"
-
-
-def upgrade():
- """Apply Adds ``trigger`` table and deferrable operator columns to task instance."""
- op.create_table(
- "trigger",
- sa.Column("id", sa.Integer(), primary_key=True, nullable=False),
- sa.Column("classpath", sa.String(length=1000), nullable=False),
- sa.Column("kwargs", ExtendedJSON(), nullable=False),
- sa.Column("created_date", sa.DateTime(), nullable=False),
- sa.Column("triggerer_id", sa.Integer(), nullable=True),
- )
- with op.batch_alter_table("task_instance", schema=None) as batch_op:
- batch_op.add_column(sa.Column("trigger_id", sa.Integer()))
- batch_op.add_column(sa.Column("trigger_timeout", sa.DateTime()))
- batch_op.add_column(sa.Column("next_method", sa.String(length=1000)))
- batch_op.add_column(sa.Column("next_kwargs", ExtendedJSON()))
- batch_op.create_foreign_key(
- "task_instance_trigger_id_fkey", "trigger", ["trigger_id"], ["id"], ondelete="CASCADE"
- )
- batch_op.create_index("ti_trigger_id", ["trigger_id"])
-
-
-def downgrade():
- """Unapply Adds ``trigger`` table and deferrable operator columns to task instance."""
- with op.batch_alter_table("task_instance", schema=None) as batch_op:
- batch_op.drop_constraint("task_instance_trigger_id_fkey", type_="foreignkey")
- batch_op.drop_index("ti_trigger_id")
- batch_op.drop_column("trigger_id")
- batch_op.drop_column("trigger_timeout")
- batch_op.drop_column("next_method")
- batch_op.drop_column("next_kwargs")
- op.drop_table("trigger")
diff --git a/airflow/migrations/versions/0092_2_2_0_add_data_interval_start_end_to_dagmodel_and_dagrun.py b/airflow/migrations/versions/0092_2_2_0_add_data_interval_start_end_to_dagmodel_and_dagrun.py
deleted file mode 100644
index fb87570347..0000000000
--- a/airflow/migrations/versions/0092_2_2_0_add_data_interval_start_end_to_dagmodel_and_dagrun.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# 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 data_interval_[start|end] to DagModel and DagRun.
-
-Revision ID: 142555e44c17
-Revises: 54bebd308c5f
-Create Date: 2021-06-09 08:28:02.089817
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-from sqlalchemy import Column
-
-from airflow.migrations.db_types import TIMESTAMP
-
-# Revision identifiers, used by Alembic.
-revision = "142555e44c17"
-down_revision = "54bebd308c5f"
-branch_labels = None
-depends_on = None
-airflow_version = "2.2.0"
-
-
-def upgrade():
- """Apply data_interval fields to DagModel and DagRun."""
- with op.batch_alter_table("dag_run") as batch_op:
- batch_op.add_column(Column("data_interval_start", TIMESTAMP))
- batch_op.add_column(Column("data_interval_end", TIMESTAMP))
- with op.batch_alter_table("dag") as batch_op:
- batch_op.add_column(Column("next_dagrun_data_interval_start", TIMESTAMP))
- batch_op.add_column(Column("next_dagrun_data_interval_end", TIMESTAMP))
-
-
-def downgrade():
- """Unapply data_interval fields to DagModel and DagRun."""
- with op.batch_alter_table("dag_run") as batch_op:
- batch_op.drop_column("data_interval_start")
- batch_op.drop_column("data_interval_end")
- with op.batch_alter_table("dag") as batch_op:
- batch_op.drop_column("next_dagrun_data_interval_start")
- batch_op.drop_column("next_dagrun_data_interval_end")
diff --git a/airflow/migrations/versions/0093_2_2_0_taskinstance_keyed_to_dagrun.py b/airflow/migrations/versions/0093_2_2_0_taskinstance_keyed_to_dagrun.py
deleted file mode 100644
index 6788fe3010..0000000000
--- a/airflow/migrations/versions/0093_2_2_0_taskinstance_keyed_to_dagrun.py
+++ /dev/null
@@ -1,409 +0,0 @@
-#
-# 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.
-"""
-Change ``TaskInstance`` and ``TaskReschedule`` tables from execution_date to run_id.
-
-Revision ID: 7b2661a43ba3
-Revises: 142555e44c17
-Create Date: 2021-07-15 15:26:12.710749
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy.sql import and_, column, select, table
-
-from airflow.migrations.db_types import TIMESTAMP, StringID
-from airflow.migrations.utils import get_mssql_table_constraints
-
-ID_LEN = 250
-
-# revision identifiers, used by Alembic.
-revision = "7b2661a43ba3"
-down_revision = "142555e44c17"
-branch_labels = None
-depends_on = None
-airflow_version = "2.2.0"
-
-
-# Just Enough Table to run the conditions for update.
-task_instance = table(
- "task_instance",
- column("task_id", sa.String),
- column("dag_id", sa.String),
- column("run_id", sa.String),
- column("execution_date", sa.TIMESTAMP),
-)
-task_reschedule = table(
- "task_reschedule",
- column("task_id", sa.String),
- column("dag_id", sa.String),
- column("run_id", sa.String),
- column("execution_date", sa.TIMESTAMP),
-)
-dag_run = table(
- "dag_run",
- column("dag_id", sa.String),
- column("run_id", sa.String),
- column("execution_date", sa.TIMESTAMP),
-)
-
-
-def upgrade():
- """Apply Change ``TaskInstance`` and ``TaskReschedule`` tables from execution_date to run_id."""
- conn = op.get_bind()
- dialect_name = conn.dialect.name
-
- dt_type = TIMESTAMP
- string_id_col_type = StringID()
-
- if dialect_name == "sqlite":
- naming_convention = {
- "uq": "%(table_name)s_%(column_0_N_name)s_key",
- }
- # The naming_convention force the previously un-named UNIQUE constraints to have the right name
- with op.batch_alter_table(
- "dag_run", naming_convention=naming_convention, recreate="always"
- ) as batch_op:
- batch_op.alter_column("dag_id", existing_type=string_id_col_type, nullable=False)
- batch_op.alter_column("run_id", existing_type=string_id_col_type, nullable=False)
- batch_op.alter_column("execution_date", existing_type=dt_type, nullable=False)
- elif dialect_name == "mysql":
- with op.batch_alter_table("dag_run") as batch_op:
- batch_op.alter_column(
- "dag_id", existing_type=sa.String(length=ID_LEN), type_=string_id_col_type, nullable=False
- )
- batch_op.alter_column(
- "run_id", existing_type=sa.String(length=ID_LEN), type_=string_id_col_type, nullable=False
- )
- batch_op.alter_column("execution_date", existing_type=dt_type, nullable=False)
- inspector = sa.inspect(conn.engine)
- unique_keys = inspector.get_unique_constraints("dag_run")
- for unique_key in unique_keys:
- batch_op.drop_constraint(unique_key["name"], type_="unique")
- batch_op.create_unique_constraint(
- "dag_run_dag_id_execution_date_key", ["dag_id", "execution_date"]
- )
- batch_op.create_unique_constraint("dag_run_dag_id_run_id_key", ["dag_id", "run_id"])
- elif dialect_name == "mssql":
- with op.batch_alter_table("dag_run") as batch_op:
- batch_op.drop_index("idx_not_null_dag_id_execution_date")
- batch_op.drop_index("idx_not_null_dag_id_run_id")
-
- batch_op.drop_index("dag_id_state")
- batch_op.drop_index("idx_dag_run_dag_id")
- batch_op.drop_index("idx_dag_run_running_dags")
- batch_op.drop_index("idx_dag_run_queued_dags")
-
- batch_op.alter_column("dag_id", existing_type=string_id_col_type, nullable=False)
- batch_op.alter_column("execution_date", existing_type=dt_type, nullable=False)
- batch_op.alter_column("run_id", existing_type=string_id_col_type, nullable=False)
-
- # _Somehow_ mssql was missing these constraints entirely
- batch_op.create_unique_constraint(
- "dag_run_dag_id_execution_date_key", ["dag_id", "execution_date"]
- )
- batch_op.create_unique_constraint("dag_run_dag_id_run_id_key", ["dag_id", "run_id"])
-
- batch_op.create_index("dag_id_state", ["dag_id", "state"], unique=False)
- batch_op.create_index("idx_dag_run_dag_id", ["dag_id"])
- batch_op.create_index(
- "idx_dag_run_running_dags",
- ["state", "dag_id"],
- mssql_where=sa.text("state='running'"),
- )
- batch_op.create_index(
- "idx_dag_run_queued_dags",
- ["state", "dag_id"],
- mssql_where=sa.text("state='queued'"),
- )
- else:
- # Make sure DagRun PK columns are non-nullable
- with op.batch_alter_table("dag_run", schema=None) as batch_op:
- batch_op.alter_column("dag_id", existing_type=string_id_col_type, nullable=False)
- batch_op.alter_column("execution_date", existing_type=dt_type, nullable=False)
- batch_op.alter_column("run_id", existing_type=string_id_col_type, nullable=False)
-
- # First create column nullable
- op.add_column("task_instance", sa.Column("run_id", type_=string_id_col_type, nullable=True))
- op.add_column("task_reschedule", sa.Column("run_id", type_=string_id_col_type, nullable=True))
-
- #
- # TaskReschedule has a FK to TaskInstance, so we have to update that before
- # we can drop the TI.execution_date column
-
- update_query = _multi_table_update(dialect_name, task_reschedule, task_reschedule.c.run_id)
- op.execute(update_query)
-
- with op.batch_alter_table("task_reschedule", schema=None) as batch_op:
- batch_op.alter_column(
- "run_id", existing_type=string_id_col_type, existing_nullable=True, nullable=False
- )
-
- batch_op.drop_constraint("task_reschedule_dag_task_date_fkey", type_="foreignkey")
- if dialect_name == "mysql":
- # Mysql creates an index and a constraint -- we have to drop both
- batch_op.drop_index("task_reschedule_dag_task_date_fkey")
- batch_op.alter_column(
- "dag_id", existing_type=sa.String(length=ID_LEN), type_=string_id_col_type, nullable=False
- )
- batch_op.drop_index("idx_task_reschedule_dag_task_date")
-
- # Then update the new column by selecting the right value from DagRun
- # But first we will drop and recreate indexes to make it faster
- if dialect_name == "postgresql":
- # Recreate task_instance, without execution_date and with dagrun.run_id
- op.execute(
- """
- CREATE TABLE new_task_instance AS SELECT
- ti.task_id,
- ti.dag_id,
- dag_run.run_id,
- ti.start_date,
- ti.end_date,
- ti.duration,
- ti.state,
- ti.try_number,
- ti.hostname,
- ti.unixname,
- ti.job_id,
- ti.pool,
- ti.queue,
- ti.priority_weight,
- ti.operator,
- ti.queued_dttm,
- ti.pid,
- ti.max_tries,
- ti.executor_config,
- ti.pool_slots,
- ti.queued_by_job_id,
- ti.external_executor_id,
- ti.trigger_id,
- ti.trigger_timeout,
- ti.next_method,
- ti.next_kwargs
- FROM task_instance ti
- INNER JOIN dag_run ON dag_run.dag_id = ti.dag_id AND dag_run.execution_date = ti.execution_date;
- """
- )
- op.drop_table("task_instance")
- op.rename_table("new_task_instance", "task_instance")
-
- # Fix up columns after the 'create table as select'
- with op.batch_alter_table("task_instance", schema=None) as batch_op:
- batch_op.alter_column(
- "pool", existing_type=string_id_col_type, existing_nullable=True, nullable=False
- )
- batch_op.alter_column("max_tries", existing_type=sa.Integer(), server_default="-1")
- batch_op.alter_column(
- "pool_slots", existing_type=sa.Integer(), existing_nullable=True, nullable=False
- )
- else:
- update_query = _multi_table_update(dialect_name, task_instance, task_instance.c.run_id)
- op.execute(update_query)
-
- with op.batch_alter_table("task_instance", schema=None) as batch_op:
- if dialect_name != "postgresql":
- # TODO: Is this right for non-postgres?
- if dialect_name == "mssql":
- constraints = get_mssql_table_constraints(conn, "task_instance")
- pk, _ = constraints["PRIMARY KEY"].popitem()
- batch_op.drop_constraint(pk, type_="primary")
- batch_op.drop_constraint("task_instance_pkey", type_="primary")
- batch_op.drop_index("ti_dag_date")
- batch_op.drop_index("ti_state_lkp")
- batch_op.drop_column("execution_date")
-
- # Then make it non-nullable
- batch_op.alter_column(
- "run_id", existing_type=string_id_col_type, existing_nullable=True, nullable=False
- )
- batch_op.alter_column(
- "dag_id", existing_type=string_id_col_type, existing_nullable=True, nullable=False
- )
-
- batch_op.create_primary_key("task_instance_pkey", ["dag_id", "task_id", "run_id"])
- batch_op.create_foreign_key(
- "task_instance_dag_run_fkey",
- "dag_run",
- ["dag_id", "run_id"],
- ["dag_id", "run_id"],
- ondelete="CASCADE",
- )
-
- batch_op.create_index("ti_dag_run", ["dag_id", "run_id"])
- batch_op.create_index("ti_state_lkp", ["dag_id", "task_id", "run_id", "state"])
- if dialect_name == "postgresql":
- batch_op.create_index("ti_dag_state", ["dag_id", "state"])
- batch_op.create_index("ti_job_id", ["job_id"])
- batch_op.create_index("ti_pool", ["pool", "state", "priority_weight"])
- batch_op.create_index("ti_state", ["state"])
- batch_op.create_foreign_key(
- "task_instance_trigger_id_fkey", "trigger", ["trigger_id"], ["id"], ondelete="CASCADE"
- )
- batch_op.create_index("ti_trigger_id", ["trigger_id"])
-
- with op.batch_alter_table("task_reschedule", schema=None) as batch_op:
- batch_op.drop_column("execution_date")
- batch_op.create_index(
- "idx_task_reschedule_dag_task_run",
- ["dag_id", "task_id", "run_id"],
- unique=False,
- )
- # _Now_ there is a unique constraint on the columns in TI we can re-create the FK from TaskReschedule
- batch_op.create_foreign_key(
- "task_reschedule_ti_fkey",
- "task_instance",
- ["dag_id", "task_id", "run_id"],
- ["dag_id", "task_id", "run_id"],
- ondelete="CASCADE",
- )
-
- # https://docs.microsoft.com/en-us/sql/relational-databases/errors-events/mssqlserver-1785-database-engine-error?view=sql-server-ver15
- ondelete = "CASCADE" if dialect_name != "mssql" else "NO ACTION"
- batch_op.create_foreign_key(
- "task_reschedule_dr_fkey",
- "dag_run",
- ["dag_id", "run_id"],
- ["dag_id", "run_id"],
- ondelete=ondelete,
- )
-
-
-def downgrade():
- """Unapply Change ``TaskInstance`` and ``TaskReschedule`` tables from execution_date to run_id."""
- dialect_name = op.get_bind().dialect.name
- dt_type = TIMESTAMP
- string_id_col_type = StringID()
-
- op.add_column("task_instance", sa.Column("execution_date", dt_type, nullable=True))
- op.add_column("task_reschedule", sa.Column("execution_date", dt_type, nullable=True))
-
- update_query = _multi_table_update(dialect_name, task_instance, task_instance.c.execution_date)
- op.execute(update_query)
-
- update_query = _multi_table_update(dialect_name, task_reschedule, task_reschedule.c.execution_date)
- op.execute(update_query)
-
- with op.batch_alter_table("task_reschedule", schema=None) as batch_op:
- batch_op.alter_column("execution_date", existing_type=dt_type, existing_nullable=True, nullable=False)
-
- # Can't drop PK index while there is a FK referencing it
- batch_op.drop_constraint("task_reschedule_ti_fkey", type_="foreignkey")
- batch_op.drop_constraint("task_reschedule_dr_fkey", type_="foreignkey")
- batch_op.drop_index("idx_task_reschedule_dag_task_run")
-
- with op.batch_alter_table("task_instance", schema=None) as batch_op:
- batch_op.drop_constraint("task_instance_pkey", type_="primary")
- batch_op.alter_column("execution_date", existing_type=dt_type, existing_nullable=True, nullable=False)
- if dialect_name != "mssql":
- batch_op.alter_column(
- "dag_id", existing_type=string_id_col_type, existing_nullable=False, nullable=True
- )
-
- batch_op.create_primary_key("task_instance_pkey", ["dag_id", "task_id", "execution_date"])
-
- batch_op.drop_constraint("task_instance_dag_run_fkey", type_="foreignkey")
- batch_op.drop_index("ti_dag_run")
- batch_op.drop_index("ti_state_lkp")
- batch_op.create_index("ti_state_lkp", ["dag_id", "task_id", "execution_date", "state"])
- batch_op.create_index("ti_dag_date", ["dag_id", "execution_date"], unique=False)
-
- batch_op.drop_column("run_id")
-
- with op.batch_alter_table("task_reschedule", schema=None) as batch_op:
- batch_op.drop_column("run_id")
- batch_op.create_index(
- "idx_task_reschedule_dag_task_date",
- ["dag_id", "task_id", "execution_date"],
- unique=False,
- )
- # Can only create FK once there is an index on these columns
- batch_op.create_foreign_key(
- "task_reschedule_dag_task_date_fkey",
- "task_instance",
- ["dag_id", "task_id", "execution_date"],
- ["dag_id", "task_id", "execution_date"],
- ondelete="CASCADE",
- )
- if dialect_name == "mysql":
- batch_op.create_index(
- "task_reschedule_dag_task_date_fkey", ["dag_id", "execution_date"], unique=False
- )
-
- if dialect_name == "mssql":
- with op.batch_alter_table("dag_run", schema=None) as batch_op:
- batch_op.drop_constraint("dag_run_dag_id_execution_date_key", type_="unique")
- batch_op.drop_constraint("dag_run_dag_id_run_id_key", type_="unique")
- batch_op.drop_index("dag_id_state")
- batch_op.drop_index("idx_dag_run_running_dags")
- batch_op.drop_index("idx_dag_run_queued_dags")
- batch_op.drop_index("idx_dag_run_dag_id")
-
- batch_op.alter_column("dag_id", existing_type=string_id_col_type, nullable=True)
- batch_op.alter_column("execution_date", existing_type=dt_type, nullable=True)
- batch_op.alter_column("run_id", existing_type=string_id_col_type, nullable=True)
-
- batch_op.create_index("dag_id_state", ["dag_id", "state"], unique=False)
- batch_op.create_index("idx_dag_run_dag_id", ["dag_id"])
- batch_op.create_index(
- "idx_dag_run_running_dags",
- ["state", "dag_id"],
- mssql_where=sa.text("state='running'"),
- )
- batch_op.create_index(
- "idx_dag_run_queued_dags",
- ["state", "dag_id"],
- mssql_where=sa.text("state='queued'"),
- )
- op.execute(
- """CREATE UNIQUE NONCLUSTERED INDEX idx_not_null_dag_id_execution_date
- ON dag_run(dag_id,execution_date)
- WHERE dag_id IS NOT NULL and execution_date is not null"""
- )
- op.execute(
- """CREATE UNIQUE NONCLUSTERED INDEX idx_not_null_dag_id_run_id
- ON dag_run(dag_id,run_id)
- WHERE dag_id IS NOT NULL and run_id is not null"""
- )
- else:
- with op.batch_alter_table("dag_run", schema=None) as batch_op:
- batch_op.drop_index("dag_id_state")
- batch_op.alter_column("run_id", existing_type=sa.VARCHAR(length=250), nullable=True)
- batch_op.alter_column("execution_date", existing_type=dt_type, nullable=True)
- batch_op.alter_column("dag_id", existing_type=sa.VARCHAR(length=250), nullable=True)
- batch_op.create_index("dag_id_state", ["dag_id", "state"], unique=False)
-
-
-def _multi_table_update(dialect_name, target, column):
- condition = dag_run.c.dag_id == target.c.dag_id
- if column == target.c.run_id:
- condition = and_(condition, dag_run.c.execution_date == target.c.execution_date)
- else:
- condition = and_(condition, dag_run.c.run_id == target.c.run_id)
-
- if dialect_name == "sqlite":
- # Most SQLite versions don't support multi table update (and SQLA doesn't know about it anyway), so we
- # need to do a Correlated subquery update
- sub_q = select(dag_run.c[column.name]).where(condition).scalar_subquery()
-
- return target.update().values({column: sub_q})
- else:
- return target.update().where(condition).values({column: dag_run.c[column.name]})
diff --git a/airflow/migrations/versions/0094_2_2_3_add_has_import_errors_column_to_dagmodel.py b/airflow/migrations/versions/0094_2_2_3_add_has_import_errors_column_to_dagmodel.py
deleted file mode 100644
index 2835346e38..0000000000
--- a/airflow/migrations/versions/0094_2_2_3_add_has_import_errors_column_to_dagmodel.py
+++ /dev/null
@@ -1,48 +0,0 @@
-#
-# 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 has_import_errors column to DagModel.
-
-Revision ID: be2bfac3da23
-Revises: 7b2661a43ba3
-Create Date: 2021-11-04 20:33:11.009547
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "be2bfac3da23"
-down_revision = "7b2661a43ba3"
-branch_labels = None
-depends_on = None
-airflow_version = "2.2.3"
-
-
-def upgrade():
- """Apply Add has_import_errors column to DagModel."""
- op.add_column("dag", sa.Column("has_import_errors", sa.Boolean(), server_default="0"))
-
-
-def downgrade():
- """Unapply Add has_import_errors column to DagModel."""
- with op.batch_alter_table("dag") as batch_op:
- batch_op.drop_column("has_import_errors", mssql_drop_default=True)
diff --git a/airflow/migrations/versions/0095_2_2_4_add_session_table_to_db.py b/airflow/migrations/versions/0095_2_2_4_add_session_table_to_db.py
deleted file mode 100644
index 12f657a728..0000000000
--- a/airflow/migrations/versions/0095_2_2_4_add_session_table_to_db.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#
-# 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.
-"""
-Create a ``session`` table to store web session data.
-
-Revision ID: c381b21cb7e4
-Revises: be2bfac3da23
-Create Date: 2022-01-25 13:56:35.069429
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "c381b21cb7e4"
-down_revision = "be2bfac3da23"
-branch_labels = None
-depends_on = None
-airflow_version = "2.2.4"
-
-TABLE_NAME = "session"
-
-
-def upgrade():
- """Apply Create a ``session`` table to store web session data."""
- op.create_table(
- TABLE_NAME,
- sa.Column("id", sa.Integer()),
- sa.Column("session_id", sa.String(255)),
- sa.Column("data", sa.LargeBinary()),
- sa.Column("expiry", sa.DateTime()),
- sa.PrimaryKeyConstraint("id"),
- sa.UniqueConstraint("session_id"),
- )
-
-
-def downgrade():
- """Unapply Create a ``session`` table to store web session data."""
- op.drop_table(TABLE_NAME)
diff --git a/airflow/migrations/versions/0096_2_2_4_adding_index_for_dag_id_in_job.py b/airflow/migrations/versions/0096_2_2_4_adding_index_for_dag_id_in_job.py
deleted file mode 100644
index 88ea89701e..0000000000
--- a/airflow/migrations/versions/0096_2_2_4_adding_index_for_dag_id_in_job.py
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-# 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 for ``dag_id`` column in ``job`` table.
-
-Revision ID: 587bdf053233
-Revises: c381b21cb7e4
-Create Date: 2021-12-14 10:20:12.482940
-
-"""
-
-from __future__ import annotations
-
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "587bdf053233"
-down_revision = "c381b21cb7e4"
-branch_labels = None
-depends_on = None
-airflow_version = "2.2.4"
-
-
-def upgrade():
- """Apply Add index for ``dag_id`` column in ``job`` table."""
- op.create_index("idx_job_dag_id", "job", ["dag_id"], unique=False)
-
-
-def downgrade():
- """Unapply Add index for ``dag_id`` column in ``job`` table."""
- op.drop_index("idx_job_dag_id", table_name="job")
diff --git a/airflow/migrations/versions/0097_2_3_0_increase_length_of_email_and_username.py b/airflow/migrations/versions/0097_2_3_0_increase_length_of_email_and_username.py
deleted file mode 100644
index e9b0906351..0000000000
--- a/airflow/migrations/versions/0097_2_3_0_increase_length_of_email_and_username.py
+++ /dev/null
@@ -1,84 +0,0 @@
-#
-# 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.
-"""
-Increase length of email and username in ``ab_user`` and ``ab_register_user`` table to ``256`` characters.
-
-Revision ID: 5e3ec427fdd3
-Revises: 587bdf053233
-Create Date: 2021-12-01 11:49:26.390210
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.migrations.utils import get_mssql_table_constraints
-
-# revision identifiers, used by Alembic.
-revision = "5e3ec427fdd3"
-down_revision = "587bdf053233"
-branch_labels = None
-depends_on = None
-airflow_version = "2.3.0"
-
-
-def upgrade():
- """Increase length of email from 64 to 256 characters."""
- with op.batch_alter_table("ab_user") as batch_op:
- batch_op.alter_column("username", type_=sa.String(256))
- batch_op.alter_column("email", type_=sa.String(256))
- with op.batch_alter_table("ab_register_user") as batch_op:
- batch_op.alter_column("username", type_=sa.String(256))
- batch_op.alter_column("email", type_=sa.String(256))
-
-
-def downgrade():
- """Revert length of email from 256 to 64 characters."""
- conn = op.get_bind()
- if conn.dialect.name != "mssql":
- with op.batch_alter_table("ab_user") as batch_op:
- batch_op.alter_column("username", type_=sa.String(64), nullable=False)
- batch_op.alter_column("email", type_=sa.String(64))
- with op.batch_alter_table("ab_register_user") as batch_op:
- batch_op.alter_column("username", type_=sa.String(64))
- batch_op.alter_column("email", type_=sa.String(64))
- else:
- # MSSQL doesn't drop implicit unique constraints it created
- # We need to drop the two unique constraints explicitly
- with op.batch_alter_table("ab_user") as batch_op:
- # Drop the unique constraint on username and email
- constraints = get_mssql_table_constraints(conn, "ab_user")
- unique_key, _ = constraints["UNIQUE"].popitem()
- batch_op.drop_constraint(unique_key, type_="unique")
- unique_key, _ = constraints["UNIQUE"].popitem()
- batch_op.drop_constraint(unique_key, type_="unique")
- batch_op.alter_column("username", type_=sa.String(64), nullable=False)
- batch_op.create_unique_constraint(None, ["username"])
- batch_op.alter_column("email", type_=sa.String(64))
- batch_op.create_unique_constraint(None, ["email"])
-
- with op.batch_alter_table("ab_register_user") as batch_op:
- # Drop the unique constraint on username and email
- constraints = get_mssql_table_constraints(conn, "ab_register_user")
- for k, _ in constraints.get("UNIQUE").items():
- batch_op.drop_constraint(k, type_="unique")
- batch_op.alter_column("username", type_=sa.String(64))
- batch_op.create_unique_constraint(None, ["username"])
- batch_op.alter_column("email", type_=sa.String(64))
diff --git a/airflow/migrations/versions/0098_2_3_0_added_timetable_description_column.py b/airflow/migrations/versions/0098_2_3_0_added_timetable_description_column.py
deleted file mode 100644
index 47f4bd759a..0000000000
--- a/airflow/migrations/versions/0098_2_3_0_added_timetable_description_column.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#
-# 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 ``timetable_description`` column to DagModel for UI.
-
-Revision ID: 786e3737b18f
-Revises: 5e3ec427fdd3
-Create Date: 2021-10-15 13:33:04.754052
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "786e3737b18f"
-down_revision = "5e3ec427fdd3"
-branch_labels = None
-depends_on = None
-airflow_version = "2.3.0"
-
-
-def upgrade():
- """Apply Add ``timetable_description`` column to DagModel for UI."""
- with op.batch_alter_table("dag", schema=None) as batch_op:
- batch_op.add_column(sa.Column("timetable_description", sa.String(length=1000), nullable=True))
-
-
-def downgrade():
- """Unapply Add ``timetable_description`` column to DagModel for UI."""
- is_sqlite = bool(op.get_bind().dialect.name == "sqlite")
- if is_sqlite:
- op.execute("PRAGMA foreign_keys=off")
- with op.batch_alter_table("dag") as batch_op:
- batch_op.drop_column("timetable_description")
- if is_sqlite:
- op.execute("PRAGMA foreign_keys=on")
diff --git a/airflow/migrations/versions/0099_2_3_0_add_task_log_filename_template_model.py b/airflow/migrations/versions/0099_2_3_0_add_task_log_filename_template_model.py
deleted file mode 100644
index 53cd1a2092..0000000000
--- a/airflow/migrations/versions/0099_2_3_0_add_task_log_filename_template_model.py
+++ /dev/null
@@ -1,66 +0,0 @@
-#
-# 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 ``LogTemplate`` table to track changes to config values ``log_filename_template``.
-
-Revision ID: f9da662e7089
-Revises: 786e3737b18f
-Create Date: 2021-12-09 06:11:21.044940
-"""
-
-from __future__ import annotations
-
-from alembic import op
-from sqlalchemy import Column, ForeignKey, Integer, Text
-
-from airflow.migrations.utils import disable_sqlite_fkeys
-from airflow.utils.sqlalchemy import UtcDateTime
-
-# Revision identifiers, used by Alembic.
-revision = "f9da662e7089"
-down_revision = "786e3737b18f"
-branch_labels = None
-depends_on = None
-airflow_version = "2.3.0"
-
-
-def upgrade():
- """Add model for task log template and establish fk on task instance."""
- op.create_table(
- "log_template",
- Column("id", Integer, primary_key=True, autoincrement=True),
- Column("filename", Text, nullable=False),
- Column("elasticsearch_id", Text, nullable=False),
- Column("created_at", UtcDateTime, nullable=False),
- )
- dag_run_log_filename_id = Column(
- "log_template_id",
- Integer,
- ForeignKey("log_template.id", name="task_instance_log_template_id_fkey", ondelete="NO ACTION"),
- )
-
- with disable_sqlite_fkeys(op), op.batch_alter_table("dag_run") as batch_op:
- batch_op.add_column(dag_run_log_filename_id)
-
-
-def downgrade():
- """Remove fk on task instance and model for task log filename template."""
- with op.batch_alter_table("dag_run") as batch_op:
- batch_op.drop_constraint("task_instance_log_template_id_fkey", type_="foreignkey")
- batch_op.drop_column("log_template_id")
- op.drop_table("log_template")
diff --git a/airflow/migrations/versions/0100_2_3_0_add_taskmap_and_map_id_on_taskinstance.py b/airflow/migrations/versions/0100_2_3_0_add_taskmap_and_map_id_on_taskinstance.py
deleted file mode 100644
index 8fc4c37162..0000000000
--- a/airflow/migrations/versions/0100_2_3_0_add_taskmap_and_map_id_on_taskinstance.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#
-# 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 TaskMap and map_index on TaskInstance.
-
-Add ``map_index`` column to TaskInstance to identify task-mapping,
-and a ``task_map`` table to track mapping values from XCom.
-
-Revision ID: e655c0453f75
-Revises: f9da662e7089
-Create Date: 2021-12-13 22:59:41.052584
-"""
-
-from __future__ import annotations
-
-from alembic import op
-from sqlalchemy import CheckConstraint, Column, ForeignKeyConstraint, Integer, text
-
-from airflow.models.base import StringID
-from airflow.utils.sqlalchemy import ExtendedJSON
-
-# Revision identifiers, used by Alembic.
-revision = "e655c0453f75"
-down_revision = "f9da662e7089"
-branch_labels = None
-depends_on = None
-airflow_version = "2.3.0"
-
-
-def upgrade():
- """Add TaskMap and map_index on TaskInstance."""
- # We need to first remove constraints on task_reschedule since they depend on task_instance.
- with op.batch_alter_table("task_reschedule") as batch_op:
- batch_op.drop_constraint("task_reschedule_ti_fkey", type_="foreignkey")
- batch_op.drop_index("idx_task_reschedule_dag_task_run")
-
- # Change task_instance's primary key.
- with op.batch_alter_table("task_instance") as batch_op:
- # I think we always use this name for TaskInstance after 7b2661a43ba3?
- batch_op.drop_constraint("task_instance_pkey", type_="primary")
- batch_op.add_column(Column("map_index", Integer, nullable=False, server_default=text("-1")))
- batch_op.create_primary_key("task_instance_pkey", ["dag_id", "task_id", "run_id", "map_index"])
-
- # Re-create task_reschedule's constraints.
- with op.batch_alter_table("task_reschedule") as batch_op:
- batch_op.add_column(Column("map_index", Integer, nullable=False, server_default=text("-1")))
- batch_op.create_foreign_key(
- "task_reschedule_ti_fkey",
- "task_instance",
- ["dag_id", "task_id", "run_id", "map_index"],
- ["dag_id", "task_id", "run_id", "map_index"],
- ondelete="CASCADE",
- )
- batch_op.create_index(
- "idx_task_reschedule_dag_task_run",
- ["dag_id", "task_id", "run_id", "map_index"],
- unique=False,
- )
-
- # Create task_map.
- op.create_table(
- "task_map",
- Column("dag_id", StringID(), primary_key=True),
- Column("task_id", StringID(), primary_key=True),
- Column("run_id", StringID(), primary_key=True),
- Column("map_index", Integer, primary_key=True),
- Column("length", Integer, nullable=False),
- Column("keys", ExtendedJSON, nullable=True),
- CheckConstraint("length >= 0", name="task_map_length_not_negative"),
- ForeignKeyConstraint(
- ["dag_id", "task_id", "run_id", "map_index"],
- [
- "task_instance.dag_id",
- "task_instance.task_id",
- "task_instance.run_id",
- "task_instance.map_index",
- ],
- name="task_map_task_instance_fkey",
- ondelete="CASCADE",
- ),
- )
-
-
-def downgrade():
- """Remove TaskMap and map_index on TaskInstance."""
- op.drop_table("task_map")
-
- with op.batch_alter_table("task_reschedule") as batch_op:
- batch_op.drop_constraint("task_reschedule_ti_fkey", type_="foreignkey")
- batch_op.drop_index("idx_task_reschedule_dag_task_run")
- batch_op.drop_column("map_index", mssql_drop_default=True)
-
- op.execute("DELETE FROM task_instance WHERE map_index != -1")
-
- with op.batch_alter_table("task_instance") as batch_op:
- batch_op.drop_constraint("task_instance_pkey", type_="primary")
- batch_op.drop_column("map_index", mssql_drop_default=True)
- batch_op.create_primary_key("task_instance_pkey", ["dag_id", "task_id", "run_id"])
-
- with op.batch_alter_table("task_reschedule") as batch_op:
- batch_op.create_foreign_key(
- "task_reschedule_ti_fkey",
- "task_instance",
- ["dag_id", "task_id", "run_id"],
- ["dag_id", "task_id", "run_id"],
- ondelete="CASCADE",
- )
- batch_op.create_index(
- "idx_task_reschedule_dag_task_run",
- ["dag_id", "task_id", "run_id"],
- unique=False,
- )
diff --git a/airflow/migrations/versions/0101_2_3_0_add_data_compressed_to_serialized_dag.py b/airflow/migrations/versions/0101_2_3_0_add_data_compressed_to_serialized_dag.py
deleted file mode 100644
index c7a2aa0c1a..0000000000
--- a/airflow/migrations/versions/0101_2_3_0_add_data_compressed_to_serialized_dag.py
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# 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 data_compressed to serialized_dag.
-
-Revision ID: a3bcd0914482
-Revises: e655c0453f75
-Create Date: 2022-02-03 22:40:59.841119
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-# revision identifiers, used by Alembic.
-revision = "a3bcd0914482"
-down_revision = "e655c0453f75"
-branch_labels = None
-depends_on = None
-airflow_version = "2.3.0"
-
-
-def upgrade():
- with op.batch_alter_table("serialized_dag") as batch_op:
- batch_op.alter_column("data", existing_type=sa.JSON, nullable=True)
- batch_op.add_column(sa.Column("data_compressed", sa.LargeBinary, nullable=True))
-
-
-def downgrade():
- with op.batch_alter_table("serialized_dag") as batch_op:
- batch_op.alter_column("data", existing_type=sa.JSON, nullable=False)
- batch_op.drop_column("data_compressed")
diff --git a/airflow/migrations/versions/0102_2_3_0_switch_xcom_table_to_use_run_id.py b/airflow/migrations/versions/0102_2_3_0_switch_xcom_table_to_use_run_id.py
deleted file mode 100644
index cc90ae7ce1..0000000000
--- a/airflow/migrations/versions/0102_2_3_0_switch_xcom_table_to_use_run_id.py
+++ /dev/null
@@ -1,181 +0,0 @@
-#
-# 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.
-"""
-Switch XCom table to use ``run_id`` and add ``map_index``.
-
-Revision ID: c306b5b5ae4a
-Revises: a3bcd0914482
-Create Date: 2022-01-19 03:20:35.329037
-"""
-
-from __future__ import annotations
-
-from typing import Sequence
-
-from alembic import op
-from sqlalchemy import Column, Integer, LargeBinary, MetaData, Table, and_, literal_column, select
-
-from airflow.migrations.db_types import TIMESTAMP, StringID
-from airflow.migrations.utils import get_mssql_table_constraints
-
-# Revision identifiers, used by Alembic.
-revision = "c306b5b5ae4a"
-down_revision = "a3bcd0914482"
-branch_labels = None
-depends_on = None
-airflow_version = "2.3.0"
-
-
-metadata = MetaData()
-
-
-def _get_new_xcom_columns() -> Sequence[Column]:
- return [
- Column("dag_run_id", Integer(), nullable=False),
- Column("task_id", StringID(), nullable=False),
- Column("key", StringID(length=512), nullable=False),
- Column("value", LargeBinary),
- Column("timestamp", TIMESTAMP, nullable=False),
- Column("dag_id", StringID(), nullable=False),
- Column("run_id", StringID(), nullable=False),
- Column("map_index", Integer, nullable=False, server_default="-1"),
- ]
-
-
-def _get_old_xcom_columns() -> Sequence[Column]:
- return [
- Column("key", StringID(length=512), nullable=False, primary_key=True),
- Column("value", LargeBinary),
- Column("timestamp", TIMESTAMP, nullable=False),
- Column("task_id", StringID(length=250), nullable=False, primary_key=True),
- Column("dag_id", StringID(length=250), nullable=False, primary_key=True),
- Column("execution_date", TIMESTAMP, nullable=False, primary_key=True),
- ]
-
-
-def _get_dagrun_table() -> Table:
- return Table(
- "dag_run",
- metadata,
- Column("id", Integer, primary_key=True),
- Column("dag_id", StringID(), nullable=False),
- Column("run_id", StringID(), nullable=False),
- Column("execution_date", TIMESTAMP, nullable=False),
- )
-
-
-def upgrade():
- """
- Switch XCom table to use run_id.
-
- For performance reasons, this is done by creating a new table with needed
- data pre-populated, adding back constraints we need, and renaming it to
- replace the existing XCom table.
- """
- conn = op.get_bind()
- is_sqlite = conn.dialect.name == "sqlite"
-
- op.create_table("__airflow_tmp_xcom", *_get_new_xcom_columns())
-
- xcom = Table("xcom", metadata, *_get_old_xcom_columns())
- dagrun = _get_dagrun_table()
- query = select(
- dagrun.c.id,
- xcom.c.task_id,
- xcom.c.key,
- xcom.c.value,
- xcom.c.timestamp,
- xcom.c.dag_id,
- dagrun.c.run_id,
- literal_column("-1"),
- ).select_from(
- xcom.join(
- right=dagrun,
- onclause=and_(
- xcom.c.dag_id == dagrun.c.dag_id,
- xcom.c.execution_date == dagrun.c.execution_date,
- ),
- ),
- )
- op.execute(f"INSERT INTO __airflow_tmp_xcom {query.selectable.compile(op.get_bind())}")
-
- if is_sqlite:
- op.execute("PRAGMA foreign_keys=off")
- op.drop_table("xcom")
- if is_sqlite:
- op.execute("PRAGMA foreign_keys=on")
- op.rename_table("__airflow_tmp_xcom", "xcom")
-
- with op.batch_alter_table("xcom") as batch_op:
- batch_op.create_primary_key("xcom_pkey", ["dag_run_id", "task_id", "map_index", "key"])
- batch_op.create_index("idx_xcom_key", ["key"])
- batch_op.create_foreign_key(
- "xcom_task_instance_fkey",
- "task_instance",
- ["dag_id", "task_id", "run_id", "map_index"],
- ["dag_id", "task_id", "run_id", "map_index"],
- ondelete="CASCADE",
- )
-
-
-def downgrade():
- """
- Switch XCom table back to use execution_date.
-
- Basically an inverse operation.
- """
- conn = op.get_bind()
- op.create_table("__airflow_tmp_xcom", *_get_old_xcom_columns())
-
- xcom = Table("xcom", metadata, *_get_new_xcom_columns())
-
- # Remoe XCom entries from mapped tis.
- op.execute(xcom.delete().where(xcom.c.map_index != -1))
-
- dagrun = _get_dagrun_table()
- query = select(
- [
- xcom.c.key,
- xcom.c.value,
- xcom.c.timestamp,
- xcom.c.task_id,
- xcom.c.dag_id,
- dagrun.c.execution_date,
- ],
- ).select_from(
- xcom.join(
- right=dagrun,
- onclause=and_(
- xcom.c.dag_id == dagrun.c.dag_id,
- xcom.c.run_id == dagrun.c.run_id,
- ),
- ),
- )
- op.execute(f"INSERT INTO __airflow_tmp_xcom {query.selectable.compile(op.get_bind())}")
-
- op.drop_table("xcom")
- op.rename_table("__airflow_tmp_xcom", "xcom")
- if conn.dialect.name == "mssql":
- constraints = get_mssql_table_constraints(conn, "xcom")
- pk, _ = constraints["PRIMARY KEY"].popitem()
- op.drop_constraint(pk, "xcom", type_="primary")
- op.create_primary_key(
- constraint_name="pk_xcom",
- table_name="xcom",
- columns=["dag_id", "task_id", "execution_date", "key"],
- )
diff --git a/airflow/migrations/versions/0103_2_3_0_add_callback_request_table.py b/airflow/migrations/versions/0103_2_3_0_add_callback_request_table.py
deleted file mode 100644
index 24d5048fe4..0000000000
--- a/airflow/migrations/versions/0103_2_3_0_add_callback_request_table.py
+++ /dev/null
@@ -1,60 +0,0 @@
-#
-# 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 callback request table.
-
-Revision ID: c97c2ab6aa23
-Revises: c306b5b5ae4a
-Create Date: 2022-01-28 21:11:11.857010
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy import func
-
-from airflow.migrations.db_types import TIMESTAMP
-from airflow.utils.sqlalchemy import ExtendedJSON
-
-# revision identifiers, used by Alembic.
-revision = "c97c2ab6aa23"
-down_revision = "c306b5b5ae4a"
-branch_labels = None
-depends_on = None
-airflow_version = "2.3.0"
-
-TABLE_NAME = "callback_request"
-
-
-def upgrade():
- op.create_table(
- TABLE_NAME,
- sa.Column("id", sa.Integer(), nullable=False, primary_key=True),
- sa.Column("created_at", TIMESTAMP, default=func.now, nullable=False),
- sa.Column("priority_weight", sa.Integer(), default=1, nullable=False),
- sa.Column("callback_data", ExtendedJSON, nullable=False),
- sa.Column("callback_type", sa.String(20), nullable=False),
- sa.Column("dag_directory", sa.String(length=1000), nullable=True),
- sa.PrimaryKeyConstraint("id"),
- )
-
-
-def downgrade():
- op.drop_table(TABLE_NAME)
diff --git a/airflow/migrations/versions/0104_2_3_0_migrate_rtif_to_use_run_id_and_map_index.py b/airflow/migrations/versions/0104_2_3_0_migrate_rtif_to_use_run_id_and_map_index.py
deleted file mode 100644
index 69d9f35cc9..0000000000
--- a/airflow/migrations/versions/0104_2_3_0_migrate_rtif_to_use_run_id_and_map_index.py
+++ /dev/null
@@ -1,170 +0,0 @@
-#
-# 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.
-"""
-Migrate RTIF to use run_id and map_index.
-
-Revision ID: 4eaab2fe6582
-Revises: c97c2ab6aa23
-Create Date: 2022-03-03 17:48:29.955821
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy.sql import and_, select
-from sqlalchemy.sql.schema import ForeignKeyConstraint
-
-from airflow.migrations.db_types import TIMESTAMP, StringID
-from airflow.migrations.utils import get_mssql_table_constraints
-
-ID_LEN = 250
-
-# revision identifiers, used by Alembic.
-revision = "4eaab2fe6582"
-down_revision = "c97c2ab6aa23"
-branch_labels = None
-depends_on = None
-airflow_version = "2.3.0"
-
-
-# Just Enough Table to run the conditions for update.
-def tables(for_downgrade=False):
- import sqlalchemy_jsonfield
-
- global task_instance, rendered_task_instance_fields, dag_run
- metadata = sa.MetaData()
- task_instance = sa.Table(
- "task_instance",
- metadata,
- sa.Column("task_id", StringID()),
- sa.Column("dag_id", StringID()),
- sa.Column("run_id", StringID()),
- sa.Column("execution_date", TIMESTAMP),
- )
- rendered_task_instance_fields = sa.Table(
- "rendered_task_instance_fields",
- metadata,
- sa.Column("dag_id", StringID()),
- sa.Column("task_id", StringID()),
- sa.Column("run_id", StringID()),
- sa.Column("execution_date", TIMESTAMP),
- sa.Column("rendered_fields", sqlalchemy_jsonfield.JSONField(), nullable=False),
- sa.Column("k8s_pod_yaml", sqlalchemy_jsonfield.JSONField(), nullable=True),
- )
-
- if for_downgrade:
- rendered_task_instance_fields.append_column(
- sa.Column("map_index", sa.Integer(), server_default="-1"),
- )
- rendered_task_instance_fields.append_constraint(
- ForeignKeyConstraint(
- ["dag_id", "run_id"],
- ["dag_run.dag_id", "dag_run.run_id"],
- name="rtif_dag_run_fkey",
- ondelete="CASCADE",
- ),
- )
- dag_run = sa.Table(
- "dag_run",
- metadata,
- sa.Column("dag_id", StringID()),
- sa.Column("run_id", StringID()),
- sa.Column("execution_date", TIMESTAMP),
- )
-
-
-def _multi_table_update(dialect_name, target, column):
- condition = dag_run.c.dag_id == target.c.dag_id
-
- if column == target.c.run_id:
- condition = and_(condition, dag_run.c.execution_date == target.c.execution_date)
- else:
- condition = and_(condition, dag_run.c.run_id == target.c.run_id)
-
- if dialect_name == "sqlite":
- # Most SQLite versions don't support multi table update (and SQLA doesn't know about it anyway), so we
- # need to do a Correlated subquery update
- sub_q = select(dag_run.c[column.name]).where(condition).scalar_subquery()
-
- return target.update().values({column: sub_q})
- else:
- return target.update().where(condition).values({column: dag_run.c[column.name]})
-
-
-def upgrade():
- tables()
- dialect_name = op.get_bind().dialect.name
-
- with op.batch_alter_table("rendered_task_instance_fields") as batch_op:
- batch_op.add_column(sa.Column("map_index", sa.Integer(), server_default="-1", nullable=False))
- rendered_task_instance_fields.append_column(
- sa.Column("map_index", sa.Integer(), server_default="-1", nullable=False)
- )
- batch_op.add_column(sa.Column("run_id", type_=StringID(), nullable=True))
-
- update_query = _multi_table_update(
- dialect_name, rendered_task_instance_fields, rendered_task_instance_fields.c.run_id
- )
- op.execute(update_query)
- with op.batch_alter_table(
- "rendered_task_instance_fields", copy_from=rendered_task_instance_fields
- ) as batch_op:
- if dialect_name == "mssql":
- constraints = get_mssql_table_constraints(op.get_bind(), "rendered_task_instance_fields")
- pk, _ = constraints["PRIMARY KEY"].popitem()
- batch_op.drop_constraint(pk, type_="primary")
- elif dialect_name != "sqlite":
- batch_op.drop_constraint("rendered_task_instance_fields_pkey", type_="primary")
- batch_op.alter_column("run_id", existing_type=StringID(), existing_nullable=True, nullable=False)
- batch_op.drop_column("execution_date")
- batch_op.create_primary_key(
- "rendered_task_instance_fields_pkey", ["dag_id", "task_id", "run_id", "map_index"]
- )
- batch_op.create_foreign_key(
- "rtif_ti_fkey",
- "task_instance",
- ["dag_id", "task_id", "run_id", "map_index"],
- ["dag_id", "task_id", "run_id", "map_index"],
- ondelete="CASCADE",
- )
-
-
-def downgrade():
- tables(for_downgrade=True)
- dialect_name = op.get_bind().dialect.name
- op.add_column("rendered_task_instance_fields", sa.Column("execution_date", TIMESTAMP, nullable=True))
-
- update_query = _multi_table_update(
- dialect_name, rendered_task_instance_fields, rendered_task_instance_fields.c.execution_date
- )
- op.execute(update_query)
-
- with op.batch_alter_table(
- "rendered_task_instance_fields", copy_from=rendered_task_instance_fields
- ) as batch_op:
- batch_op.alter_column("execution_date", existing_type=TIMESTAMP, nullable=False)
- if dialect_name != "sqlite":
- batch_op.drop_constraint("rtif_ti_fkey", type_="foreignkey")
- batch_op.drop_constraint("rendered_task_instance_fields_pkey", type_="primary")
- batch_op.create_primary_key(
- "rendered_task_instance_fields_pkey", ["dag_id", "task_id", "execution_date"]
- )
- batch_op.drop_column("map_index", mssql_drop_default=True)
- batch_op.drop_column("run_id")
diff --git a/airflow/migrations/versions/0105_2_3_0_add_map_index_to_taskfail.py b/airflow/migrations/versions/0105_2_3_0_add_map_index_to_taskfail.py
deleted file mode 100644
index 6c23201418..0000000000
--- a/airflow/migrations/versions/0105_2_3_0_add_map_index_to_taskfail.py
+++ /dev/null
@@ -1,158 +0,0 @@
-#
-# 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 map_index to TaskFail.
-
-Drop index idx_task_fail_dag_task_date
-Add run_id and map_index
-Drop execution_date
-Add FK `task_fail_ti_fkey`: TF -> TI ([dag_id, task_id, run_id, map_index])
-
-Revision ID: 48925b2719cb
-Revises: 4eaab2fe6582
-Create Date: 2022-03-14 10:31:11.220720
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-from sqlalchemy.sql import ColumnElement, Update, and_, select
-
-from airflow.migrations.db_types import TIMESTAMP, StringID
-
-# revision identifiers, used by Alembic.
-revision = "48925b2719cb"
-down_revision = "4eaab2fe6582"
-branch_labels = None
-depends_on = None
-airflow_version = "2.3.0"
-
-ID_LEN = 250
-
-
-def tables():
- global task_instance, task_fail, dag_run
- metadata = sa.MetaData()
- task_instance = sa.Table(
- "task_instance",
- metadata,
- sa.Column("task_id", StringID()),
- sa.Column("dag_id", StringID()),
- sa.Column("run_id", StringID()),
- sa.Column("map_index", sa.Integer(), server_default="-1"),
- sa.Column("execution_date", TIMESTAMP),
- )
- task_fail = sa.Table(
- "task_fail",
- metadata,
- sa.Column("dag_id", StringID()),
- sa.Column("task_id", StringID()),
- sa.Column("run_id", StringID()),
- sa.Column("map_index", StringID()),
- sa.Column("execution_date", TIMESTAMP),
- )
- dag_run = sa.Table(
- "dag_run",
- metadata,
- sa.Column("dag_id", StringID()),
- sa.Column("run_id", StringID()),
- sa.Column("execution_date", TIMESTAMP),
- )
-
-
-def _update_value_from_dag_run(
- dialect_name: str,
- target_table: sa.Table,
- target_column: ColumnElement,
- join_columns: list[str],
-) -> Update:
- """
- Grabs a value from the source table ``dag_run`` and updates target with this value.
-
- :param dialect_name: dialect in use
- :param target_table: the table to update
- :param target_column: the column to update
- """
- # for run_id: dag_id, execution_date
- # otherwise: dag_id, run_id
- condition_list = [getattr(dag_run.c, x) == getattr(target_table.c, x) for x in join_columns]
- condition = and_(*condition_list)
-
- if dialect_name == "sqlite":
- # Most SQLite versions don't support multi table update (and SQLA doesn't know about it anyway), so we
- # need to do a Correlated subquery update
- sub_q = select(dag_run.c[target_column.name]).where(condition).scalar_subquery()
-
- return target_table.update().values({target_column: sub_q})
- else:
- return target_table.update().where(condition).values({target_column: dag_run.c[target_column.name]})
-
-
-def upgrade():
- tables()
- dialect_name = op.get_bind().dialect.name
-
- op.drop_index("idx_task_fail_dag_task_date", table_name="task_fail")
-
- with op.batch_alter_table("task_fail") as batch_op:
- batch_op.add_column(sa.Column("map_index", sa.Integer(), server_default="-1", nullable=False))
- batch_op.add_column(sa.Column("run_id", type_=StringID(), nullable=True))
-
- update_query = _update_value_from_dag_run(
- dialect_name=dialect_name,
- target_table=task_fail,
- target_column=task_fail.c.run_id,
- join_columns=["dag_id", "execution_date"],
- )
- op.execute(update_query)
- with op.batch_alter_table("task_fail") as batch_op:
- batch_op.alter_column("run_id", existing_type=StringID(), existing_nullable=True, nullable=False)
- batch_op.drop_column("execution_date")
- batch_op.create_foreign_key(
- "task_fail_ti_fkey",
- "task_instance",
- ["dag_id", "task_id", "run_id", "map_index"],
- ["dag_id", "task_id", "run_id", "map_index"],
- ondelete="CASCADE",
- )
-
-
-def downgrade():
- tables()
- dialect_name = op.get_bind().dialect.name
- op.add_column("task_fail", sa.Column("execution_date", TIMESTAMP, nullable=True))
- update_query = _update_value_from_dag_run(
- dialect_name=dialect_name,
- target_table=task_fail,
- target_column=task_fail.c.execution_date,
- join_columns=["dag_id", "run_id"],
- )
- op.execute(update_query)
- with op.batch_alter_table("task_fail") as batch_op:
- batch_op.alter_column("execution_date", existing_type=TIMESTAMP, nullable=False)
- if dialect_name != "sqlite":
- batch_op.drop_constraint("task_fail_ti_fkey", type_="foreignkey")
- batch_op.drop_column("map_index", mssql_drop_default=True)
- batch_op.drop_column("run_id")
- op.create_index(
- index_name="idx_task_fail_dag_task_date",
- table_name="task_fail",
- columns=["dag_id", "task_id", "execution_date"],
- unique=False,
- )
diff --git a/airflow/migrations/versions/0106_2_3_0_update_migration_for_fab_tables_to_add_missing_constraints.py b/airflow/migrations/versions/0106_2_3_0_update_migration_for_fab_tables_to_add_missing_constraints.py
deleted file mode 100644
index eb2f9f12fb..0000000000
--- a/airflow/migrations/versions/0106_2_3_0_update_migration_for_fab_tables_to_add_missing_constraints.py
+++ /dev/null
@@ -1,109 +0,0 @@
-#
-# 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.
-"""
-Update migration for FAB tables to add missing constraints.
-
-Revision ID: 909884dea523
-Revises: 48925b2719cb
-Create Date: 2022-03-21 08:33:01.635688
-
-"""
-
-from __future__ import annotations
-
-import sqlalchemy as sa
-from alembic import op
-
-from airflow.migrations.utils import get_mssql_table_constraints
-
-# revision identifiers, used by Alembic.
-revision = "909884dea523"
-down_revision = "48925b2719cb"
-branch_labels = None
-depends_on = None
-airflow_version = "2.3.0"
-
-
-def upgrade():
- """Apply Update migration for FAB tables to add missing constraints."""
- conn = op.get_bind()
- if conn.dialect.name == "sqlite":
- op.execute("PRAGMA foreign_keys=OFF")
- with op.batch_alter_table("ab_view_menu", schema=None) as batch_op:
- batch_op.create_unique_constraint(batch_op.f("ab_view_menu_name_uq"), ["name"])
- op.execute("PRAGMA foreign_keys=ON")
- elif conn.dialect.name == "mysql":
- with op.batch_alter_table("ab_register_user", schema=None) as batch_op:
- batch_op.alter_column("username", existing_type=sa.String(256), nullable=False)
- batch_op.alter_column("email", existing_type=sa.String(256), nullable=False)
- with op.batch_alter_table("ab_user", schema=None) as batch_op:
- batch_op.alter_column("username", existing_type=sa.String(256), nullable=False)
- batch_op.alter_column("email", existing_type=sa.String(256), nullable=False)
- elif conn.dialect.name == "mssql":
- with op.batch_alter_table("ab_register_user") as batch_op:
- # Drop the unique constraint on username and email
- constraints = get_mssql_table_constraints(conn, "ab_register_user")
- for k, _ in constraints.get("UNIQUE").items():
- batch_op.drop_constraint(k, type_="unique")
- batch_op.alter_column("username", existing_type=sa.String(256), nullable=False)
- batch_op.create_unique_constraint(None, ["username"])
- batch_op.alter_column("email", existing_type=sa.String(256), nullable=False)
- with op.batch_alter_table("ab_user") as batch_op:
- # Drop the unique constraint on username and email
- constraints = get_mssql_table_constraints(conn, "ab_user")
- for k, _ in constraints.get("UNIQUE").items():
- batch_op.drop_constraint(k, type_="unique")
- batch_op.alter_column("username", existing_type=sa.String(256), nullable=False)
- batch_op.create_unique_constraint(None, ["username"])
- batch_op.alter_column("email", existing_type=sa.String(256), nullable=False)
- batch_op.create_unique_constraint(None, ["email"])
-
-
-def downgrade():
- """Unapply Update migration for FAB tables to add missing constraints."""
- conn = op.get_bind()
- if conn.dialect.name == "sqlite":
- op.execute("PRAGMA foreign_keys=OFF")
- with op.batch_alter_table("ab_view_menu", schema=None) as batch_op:
- batch_op.drop_constraint("ab_view_menu_name_uq", type_="unique")
- op.execute("PRAGMA foreign_keys=ON")
- elif conn.dialect.name == "mysql":
- with op.batch_alter_table("ab_user", schema=None) as batch_op:
- batch_op.alter_column("email", existing_type=sa.String(256), nullable=True)
- batch_op.alter_column("username", existing_type=sa.String(256), nullable=True, unique=True)
- with op.batch_alter_table("ab_register_user", schema=None) as batch_op:
- batch_op.alter_column("email", existing_type=sa.String(256), nullable=True)
- batch_op.alter_column("username", existing_type=sa.String(256), nullable=True, unique=True)
- elif conn.dialect.name == "mssql":
- with op.batch_alter_table("ab_register_user") as batch_op:
- # Drop the unique constraint on username and email
- constraints = get_mssql_table_constraints(conn, "ab_register_user")
- for k, _ in constraints.get("UNIQUE").items():
- batch_op.drop_constraint(k, type_="unique")
- batch_op.alter_column("username", existing_type=sa.String(256), nullable=False, unique=True)
- batch_op.create_unique_constraint(None, ["username"])
- batch_op.alter_column("email", existing_type=sa.String(256), nullable=False, unique=True)
- with op.batch_alter_table("ab_user") as batch_op:
- # Drop the unique constraint on username and email
- constraints = get_mssql_table_constraints(conn, "ab_user")
- for k, _ in constraints.get("UNIQUE").items():
- batch_op.drop_constraint(k, type_="unique")
- batch_op.alter_column("username", existing_type=sa.String(256), nullable=True)
- batch_op.create_unique_constraint(None, ["username"])
- batch_op.alter_column("email", existing_type=sa.String(256), nullable=True, unique=True)
- batch_op.create_unique_constraint(None, ["email"])
diff --git a/airflow/migrations/versions/0107_2_3_0_add_map_index_to_log.py b/airflow/migrations/versions/0107_2_3_0_add_map_index_to_log.py
deleted file mode 100644
index 407500305b..0000000000
--- a/airflow/migrations/versions/0107_2_3_0_add_map_index_to_log.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# 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 map_index to Log.
-
-Revision ID: 75d5ed6c2b43
-Revises: 909884dea523
-Create Date: 2022-03-15 16:35:54.816863
-"""
... 4711 lines suppressed ...