def _walk_versions(self, initial_version=0): # 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(exception.DatabaseMigrationError, migration_api.db_version) # Place the database under version control migration_api.version_control(version=initial_version) cur_version = migration_api.db_version() self.assertEqual(initial_version, cur_version) for version in xrange(initial_version + 1, TestMigrations.REPOSITORY.latest + 1): migration_api.db_sync(version) cur_version = migration_api.db_version() 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(version) cur_version = migration_api.db_version() self.assertEqual(cur_version, version)
def test_db_sync(self): initial_version = 0 migration_api.db_sync(initial_version) cur_version = migration_api.db_version() self.assertEqual(cur_version, initial_version) migration_api.db_sync(TestMigrations.REPOSITORY.latest) cur_version = migration_api.db_version() self.assertEqual(cur_version, TestMigrations.REPOSITORY.latest) migration_api.db_sync(initial_version) cur_version = migration_api.db_version() self.assertEqual(cur_version, initial_version)
def sync(self, version=None, current_version=None): """ Place a database under migration control and upgrade, creating first if necessary. """ migration.db_sync(version, current_version)