aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/migration_tools.py
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2016-03-12 09:45:28 -0800
committerChristopher Allan Webber <cwebber@dustycloud.org>2016-03-26 11:39:07 -0700
commitf25b476202b5ebe706a99fa586041c23b85acaa5 (patch)
tree6182163abc7fb07b3abec46047e257b96a453a2e /mediagoblin/db/migration_tools.py
parent8a26b072989a2393f81916fa0e5d15071b1de265 (diff)
downloadmediagoblin-f25b476202b5ebe706a99fa586041c23b85acaa5.tar.lz
mediagoblin-f25b476202b5ebe706a99fa586041c23b85acaa5.tar.xz
mediagoblin-f25b476202b5ebe706a99fa586041c23b85acaa5.zip
Only run sqlalchemy-migrate migrations if we have to; separate foundations
The goal is to get things to the point where Alembic can run on its own for new databases and initialize the whole database on its own. There are risks to not doing so, see #5413 for details. There's a lot more here that could removed or cleaned up once sqlalchemy-migrate is *completely* removed in the future. * mediagoblin/db/migration_tools.py (MigrationManager.foundations): Removed attribute. (MigrationManager.populate_table_foundations): Removed method. (MigrationManager.init_or_migrate): Removed call to deprecated method. (populate_table_foundations): New function, refactored from former MigrationManager method of same name. * mediagoblin/gmg_commands/dbupdate.py: Import populate_table_foundations. (DatabaseData.foundations): Remove attribute. (DatabaseData.make_migration_manager): Adjust instantiation of MigrationManager. (gather_database_data): Move out the work of building up foundations data. (run_foundations): New method, incorporating logic for gathering and running foundations which was previously spread across other functions and methods. (run_alembic_migrations): Remove deprecated comment. (run_dbupdate): Only run sqlalchemy migrations if we have to. Also run run_foundations if we are setting up this database for the first time. (sqam_migrations_to_run): New method.
Diffstat (limited to 'mediagoblin/db/migration_tools.py')
-rw-r--r--mediagoblin/db/migration_tools.py33
1 files changed, 18 insertions, 15 deletions
diff --git a/mediagoblin/db/migration_tools.py b/mediagoblin/db/migration_tools.py
index 2706c9b7..f4273fa0 100644
--- a/mediagoblin/db/migration_tools.py
+++ b/mediagoblin/db/migration_tools.py
@@ -44,7 +44,7 @@ class MigrationManager(object):
to the latest migrations, etc.
"""
- def __init__(self, name, models, foundations, migration_registry, session,
+ def __init__(self, name, models, migration_registry, session,
printer=simple_printer):
"""
Args:
@@ -55,7 +55,6 @@ class MigrationManager(object):
"""
self.name = name
self.models = models
- self.foundations = foundations
self.session = session
self.migration_registry = migration_registry
self._sorted_migrations = None
@@ -156,18 +155,6 @@ class MigrationManager(object):
self.session.bind,
tables=[model.__table__ for model in self.models])
- def populate_table_foundations(self):
- """
- Create the table foundations (default rows) as layed out in FOUNDATIONS
- in mediagoblin.db.models
- """
- for Model, rows in self.foundations.items():
- self.printer(u' + Laying foundations for %s table\n' %
- (Model.__name__))
- for parameters in rows:
- new_row = Model(**parameters)
- self.session.add(new_row)
-
def create_new_migration_record(self):
"""
Create a new migration record for this migration set
@@ -232,7 +219,6 @@ class MigrationManager(object):
# auto-set at latest migration number
self.create_new_migration_record()
self.printer(u"done.\n")
- self.populate_table_foundations()
self.set_current_migration()
return u'inited'
@@ -356,6 +342,23 @@ def model_iteration_hack(db, query):
return db.execute(query)
+def populate_table_foundations(session, foundations, name,
+ printer=simple_printer):
+ """
+ Create the table foundations (default rows) as layed out in FOUNDATIONS
+ in mediagoblin.db.models
+ """
+ printer(u'Laying foundations for %s:\n' % name)
+ for Model, rows in foundations.items():
+ printer(u' + Laying foundations for %s table\n' %
+ (Model.__name__))
+ for parameters in rows:
+ new_row = Model(**parameters)
+ session.add(new_row)
+
+ session.commit()
+
+
def build_alembic_config(global_config, cmd_options, session):
"""
Build up a config that the alembic tooling can use based on our