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 <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-03-29 15:20:19 -07:00
parent 2df90ce280
commit 7c65604dad

View file

@ -11,10 +11,6 @@ import aurweb.schema
# access to the values within the .ini file in use. # access to the values within the .ini file in use.
config = context.config 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 # model MetaData for autogenerating migrations
target_metadata = aurweb.schema.metadata target_metadata = aurweb.schema.metadata
@ -68,7 +64,12 @@ def run_migrations_online():
context.run_migrations() context.run_migrations()
if context.is_offline_mode(): if __name__ == "__main__":
run_migrations_offline() # Interpret the config file for Python logging.
else: # This line sets up loggers basically.
run_migrations_online() logging.config.fileConfig(config.config_file_name)
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()