added openid docs
[mediagoblin.git] / mediagoblin / gmg_commands / dbupdate.py
index f33d83d5002a19dd8151c8e4e4d307982dcf51dd..22ad426c1046dd0fbe8bfb9518490870c4335326 100644 (file)
@@ -78,6 +78,7 @@ def gather_database_data(media_types, plugins):
         except AttributeError as exc:
             _log.warning('Could not find MODELS in {0}.models, have you \
 forgotten to add it? ({1})'.format(plugin, exc))
+            models = []
 
         try:
             migrations = import_component('{0}.migrations:MIGRATIONS'.format(
@@ -91,6 +92,7 @@ forgotten to add it? ({1})'.format(plugin, exc))
         except AttributeError as exc:
             _log.debug('Cloud not find MIGRATIONS in {0}.migrations, have you \
 forgotten to add it? ({1})'.format(plugin, exc))
+            migrations = {}
 
         if models:
             managed_dbdata.append(
@@ -108,14 +110,26 @@ def run_dbupdate(app_config, global_config):
     in the future, plugins)
     """
 
+    # Set up the database
+    db = setup_connection_and_db_from_config(app_config, migrations=True)
+    #Run the migrations
+    run_all_migrations(db, app_config, global_config)
+
+
+def run_all_migrations(db, app_config, global_config):
+    """
+    Initializes or migrates a database that already has a 
+    connection setup and also initializes or migrates all
+    extensions based on the config files.
+
+    It can be used to initialize an in-memory database for
+    testing.
+    """
     # Gather information from all media managers / projects
     dbdatas = gather_database_data(
             app_config['media_types'],
             global_config.get('plugins', {}).keys())
 
-    # Set up the database
-    db = setup_connection_and_db_from_config(app_config, sqlite_refcheck=False)
-
     Session = sessionmaker(bind=db.engine)
 
     # Setup media managers for all dbdata, run init/migrate and print info