A few basic fixes to sql/util.py
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 29 Jan 2012 22:58:58 +0000 (16:58 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 29 Jan 2012 22:58:58 +0000 (16:58 -0600)
 - MigrationRecord to MigrationData, again
 - If the table doesn't exist, return None for database_current_migration
 - database.engine -> database.bind

mediagoblin/db/sql/util.py

index d9ce7d2b19236c5a6054d488f17daf41232da273..604ea19c1cbcb6aee3dc84e67b1fbb998ad8d8ff 100644 (file)
@@ -93,6 +93,10 @@ class MigrationManager(object):
         """
         Return the current migration in the database.
         """
+        # If the table doesn't even exist, return None.
+        if not self.migration_table.exists(self.database.bind):
+            return None
+
         return self.migration_data.version
 
     def set_current_migration(self, migration_number):
@@ -129,7 +133,7 @@ class MigrationManager(object):
             assert not model.__table__.exists(self.database)
 
         self.migration_model.metadata.create_all(
-            self.database.engine,
+            self.database.bind,
             tables=[model.__table__ for model in self.models])
 
     def create_new_migration_record(self):
@@ -253,8 +257,8 @@ def assure_migrations_table_setup(db):
     """
     Make sure the migrations table is set up in the database.
     """
-    from mediagoblin.db.sql.models import MigrationRecord
+    from mediagoblin.db.sql.models import MigrationData
 
-    if not MigrationRecord.__table__.exists(db.engine):
-        MigrationRecord.metadata.create_all(
-            db, tables=[MigrationRecord.__table__])
+    if not MigrationData.__table__.exists(db.bind):
+        MigrationData.metadata.create_all(
+            db, tables=[MigrationData.__table__])