From ff3519ae113dd0f8b19051e9f08ddffefb7adf56 Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Fri, 25 Jun 2021 22:12:01 -0700 Subject: [PATCH] [alembic] Log db name being used in a migration Signed-off-by: Kevin Morris --- migrations/env.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/migrations/env.py b/migrations/env.py index dfe14804..7130d141 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -1,3 +1,4 @@ +import logging import logging.config import sqlalchemy @@ -19,12 +20,14 @@ target_metadata = aurweb.schema.metadata # my_important_option = config.get_main_option("my_important_option") # ... etc. - # If configure_logger is either True or not specified, # configure the logger via fileConfig. if config.attributes.get("configure_logger", True): logging.config.fileConfig(config.config_file_name) +# This grabs the root logger in env.py. +logger = logging.getLogger(__name__) + def run_migrations_offline(): """Run migrations in 'offline' mode. @@ -38,6 +41,8 @@ def run_migrations_offline(): script output. """ + db_name = aurweb.config.get("database", "name") + logging.info(f"Performing offline migration on database '{db_name}'.") context.configure( url=aurweb.db.get_sqlalchemy_url(), target_metadata=target_metadata, @@ -56,6 +61,8 @@ def run_migrations_online(): and associate a connection with the context. """ + db_name = aurweb.config.get("database", "name") + logging.info(f"Performing online migration on database '{db_name}'.") connectable = sqlalchemy.create_engine( aurweb.db.get_sqlalchemy_url(), poolclass=sqlalchemy.pool.NullPool,