diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-07-10 22:02:51 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-07-10 22:02:51 -0500 |
commit | dab0d24d98ef6bdbb43548f7108437b8b91e4af0 (patch) | |
tree | 6361eab38ea89821dc70f13fdfb3d45d5260a90d /mediagoblin/db/util.py | |
parent | 9548c6463b157284dabdc98391afb4c784d1c2a2 (diff) | |
download | mediagoblin-dab0d24d98ef6bdbb43548f7108437b8b91e4af0.tar.lz mediagoblin-dab0d24d98ef6bdbb43548f7108437b8b91e4af0.tar.xz mediagoblin-dab0d24d98ef6bdbb43548f7108437b8b91e4af0.zip |
Made it so that it's migrate_new() which installs the migration
version if missing, migrations_to_run just throws an error if not set
Diffstat (limited to 'mediagoblin/db/util.py')
-rw-r--r-- | mediagoblin/db/util.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 1a4dd95b..5a1b317d 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -115,6 +115,9 @@ def remove_deprecated_indexes(database, deprecated_indexes=DEPRECATED_INDEXES): # Don't set this yourself! RegisterMigration will automatically fill # this with stuff via decorating methods in migrations.py +class MissingCurrentMigration(Exception): pass + + MIGRATIONS = {} @@ -164,6 +167,16 @@ class MigrationManager(object): self.migration_registry = migration_registry self._sorted_migrations = None + def _ensure_current_migration_record(self): + """ + If there isn't a database[u'app_metadata'] mediagoblin entry + with the 'current_migration', throw an error. + """ + if self.database_current_migration() is None: + MissingCurrentMigration( + "Tried to call function which requires " + "'current_migration' set in database") + @property def sorted_migrations(self): """ @@ -235,9 +248,7 @@ class MigrationManager(object): Note that calling this will set your migration version to the latest version if it isn't installed to anything yet! """ - # If we aren't set to any version number, presume we're at the - # latest (which means we'll do nothing here...) - self.install_migration_version_if_missing() + self._ensure_current_migration_record() db_current_migration = self.database_current_migration() @@ -258,6 +269,10 @@ class MigrationManager(object): run post-migration. Takes (migration_number, migration_func) as arguments """ + # If we aren't set to any version number, presume we're at the + # latest (which means we'll do nothing here...) + self.install_migration_version_if_missing() + for migration_number, migration_func in self.migrations_to_run(): if pre_callback: pre_callback(migration_number, migration_func) |