Attach the MediaGoblinApp to the engine, and provide a way for models to access

This allows SQLAlchemy models to gain access to app-level configuration
without the need for global variables.

This commit sponsored by Peter Hogg.  Thank you, Peter!
This commit is contained in:
Christopher Allan Webber
2014-12-03 13:13:58 -06:00
parent 5e5ea4a3e9
commit 7c563e91bf
4 changed files with 18 additions and 7 deletions

View File

@@ -60,14 +60,16 @@ def setup_global_and_app_config(config_path):
return global_config, app_config
def setup_database(run_migrations=False):
app_config = mg_globals.app_config
global_config = mg_globals.global_config
def setup_database(app):
app_config = app.app_config
global_config = app.global_config
run_migrations = app_config['run_migrations']
# Load all models for media types (plugins, ...)
load_models(app_config)
# Set up the database
db = setup_connection_and_db_from_config(app_config, run_migrations)
db = setup_connection_and_db_from_config(
app_config, run_migrations, app=app)
if run_migrations:
#Run the migrations to initialize/update the database.
from mediagoblin.gmg_commands.dbupdate import run_all_migrations