Skip to content

Add airflow db-manager CLI for managing external databases #50657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ephraimbuddy
Copy link
Contributor

@ephraimbuddy ephraimbuddy commented May 15, 2025

This adds a new top-level CLI command, airflow db-manager, which provides an interface for managing metadata databases handled by external DB managers.

Previously, external DB managers were required to define and expose their own CLI commands. With this change, Airflow now provides support for common DB actions (reset, migrate, downgrade) across external database backends by delegating to their registered managers.

Changes:

  • Introduces db-manager CLI group with reset, migrate, and downgrade commands.

  • Each command accepts a --name flag to select the DB manager.

  • Adds test coverage for the CLI commands.

This enables external providers to plug in seamlessly without duplicating db command logic.

Closes: #50496

This adds a new top-level CLI command, `airflow db-manager`, which provides an
interface for managing metadata databases handled by external DB managers.

Previously, external DB managers were required to define and expose their own CLI commands.
With this change, Airflow now provides support for common DB actions
(reset, migrate, downgrade) across external database backends by delegating to their registered managers.

Changes:

 - Introduces db-manager CLI group with reset, migrate, and downgrade commands.

 - Each command accepts a --name flag to select the DB manager.

 - Adds test coverage for the CLI commands.

This enables external providers to plug in seamlessly without duplicating db command logic.
@ephraimbuddy ephraimbuddy force-pushed the add-dbmanagers-command branch from 3c45865 to cd1de06 Compare May 15, 2025 19:35
@ephraimbuddy ephraimbuddy marked this pull request as ready for review May 15, 2025 19:36
@ephraimbuddy ephraimbuddy requested a review from vincbeck as a code owner May 15, 2025 19:36
@ephraimbuddy ephraimbuddy self-assigned this May 19, 2025
DB_MANAGERS_COMMANDS = (
ActionCommand(
name="reset",
help="Burn down and rebuild the metadata database",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help docs for these should be rewritten a bit since these are just the things the db manager controls, not the whole db.

@@ -599,6 +599,13 @@ def string_lower_type(val):
default=False,
)

ARG_DB_MANAGER_NAME = Arg(
("--name",),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
("--name",),
("name",),

Having it be positional might be a bit nicer?

db_managers = conf.get("database", "external_db_managers")
db_manager = None
for manager in db_managers.split(","):
if name in manager:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is right - we want a complete match right, not just a partial match? If we have a a and a abc we could match a to abc. Since we don't have the concept of a "name", maybe we should take the whole classpath?

Comment on lines +27 to +37
def _get_db_manager(name):
"""Import the db manager class."""
db_managers = conf.get("database", "external_db_managers")
db_manager = None
for manager in db_managers.split(","):
if name in manager:
db_manager = manager
break
if db_manager is None:
raise SystemExit(f"DB manager {name} not found in configuration.")
return import_string(db_manager.strip())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _get_db_manager(name):
"""Import the db manager class."""
db_managers = conf.get("database", "external_db_managers")
db_manager = None
for manager in db_managers.split(","):
if name in manager:
db_manager = manager
break
if db_manager is None:
raise SystemExit(f"DB manager {name} not found in configuration.")
return import_string(db_manager.strip())
def _get_db_manager(manager_classpath: str):
"""Import the db manager class."""
db_managers = conf.getlistlist("database", "external_db_managers")
if manager_classpath not in manager:
raise SystemExit(f"DB manager {manager_classpath} not found in configuration.")
return import_string(manager_classpath.strip())

Something like this is probably better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be nice to have a command like:
airflow db-manager "airflow.providers.fab.auth_manager.models.db.FABDBManager" reset -y
or what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a general command for migrating external db managers
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy