diff --git a/airflow/cli/cli_config.py b/airflow/cli/cli_config.py index cd6aa6c9a29c2..0e5dbad1f5372 100644 --- a/airflow/cli/cli_config.py +++ b/airflow/cli/cli_config.py @@ -1438,17 +1438,6 @@ class GroupCommand(NamedTuple): ), ) DB_COMMANDS = ( - ActionCommand( - name="init", - help=( - "Deprecated -- use `migrate` instead. " - "To create default connections use `airflow connections create-default-connections`. " - "Initialize the metadata database" - ), - func=lazy_load_command("airflow.cli.commands.local_commands.db_command.initdb"), - args=(ARG_VERBOSE,), - hide=True, - ), ActionCommand( name="check-migrations", help="Check if migration have finished", @@ -1462,28 +1451,6 @@ class GroupCommand(NamedTuple): func=lazy_load_command("airflow.cli.commands.local_commands.db_command.resetdb"), args=(ARG_YES, ARG_DB_SKIP_INIT, ARG_VERBOSE), ), - ActionCommand( - name="upgrade", - help="Deprecated -- use `migrate` instead. Upgrade the metadata database to latest version", - description=( - "Upgrade the schema of the metadata database. " - "To print but not execute commands, use option ``--show-sql-only``. " - "If using options ``--from-revision`` or ``--from-version``, you must also use " - "``--show-sql-only``, because if actually *running* migrations, we should only " - "migrate from the *current* Alembic revision." - ), - func=lazy_load_command("airflow.cli.commands.local_commands.db_command.upgradedb"), - args=( - ARG_DB_REVISION__UPGRADE, - ARG_DB_VERSION__UPGRADE, - ARG_DB_SQL_ONLY, - ARG_DB_FROM_REVISION, - ARG_DB_FROM_VERSION, - ARG_DB_RESERIALIZE_DAGS, - ARG_VERBOSE, - ), - hide=True, - ), ActionCommand( name="migrate", help="Migrates the metadata database to the latest version", diff --git a/airflow/cli/commands/legacy_commands.py b/airflow/cli/commands/legacy_commands.py index 1132c6158e385..c9fddec2d76fe 100644 --- a/airflow/cli/commands/legacy_commands.py +++ b/airflow/cli/commands/legacy_commands.py @@ -36,9 +36,11 @@ "task_state": "tasks state", "run": "tasks run", "render": "tasks render", - "initdb": "db init", + "initdb": "db migrate", + "db init": "db migrate", "resetdb": "db reset", - "upgradedb": "db upgrade", + "upgradedb": "db migrate", + "db upgrade": "db migrate", "checkdb": "db check", "shell": "db shell", "pool": "pools", diff --git a/airflow/cli/commands/local_commands/db_command.py b/airflow/cli/commands/local_commands/db_command.py index ff268d1de1662..d6a5f8c260725 100644 --- a/airflow/cli/commands/local_commands/db_command.py +++ b/airflow/cli/commands/local_commands/db_command.py @@ -21,7 +21,6 @@ import logging import os import textwrap -import warnings from tempfile import NamedTemporaryFile from typing import TYPE_CHECKING @@ -42,20 +41,6 @@ log = logging.getLogger(__name__) -@providers_configuration_loaded -def initdb(args): - """Initialize the metadata database.""" - warnings.warn( - "`db init` is deprecated. Use `db migrate` instead to migrate the db and/or " - "airflow connections create-default-connections to create the default connections", - DeprecationWarning, - stacklevel=2, - ) - print(f"DB: {settings.engine.url!r}") - db.initdb() - print("Initialization done") - - @providers_configuration_loaded def resetdb(args): """Reset the metadata database.""" @@ -65,12 +50,6 @@ def resetdb(args): db.resetdb(skip_init=args.skip_init) -def upgradedb(args): - """Upgrades the metadata database.""" - warnings.warn("`db upgrade` is deprecated. Use `db migrate` instead.", DeprecationWarning, stacklevel=2) - migratedb(args) - - def _get_version_revision( version: str, recursion_limit: int = 10, revision_heads_map: dict[str, str] | None = None ) -> str | None: diff --git a/newsfragments/44706.significant.rst b/newsfragments/44706.significant.rst new file mode 100644 index 0000000000000..bd3efa6972588 --- /dev/null +++ b/newsfragments/44706.significant.rst @@ -0,0 +1,15 @@ +Deprecated cli commands under ``db`` group removed + +The ``db init`` and ``db upgrade`` commands have been removed. Use ``db migrate`` instead to initialize or migrate the metadata database. + +If you would like to create default connections use ``airflow connections create-default-connections``. + +* Types of change + + * [ ] DAG changes + * [ ] Config changes + * [ ] API changes + * [x] CLI changes + * [ ] Behaviour changes + * [ ] Plugin changes + * [ ] Dependency change diff --git a/tests/cli/commands/local_commands/test_db_command.py b/tests/cli/commands/local_commands/test_db_command.py index b428c396387d1..7052899fc5008 100644 --- a/tests/cli/commands/local_commands/test_db_command.py +++ b/tests/cli/commands/local_commands/test_db_command.py @@ -36,12 +36,6 @@ class TestCliDb: def setup_class(cls): cls.parser = cli_parser.get_parser() - @mock.patch("airflow.cli.commands.local_commands.db_command.db.initdb") - def test_cli_initdb(self, mock_initdb): - with pytest.warns(expected_warning=DeprecationWarning, match="`db init` is deprecated"): - db_command.initdb(self.parser.parse_args(["db", "init"])) - mock_initdb.assert_called_once_with() - @mock.patch("airflow.cli.commands.local_commands.db_command.db.resetdb") def test_cli_resetdb(self, mock_resetdb): db_command.resetdb(self.parser.parse_args(["db", "reset", "--yes"])) @@ -188,12 +182,6 @@ def test_cli_sync_failure(self, mock_upgradedb, args, pattern): with pytest.raises(SystemExit, match=pattern): db_command.migratedb(self.parser.parse_args(["db", "migrate", *args])) - @mock.patch("airflow.cli.commands.local_commands.db_command.migratedb") - def test_cli_upgrade(self, mock_migratedb): - with pytest.warns(expected_warning=DeprecationWarning, match="`db upgrade` is deprecated"): - db_command.upgradedb(self.parser.parse_args(["db", "upgrade"])) - mock_migratedb.assert_called_once() - @mock.patch("airflow.cli.commands.local_commands.db_command.execute_interactive") @mock.patch("airflow.cli.commands.local_commands.db_command.NamedTemporaryFile") @mock.patch(