Skip to content

Commit

Permalink
Assume relative revisions belong to alembic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Boris Bobrov committed Aug 20, 2015
1 parent 4e83ad8 commit b843f04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions oslo_db/sqlalchemy/migration_cli/ext_alembic.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ def stamp(self, revision):
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:
Expand Down
4 changes: 4 additions & 0 deletions oslo_db/tests/sqlalchemy/test_migrate_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def test_has_revision(self, command):
'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.'
Expand Down Expand Up @@ -198,6 +200,8 @@ def test_has_revision_negative(self, command):
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):
Expand Down

0 comments on commit b843f04

Please sign in to comment.