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:
Rick Harris
2013-02-27 23:32:40 +00:00
parent b1bcd6b2f8
commit 0caa87f8c5

View File

@@ -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,10 +400,11 @@ 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.
post_downgrade = getattr(
self, "_post_downgrade_%03d" % (version + 1), None)
if post_downgrade:
post_downgrade(engine)
if with_data:
post_downgrade = getattr(
self, "_post_downgrade_%03d" % (version + 1), None)
if post_downgrade:
post_downgrade(engine)
def _migrate_up(self, engine, version, with_data=False):
"""migrate up to a new version of the db.
@@ -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.db_version(engine,
self.REPOSITORY))
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: