This is an automated email from the ASF dual-hosted git repository.

jedcunningham 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 052fd6f4bac Remove deprecated cli commands from the `db` group (#44706)
052fd6f4bac is described below

commit 052fd6f4bac0a247c238703b46155257bc4dab64
Author: Jed Cunningham <[email protected]>
AuthorDate: Fri Dec 6 11:40:11 2024 -0700

    Remove deprecated cli commands from the `db` group (#44706)
    
    I've added these to the "legacy commands" list, so Airflow will return a
    helpful error message if someone does run them.
---
 airflow/cli/cli_config.py                          | 33 ----------------------
 airflow/cli/commands/legacy_commands.py            |  6 ++--
 airflow/cli/commands/local_commands/db_command.py  | 21 --------------
 newsfragments/44706.significant.rst                | 15 ++++++++++
 .../cli/commands/local_commands/test_db_command.py | 12 --------
 5 files changed, 19 insertions(+), 68 deletions(-)

diff --git a/airflow/cli/cli_config.py b/airflow/cli/cli_config.py
index cd6aa6c9a29..0e5dbad1f53 100644
--- a/airflow/cli/cli_config.py
+++ b/airflow/cli/cli_config.py
@@ -1438,17 +1438,6 @@ VARIABLES_COMMANDS = (
     ),
 )
 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 @@ DB_COMMANDS = (
         
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 1132c6158e3..c9fddec2d76 100644
--- a/airflow/cli/commands/legacy_commands.py
+++ b/airflow/cli/commands/legacy_commands.py
@@ -36,9 +36,11 @@ COMMAND_MAP = {
     "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 ff268d1de16..d6a5f8c2607 100644
--- a/airflow/cli/commands/local_commands/db_command.py
+++ b/airflow/cli/commands/local_commands/db_command.py
@@ -21,7 +21,6 @@ from __future__ import annotations
 import logging
 import os
 import textwrap
-import warnings
 from tempfile import NamedTemporaryFile
 from typing import TYPE_CHECKING
 
@@ -42,20 +41,6 @@ if TYPE_CHECKING:
 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 00000000000..bd3efa69725
--- /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 b428c396387..7052899fc50 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 @@ class TestCliDb:
         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(

Reply via email to