-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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
base: main
Are you sure you want to change the base?
Conversation
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.
3c45865
to
cd1de06
Compare
DB_MANAGERS_COMMANDS = ( | ||
ActionCommand( | ||
name="reset", | ||
help="Burn down and rebuild the metadata database", |
There was a problem hiding this comment.
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",), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
("--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: |
There was a problem hiding this comment.
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?
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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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?
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