aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/open.py
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2014-12-03 13:13:58 -0600
committerChristopher Allan Webber <cwebber@dustycloud.org>2014-12-03 15:40:58 -0600
commit7c563e91bf66b0c01dfceb65c614b0da84ed91c3 (patch)
tree9002b481acd2df89297d8e48000a84ea885879d4 /mediagoblin/db/open.py
parent5e5ea4a3e97c14c377b7f2a82dc7d2558c14dcee (diff)
downloadmediagoblin-7c563e91bf66b0c01dfceb65c614b0da84ed91c3.tar.lz
mediagoblin-7c563e91bf66b0c01dfceb65c614b0da84ed91c3.tar.xz
mediagoblin-7c563e91bf66b0c01dfceb65c614b0da84ed91c3.zip
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!
Diffstat (limited to 'mediagoblin/db/open.py')
-rw-r--r--mediagoblin/db/open.py7
1 files changed, 6 insertions, 1 deletions
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: