diff options
author | Boris Bobrov <bbobrov@mirantis.com> | 2015-07-13 20:35:56 +0300 |
---|---|---|
committer | Boris Bobrov <bbobrov@mirantis.com> | 2015-08-05 15:17:59 +0300 |
commit | dbca2ee070a3b27359cf80c02cbc632574c0e18f (patch) | |
tree | 04d4fad98efc6a25b8b66605f85a18a54048e5dc /oslo_db/sqlalchemy/migration_cli/ext_alembic.py | |
parent | 5554801ee6b76b14ed5dbbbc70a4b62e823b3deb (diff) | |
download | oslo-db-dbca2ee070a3b27359cf80c02cbc632574c0e18f.tar.gz |
Upgrade and downgrade based on revision existence
Before there was no way to upgrade to a specific revision, because the
revision passed to the manager was passed to all the plugins, some of
which failed to process it.
Add a new method to every plugin `has_revision`, which returns
whether the plugin has the revision. Use it in upgrade and
downgrade.
Change-Id: I89b02d7ad479da6bff3c492c88edfee9c19abc22
Closes-Bug: 1474067
Diffstat (limited to 'oslo_db/sqlalchemy/migration_cli/ext_alembic.py')
-rw-r--r-- | oslo_db/sqlalchemy/migration_cli/ext_alembic.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/oslo_db/sqlalchemy/migration_cli/ext_alembic.py b/oslo_db/sqlalchemy/migration_cli/ext_alembic.py index 1dbf88f..825c638 100644 --- a/oslo_db/sqlalchemy/migration_cli/ext_alembic.py +++ b/oslo_db/sqlalchemy/migration_cli/ext_alembic.py @@ -15,6 +15,7 @@ import os import alembic from alembic import config as alembic_config import alembic.migration as alembic_migration +from alembic import script as alembic_script from oslo_db.sqlalchemy.migration_cli import ext_base @@ -89,3 +90,14 @@ class AlembicExtension(ext_base.MigrationExtensionBase): with self.engine.begin() as connection: self.config.attributes['connection'] = connection return alembic.command.stamp(self.config, revision=revision) + + def has_revision(self, rev_id): + if rev_id in ['base', 'head']: + return True + script = alembic_script.ScriptDirectory( + self.config.get_main_option('alembic_repo_path')) + try: + script.get_revision(rev_id) + return True + except alembic.util.CommandError: + return False |