def _walk_versions(self, sql_connection): # Determine latest version script from the repo, then # upgrade from 1 through to the latest, with no data # in the databases. This just checks that the schema itself # upgrades successfully. # Assert we are not under version control... self.assertRaises(fault.DatabaseMigrationError, migration_api.db_version, sql_connection) # Place the database under version control print migration_api.version_control(sql_connection) cur_version = migration_api.db_version(sql_connection) self.assertEqual(0, cur_version) for version in xrange(1, TestMigrations.REPOSITORY.latest + 1): migration_api.upgrade(sql_connection, version) cur_version = migration_api.db_version(sql_connection) self.assertEqual(cur_version, version) # Now walk it back down to 0 from the latest, testing # the downgrade paths. for version in reversed(xrange(0, TestMigrations.REPOSITORY.latest)): migration_api.downgrade(sql_connection, version) cur_version = migration_api.db_version(sql_connection) self.assertEqual(cur_version, version)
def _walk_versions(self, options): # Determine latest version script from the repo, then # upgrade from 1 through to the latest, with no data # in the databases. This just checks that the schema itself # upgrades successfully. # Assert we are not under version control... self.assertRaises(fault.DatabaseMigrationError, migration_api.db_version, options) # Place the database under version control print options print migration_api.version_control(options) cur_version = migration_api.db_version(options) self.assertEqual(0, cur_version) for version in xrange(1, TestMigrations.REPOSITORY.latest + 1): migration_api.upgrade(options, version) cur_version = migration_api.db_version(options) self.assertEqual(cur_version, version) # Now walk it back down to 0 from the latest, testing # the downgrade paths. for version in reversed( xrange(0, TestMigrations.REPOSITORY.latest)): migration_api.downgrade(options, version) cur_version = migration_api.db_version(options) self.assertEqual(cur_version, version)
def do_db_downgrade(options, args): """Downgrade the database's migration level""" try: db_version = args[2] except IndexError: raise Exception("downgrade requires a version argument") migration.downgrade(options, version=db_version)
def downgrade_database(version): """Downgrade database to the specified version""" migration.downgrade(Command._get_connection_string(), version=version)