From 85b10c38f39732421a230d938adddc7805d0e001 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Mon, 16 Nov 2026 09:27:29 +0100 Subject: style(core): reorder module declarations Group globals and data classes near module imports, keep primary classes and functions together, and move implementation helpers after their public callers. Reorder Alembic setup so configuration happens after the required helpers are defined, without changing runtime behavior. --- webmentions_ssg/migrations/env.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'webmentions_ssg/migrations') diff --git a/webmentions_ssg/migrations/env.py b/webmentions_ssg/migrations/env.py index 86d9d99..bd66546 100644 --- a/webmentions_ssg/migrations/env.py +++ b/webmentions_ssg/migrations/env.py @@ -17,6 +17,10 @@ config = context.config logger = logging.getLogger("alembic.env") +# Database metadata shared by both migration modes. +target_db = current_app.extensions["migrate"].db + + def get_engine(): return current_app.extensions["migrate"].db.engine @@ -28,19 +32,6 @@ def get_engine_url(): return str(get_engine().url).replace("%", "%%") -# add your model's MetaData object here -# for 'autogenerate' support -# from myapp import mymodel -# target_metadata = mymodel.Base.metadata -config.set_main_option("sqlalchemy.url", get_engine_url()) -target_db = current_app.extensions["migrate"].db - -# other values from the config, defined by the needs of env.py, -# can be acquired: -# my_important_option = config.get_main_option("my_important_option") -# ... etc. - - def get_metadata(): if hasattr(target_db, "metadatas"): return target_db.metadatas[None] @@ -97,6 +88,10 @@ def run_migrations_online(): context.run_migrations() +# Configure Alembic after the engine URL helper is defined. +config.set_main_option("sqlalchemy.url", get_engine_url()) + + if context.is_offline_mode(): run_migrations_offline() else: -- cgit v1.3.1