From 7c65604dad8d9c68bee59129b03af05d26db1582 Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Mon, 29 Mar 2021 15:20:19 -0700 Subject: [PATCH] move off env.py's active code to __name__ == "__main__" * Moved migrations/env.py's logging initialization and migration execution into a `__name__ == "__main__"` stanza so it doesn't immediately happen when imported by another module. Signed-off-by: Kevin Morris --- migrations/env.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/migrations/env.py b/migrations/env.py index c2ff58c1..23759123 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -11,10 +11,6 @@ import aurweb.schema # access to the values within the .ini file in use. config = context.config -# Interpret the config file for Python logging. -# This line sets up loggers basically. -logging.config.fileConfig(config.config_file_name) - # model MetaData for autogenerating migrations target_metadata = aurweb.schema.metadata @@ -68,7 +64,12 @@ def run_migrations_online(): context.run_migrations() -if context.is_offline_mode(): - run_migrations_offline() -else: - run_migrations_online() +if __name__ == "__main__": + # Interpret the config file for Python logging. + # This line sets up loggers basically. + logging.config.fileConfig(config.config_file_name) + + if context.is_offline_mode(): + run_migrations_offline() + else: + run_migrations_online()