Add database downgrade migration tests

Change-Id: I7cab62ab22fc313ed84a220352caffd841595746
This commit is contained in:
Mike Fedosin 2017-05-28 23:21:38 +03:00
parent d9915469ab
commit 1f7a4ffeda
2 changed files with 18 additions and 28 deletions

View File

@ -156,36 +156,8 @@ def upgrade():
mysql_charset=MYSQL_CHARSET
)
# end Alembic commands #
def downgrade():
op.drop_index('ix_glare_artifact_properties_name',
table_name='glare_artifact_properties')
op.drop_index('ix_glare_artifact_properties_artifact_id',
table_name='glare_artifact_properties')
op.drop_index('ix_glare_artifact_blobs_name',
table_name='glare_artifact_blobs')
op.drop_index('ix_glare_artifact_blobs_artifact_id',
table_name='glare_artifact_blobs')
op.drop_index('ix_glare_artifact_tags_artifact_id_tag_value',
table_name='glare_artifact_tags')
op.drop_index('ix_glare_artifact_tags_artifact_id',
table_name='glare_artifact_tags')
op.drop_index('ix_glare_artifact_visibility',
table_name='glare_artifacts')
op.drop_index('ix_glare_artifact_owner',
table_name='glare_artifacts')
op.drop_index('ix_glare_artifact_status',
table_name='glare_artifacts')
op.drop_index('ix_glare_artifact_type',
table_name='glare_artifacts')
op.drop_index('ix_glare_artifact_name_and_version',
table_name='glare_artifacts')
op.drop_table('glare_artifact_locks')
op.drop_table('glare_artifact_properties')
op.drop_table('glare_artifact_blobs')

View File

@ -73,6 +73,11 @@ class WalkVersionsMixin(object):
self._migrate_up(engine, alembic_cfg,
version.revision, with_data=True)
for version in versions:
with glare_fixtures.BannedDBSchemaOperations():
self._migrate_down(engine, alembic_cfg,
version.down_revision, with_data=True)
def _migrate_up(self, engine, config, version, with_data=False):
"""migrate up to a new version of the db.
@ -99,6 +104,19 @@ class WalkVersionsMixin(object):
"%(engine)s", {'version': version, 'engine': engine})
raise
def _migrate_down(self, engine, config, version, with_data=False):
try:
self.migration_api.downgrade(version, config=config)
if with_data:
post_downgrade = getattr(
self, "_post_downgrade_%s" % version, None)
if post_downgrade:
post_downgrade(engine)
except Exception:
LOG.error("Failed to migrate to version %(version)s on engine "
"%(engine)s", {'version': version, 'engine': engine})
raise
class GlareMigrationsCheckers(object):