More work on SQL MigrationManager

Added methods:
 - migration_data
 - database_current_migration
 - migrations_to_run
This commit is contained in:
Christopher Allan Webber 2012-01-01 16:02:14 -06:00
parent 4c86905789
commit 3635ccdf34

View File

@ -68,6 +68,17 @@ class MigrationManager(object):
return self._sorted_migrations return self._sorted_migrations
@property
def migration_data(self):
"""
Get the migration row associated with this object, if any.
"""
query = self.database.query(
self.migration_model).filter_by(name=self.name)[0]
if query.count():
return query[0]
def latest_migration(self): def latest_migration(self):
""" """
Return a migration number for the latest migration, or 0 if Return a migration number for the latest migration, or 0 if
@ -83,32 +94,31 @@ class MigrationManager(object):
""" """
Return the current migration in the database. Return the current migration in the database.
""" """
# TODO return self.migration_data.version
def set_current_migration(self, migration_number): def set_current_migration(self, migration_number):
""" """
Set the migration in the database to migration_number Set the migration in the database to migration_number
""" """
# TODO self.migration_data = migration_number
pass self.database.commit()
def migrations_to_run(self): def migrations_to_run(self):
""" """
Get a list of migrations to run still, if any. Get a list of migrations to run still, if any.
Note that calling this will set your migration version to the Note that this will fail if there's no migration record for
latest version if it isn't installed to anything yet! this class!
""" """
## TODO assert self.database_current_migration is None
# self._ensure_current_migration_record()
# db_current_migration = self.database_current_migration()
# db_current_migration = self.database_current_migration()
# return [
# return [ (migration_number, migration_func)
# (migration_number, migration_func) for migration_number, migration_func in self.sorted_migrations
# for migration_number, migration_func in self.sorted_migrations if migration_number > db_current_migration]
# if migration_number > db_current_migration]
pass
def init_tables(self): def init_tables(self):
## TODO ## TODO