diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-07-10 15:41:18 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-07-10 15:41:18 -0500 |
commit | d0ee0003a2473b8ef23e32a0b1d754f5ce36d530 (patch) | |
tree | 418f0ca8a89642685fd5434491dd45da191a7edd /mediagoblin/db/util.py | |
parent | 42fe0780297f87c046f9f44887874147b94c1f08 (diff) | |
download | mediagoblin-d0ee0003a2473b8ef23e32a0b1d754f5ce36d530.tar.lz mediagoblin-d0ee0003a2473b8ef23e32a0b1d754f5ce36d530.tar.xz mediagoblin-d0ee0003a2473b8ef23e32a0b1d754f5ce36d530.zip |
Simpler run_migrations method.
Allows for calbacks, should be useful for printing output and catching
things in tests.
Gets rid of the generator stuff which now that I think of it is a
messy idea.
Diffstat (limited to 'mediagoblin/db/util.py')
-rw-r--r-- | mediagoblin/db/util.py | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 7bae57ff..9e4efcab 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -232,25 +232,22 @@ class MigrationManager(object): for migration_number, migration_func in self.sorted_migrations if migration_number > db_current_migration] - def iteratively_migrate(self): + def migrate_new(self, pre_callback=None, post_callback=None): """ - Iteratively run all migrations. + Run all migrations. - Useful if you need to print some message about each migration - after you run it. - - Each time you loop over this, it'll return the migration - number and migration function. + Includes two optional args: + - pre_callback: if called, this is a callback on something to + run pre-migration. Takes (migration_number, migration_func) + as arguments + - pre_callback: if called, this is a callback on something to + run post-migration. Takes (migration_number, migration_func) + as arguments """ for migration_number, migration_func in self.migrations_to_run(): + if pre_callback: + pre_callback(migration_number, migration_func) migration_func(self.database) self.set_current_migration(migration_number) - yield migration_number, migration_func - - def run_new_migrations(self): - """ - Install all migrations that need to be installed, quietly. - """ - for migration_number, migration_func in self.iteratively_migrate(): - # No need to say anything... we're just migrating quietly. - pass + if post_callback: + post_callback(migration_number, migration_func) |