From 7c563e91bf66b0c01dfceb65c614b0da84ed91c3 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 3 Dec 2014 13:13:58 -0600 Subject: 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! --- mediagoblin/db/open.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mediagoblin/db/open.py') diff --git a/mediagoblin/db/open.py b/mediagoblin/db/open.py index e85536de..bd629909 100644 --- a/mediagoblin/db/open.py +++ b/mediagoblin/db/open.py @@ -158,9 +158,14 @@ def _sqlite_disable_fk_pragma_on_connect(dbapi_con, con_record): dbapi_con.execute('pragma foreign_keys=off') -def setup_connection_and_db_from_config(app_config, migrations=False): +def setup_connection_and_db_from_config(app_config, migrations=False, app=None): engine = create_engine(app_config['sql_engine']) + # @@: Maybe make a weak-ref so an engine can get garbage + # collected? Not that we expect to make a lot of MediaGoblinApp + # instances in a single process... + engine.app = app + # Enable foreign key checking for sqlite if app_config['sql_engine'].startswith('sqlite://'): if migrations: -- cgit v1.2.3