diff --git a/oslo_db/sqlalchemy/migration_cli/ext_alembic.py b/oslo_db/sqlalchemy/migration_cli/ext_alembic.py index 0348a37..a855321 100644 --- a/oslo_db/sqlalchemy/migration_cli/ext_alembic.py +++ b/oslo_db/sqlalchemy/migration_cli/ext_alembic.py @@ -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: diff --git a/oslo_db/tests/sqlalchemy/test_migrate_cli.py b/oslo_db/tests/sqlalchemy/test_migrate_cli.py index 72d8b4e..8d2ae8d 100644 --- a/oslo_db/tests/sqlalchemy/test_migrate_cli.py +++ b/oslo_db/tests/sqlalchemy/test_migrate_cli.py @@ -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):