Merge "Assume relative revisions belong to alembic"
This commit is contained in:
commit
4ad8ed0c17
@ -94,6 +94,15 @@ class AlembicExtension(ext_base.MigrationExtensionBase):
|
||||
def has_revision(self, rev_id):
|
||||
if rev_id in ['base', 'head']:
|
||||
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(
|
||||
self.config.get_main_option('script_location'))
|
||||
try:
|
||||
|
@ -109,6 +109,8 @@ class TestAlembicExtension(test_base.BaseTestCase):
|
||||
'test')
|
||||
self.assertIs(True, self.alembic.has_revision(None))
|
||||
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):
|
||||
with mock.patch(('oslo_db.sqlalchemy.migration_cli.'
|
||||
@ -202,6 +204,8 @@ class TestMigrateExtension(test_base.BaseTestCase):
|
||||
mocked.Collection().version.side_effect = ValueError
|
||||
self.assertIs(False, self.migrate.has_revision('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):
|
||||
|
Loading…
Reference in New Issue
Block a user