summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Bobrov <bbobrov@mirantis.com>2015-08-20 13:51:54 +0300
committerBoris Bobrov <bbobrov@mirantis.com>2015-08-20 14:41:14 +0300
commitb843f049f39251c46f57df2b0da3fdc1ec923ef0 (patch)
treecd0bb24d0ea2e80925d7d1b086d62028b20c8ce8
parent4e83ad8299182d1e8a1b0600c0722d4754180487 (diff)
downloadoslo-db-b843f049f39251c46f57df2b0da3fdc1ec923ef0.tar.gz
Assume relative revisions belong to alembic
migration_cli alembic plugin returned that it doesn't know anything about relative revisions. This cause the situation when one could not perform relative upgrades or downgrades. Change-Id: I3c0eddf75d4a8c91c7a23c6fbad947900ec0ac94 Closes-Bug: 1486790
-rw-r--r--oslo_db/sqlalchemy/migration_cli/ext_alembic.py9
-rw-r--r--oslo_db/tests/sqlalchemy/test_migrate_cli.py4
2 files changed, 13 insertions, 0 deletions
diff --git a/oslo_db/sqlalchemy/migration_cli/ext_alembic.py b/oslo_db/sqlalchemy/migration_cli/ext_alembic.py
index 825c638..2fb9583 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('alembic_repo_path'))
try:
diff --git a/oslo_db/tests/sqlalchemy/test_migrate_cli.py b/oslo_db/tests/sqlalchemy/test_migrate_cli.py
index 6bdb09a..5a8aba7 100644
--- a/oslo_db/tests/sqlalchemy/test_migrate_cli.py
+++ b/oslo_db/tests/sqlalchemy/test_migrate_cli.py
@@ -107,6 +107,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.'
@@ -198,6 +200,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):