Enable alembic as the main tool for migrations
authorBoris Bobrov <breton@cynicmansion.ru>
Sat, 7 Nov 2015 13:57:22 +0000 (16:57 +0300)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 11 Jan 2016 15:14:33 +0000 (07:14 -0800)
Enable alembic for all migrations and limit the max number of
sqlalchemy-migration migration. All new migrations must now be in
Alembic!

mediagoblin/db/migration_tools.py
mediagoblin/gmg_commands/dbupdate.py

index 2a570a053c45578123b7ce13a5ef9f4e6bd4f584..756c109306aa5ee2da638306fd38549a59cbe164 100644 (file)
@@ -166,14 +166,14 @@ class MigrationManager(object):
     def migrations_to_run(self):
         """
         Get a list of migrations to run still, if any.
-        
+
         Note that this will fail if there's no migration record for
         this class!
         """
         assert self.database_current_migration is not None
 
         db_current_migration = self.database_current_migration
-        
+
         return [
             (migration_number, migration_func)
             for migration_number, migration_func in self.sorted_migrations
@@ -202,7 +202,7 @@ class MigrationManager(object):
             in mediagoblin.db.models
         """
         for Model, rows in self.foundations.items():
-            self.printer(u'   + Laying foundations for %s table\n' % 
+            self.printer(u'   + Laying foundations for %s table\n' %
                 (Model.__name__))
             for parameters in rows:
                 new_row = Model(**parameters)
@@ -238,7 +238,7 @@ class MigrationManager(object):
                         migration_number, migration_func.func_name))
 
             return u'migrated'
-        
+
     def name_for_printing(self):
         if self.name == u'__main__':
             return u"main mediagoblin tables"
@@ -317,6 +317,8 @@ class RegisterMigration(object):
         assert migration_number > 0, "Migration number must be > 0!"
         assert migration_number not in migration_registry, \
             "Duplicate migration numbers detected!  That's not allowed!"
+        assert migration_number <= 44, ('Alembic should be used for '
+                                        'new migrations')
 
         self.migration_number = migration_number
         self.migration_registry = migration_registry
@@ -349,7 +351,7 @@ def replace_table_hack(db, old_table, replacement_table):
     -tion, for example, dropping a boolean column in sqlite is impossible w/o
     this method
 
-        :param old_table            A ref to the old table, gotten through 
+        :param old_table            A ref to the old table, gotten through
                                     inspect_table
 
         :param replacement_table    A ref to the new table, gotten through
@@ -389,7 +391,7 @@ def model_iteration_hack(db, query):
     # If it's SQLite just return all the objects
     if db.bind.url.drivername == "sqlite":
         return [obj for obj in db.execute(query)]
-    
+
     # Postgres return the query as it knows how to deal with it.
     return db.execute(query)
 
index 342ee7eba659c48ab61f8a05e5df4dcd93cd43bc..da07c0a87e63619ccaa0cc340cc887fbad10e74b 100644 (file)
@@ -130,8 +130,7 @@ def run_dbupdate(app_config, global_config):
 
     # TODO: Make this happen regardless of python 2 or 3 once ensured
     # to be "safe"!
-    if six.PY3:
-        run_alembic_migrations(db, app_config, global_config)
+    run_alembic_migrations(db, app_config, global_config)
 
 
 def run_all_migrations(db, app_config, global_config):