Fix with_data handling in test-migrations.
Two issues with the existing code: 1) migrate-down wasn't respecting the `with_data` flag 2) migrate-up was not actually migrating unless `with_data` was True. The correct behavior is to always migrate up, but only run checks when `with_data` is set. Change-Id: I781fa4796908bea684d4499fa9ff5e4d7a18fbd4
This commit is contained in:
@@ -374,7 +374,7 @@ class BaseMigrationTestCase(test.TestCase):
|
||||
# upgrade -> downgrade -> upgrade
|
||||
self._migrate_up(engine, version, with_data=True)
|
||||
if snake_walk:
|
||||
self._migrate_down(engine, version - 1)
|
||||
self._migrate_down(engine, version - 1, with_data=True)
|
||||
self._migrate_up(engine, version)
|
||||
|
||||
if downgrade:
|
||||
@@ -389,7 +389,7 @@ class BaseMigrationTestCase(test.TestCase):
|
||||
self._migrate_up(engine, version)
|
||||
self._migrate_down(engine, version - 1)
|
||||
|
||||
def _migrate_down(self, engine, version):
|
||||
def _migrate_down(self, engine, version, with_data=False):
|
||||
self.migration_api.downgrade(engine,
|
||||
self.REPOSITORY,
|
||||
version)
|
||||
@@ -400,6 +400,7 @@ class BaseMigrationTestCase(test.TestCase):
|
||||
# NOTE(sirp): `version` is what we're downgrading to (i.e. the 'target'
|
||||
# version). So if we have any downgrade checks, they need to be run for
|
||||
# the previous (higher numbered) migration.
|
||||
if with_data:
|
||||
post_downgrade = getattr(
|
||||
self, "_post_downgrade_%03d" % (version + 1), None)
|
||||
if post_downgrade:
|
||||
@@ -422,14 +423,10 @@ class BaseMigrationTestCase(test.TestCase):
|
||||
if pre_upgrade:
|
||||
data = pre_upgrade(engine)
|
||||
|
||||
self.migration_api.upgrade(engine,
|
||||
self.REPOSITORY,
|
||||
version)
|
||||
self.assertEqual(
|
||||
version,
|
||||
self.migration_api.upgrade(engine, self.REPOSITORY, version)
|
||||
self.assertEqual(version,
|
||||
self.migration_api.db_version(engine,
|
||||
self.REPOSITORY))
|
||||
|
||||
if with_data:
|
||||
check = getattr(self, "_check_%03d" % version, None)
|
||||
if check:
|
||||
|
||||
Reference in New Issue
Block a user