aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/open.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/db/open.py')
-rw-r--r--mediagoblin/db/open.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/mediagoblin/db/open.py b/mediagoblin/db/open.py
index 5fd5ed03..4ff0945f 100644
--- a/mediagoblin/db/open.py
+++ b/mediagoblin/db/open.py
@@ -52,10 +52,6 @@ class DatabaseMaster(object):
def load_models(app_config):
import mediagoblin.db.models
- for media_type in app_config['media_types']:
- _log.debug("Loading %s.models", media_type)
- __import__(media_type + ".models")
-
for plugin in mg_globals.global_config.get('plugins', {}).keys():
_log.debug("Loading %s.models", plugin)
try:
@@ -71,12 +67,24 @@ def _sqlite_fk_pragma_on_connect(dbapi_con, con_record):
dbapi_con.execute('pragma foreign_keys=on')
-def setup_connection_and_db_from_config(app_config):
+def _sqlite_disable_fk_pragma_on_connect(dbapi_con, con_record):
+ """
+ Disable foreign key checking on each new sqlite connection
+ (Good for migrations!)
+ """
+ dbapi_con.execute('pragma foreign_keys=off')
+
+
+def setup_connection_and_db_from_config(app_config, migrations=False):
engine = create_engine(app_config['sql_engine'])
# Enable foreign key checking for sqlite
if app_config['sql_engine'].startswith('sqlite://'):
- event.listen(engine, 'connect', _sqlite_fk_pragma_on_connect)
+ if migrations:
+ event.listen(engine, 'connect',
+ _sqlite_disable_fk_pragma_on_connect)
+ else:
+ event.listen(engine, 'connect', _sqlite_fk_pragma_on_connect)
# logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)