Merge "Assume relative revisions belong to alembic"

This commit is contained in:
Jenkins 2015-08-20 15:03:15 +00:00 committed by Gerrit Code Review
commit 4ad8ed0c17
2 changed files with 13 additions and 0 deletions

View File

@ -94,6 +94,15 @@ class AlembicExtension(ext_base.MigrationExtensionBase):
def has_revision(self, rev_id): def has_revision(self, rev_id):
if rev_id in ['base', 'head']: if rev_id in ['base', 'head']:
return True return True
# Although alembic supports relative upgrades and downgrades,
# get_revision always returns False for relative revisions.
# Since only alembic supports relative revisions, assume the
# revision belongs to this plugin.
if rev_id: # rev_id can be None, so the check is required
if '-' in rev_id or '+' in rev_id:
return True
script = alembic_script.ScriptDirectory( script = alembic_script.ScriptDirectory(
self.config.get_main_option('script_location')) self.config.get_main_option('script_location'))
try: try:

View File

@ -109,6 +109,8 @@ class TestAlembicExtension(test_base.BaseTestCase):
'test') 'test')
self.assertIs(True, self.alembic.has_revision(None)) self.assertIs(True, self.alembic.has_revision(None))
self.assertIs(True, self.alembic.has_revision('head')) self.assertIs(True, self.alembic.has_revision('head'))
# relative revision, should be True for alembic
self.assertIs(True, self.alembic.has_revision('+1'))
def test_has_revision_negative(self, command): def test_has_revision_negative(self, command):
with mock.patch(('oslo_db.sqlalchemy.migration_cli.' with mock.patch(('oslo_db.sqlalchemy.migration_cli.'
@ -202,6 +204,8 @@ class TestMigrateExtension(test_base.BaseTestCase):
mocked.Collection().version.side_effect = ValueError mocked.Collection().version.side_effect = ValueError
self.assertIs(False, self.migrate.has_revision('test')) self.assertIs(False, self.migrate.has_revision('test'))
mocked.Collection().version.assert_called_once_with('test') mocked.Collection().version.assert_called_once_with('test')
# relative revision, should be False for migrate
self.assertIs(False, self.migrate.has_revision('+1'))
class TestMigrationManager(test_base.BaseTestCase): class TestMigrationManager(test_base.BaseTestCase):