Skip to content

Commit

Permalink
Remove deprecated cli commands from the db group (apache#44706)
Browse files Browse the repository at this point in the history
I've added these to the "legacy commands" list, so Airflow will return a
helpful error message if someone does run them.
  • Loading branch information
jedcunningham authored Dec 6, 2024
1 parent 2412792 commit 052fd6f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 68 deletions.
33 changes: 0 additions & 33 deletions airflow/cli/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions airflow/cli/commands/legacy_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 0 additions & 21 deletions airflow/cli/commands/local_commands/db_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import logging
import os
import textwrap
import warnings
from tempfile import NamedTemporaryFile
from typing import TYPE_CHECKING

Expand All @@ -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."""
Expand All @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions newsfragments/44706.significant.rst
Original file line number Diff line number Diff line change
@@ -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
12 changes: 0 additions & 12 deletions tests/cli/commands/local_commands/test_db_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 052fd6f

Please sign in to comment.