From 7fb274f6db23485a8e672dfab9eb81fc9086415d Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 29 Oct 2020 16:14:13 +0000 Subject: [PATCH] db: Stop checking for DB under sqlalchemy-migrate control This has been in place since Ocata. If any version since then has been deployed, this will have already been deployed. Time to drop this. UpgradeImpact Change-Id: I5412d78c63cf3381782f5c6fc059641489f89053 Implements: blueprint remove-sqlalchemy-migrate Signed-off-by: Stephen Finucane --- glance/cmd/manage.py | 2 - glance/db/migration.py | 9 --- .../sqlalchemy/alembic_migrations/__init__.py | 60 ------------------- glance/tests/unit/test_manage.py | 3 - ...r-sqlalchemy-migrate-4bcbe7b200697586.yaml | 8 +++ 5 files changed, 8 insertions(+), 74 deletions(-) create mode 100644 releasenotes/notes/drop-support-for-sqlalchemy-migrate-4bcbe7b200697586.yaml diff --git a/glance/cmd/manage.py b/glance/cmd/manage.py index e7af21acf6..7139514f56 100644 --- a/glance/cmd/manage.py +++ b/glance/cmd/manage.py @@ -172,8 +172,6 @@ class DbCommands(object): Place an existing database under migration control and upgrade it. """ - alembic_migrations.place_database_under_alembic_control() - a_config = alembic_migrations.get_alembic_config() alembic_command.upgrade(a_config, version) heads = alembic_migrations.get_current_alembic_heads() diff --git a/glance/db/migration.py b/glance/db/migration.py index 507645ca63..08268b703e 100644 --- a/glance/db/migration.py +++ b/glance/db/migration.py @@ -19,7 +19,6 @@ """Database setup and migration commands.""" -import os import threading from oslo_config import cfg @@ -49,11 +48,3 @@ EXPAND_BRANCH = 'expand' CONTRACT_BRANCH = 'contract' CURRENT_RELEASE = 'wallaby' ALEMBIC_INIT_VERSION = 'liberty' -LATEST_REVISION = 'wallaby_contract01' -INIT_VERSION = 0 - -MIGRATE_REPO_PATH = os.path.join( - os.path.abspath(os.path.dirname(__file__)), - 'sqlalchemy', - 'migrate_repo', -) diff --git a/glance/db/sqlalchemy/alembic_migrations/__init__.py b/glance/db/sqlalchemy/alembic_migrations/__init__.py index ef9faf38cd..66d4639b69 100644 --- a/glance/db/sqlalchemy/alembic_migrations/__init__.py +++ b/glance/db/sqlalchemy/alembic_migrations/__init__.py @@ -14,19 +14,13 @@ # under the License. import os -import sys -from alembic import command as alembic_command from alembic import config as alembic_config from alembic import migration as alembic_migration from alembic import script as alembic_script from sqlalchemy import MetaData, Table -from oslo_db import exception as db_exception -from oslo_db.sqlalchemy import migration as sqla_migration -from glance.db import migration as db_migration from glance.db.sqlalchemy import api as db_api -from glance.i18n import _ def get_alembic_config(engine=None): @@ -75,60 +69,6 @@ def get_current_alembic_heads(): return heads -def get_current_legacy_head(): - try: - legacy_head = sqla_migration.db_version(db_api.get_engine(), - db_migration.MIGRATE_REPO_PATH, - db_migration.INIT_VERSION) - except db_exception.DBMigrationError: - legacy_head = None - return legacy_head - - -def is_database_under_alembic_control(): - if get_current_alembic_heads(): - return True - return False - - -def is_database_under_migrate_control(): - if get_current_legacy_head(): - return True - return False - - -def place_database_under_alembic_control(): - a_config = get_alembic_config() - - if not is_database_under_migrate_control(): - return - - if not is_database_under_alembic_control(): - print(_("Database is currently not under Alembic's migration " - "control.")) - head = get_current_legacy_head() - if head == 42: - alembic_version = 'liberty' - elif head == 43: - alembic_version = 'mitaka01' - elif head == 44: - alembic_version = 'mitaka02' - elif head == 45: - alembic_version = 'ocata01' - elif head in range(1, 42): - print("Legacy head: ", head) - sys.exit(_("The current database version is not supported any " - "more. Please upgrade to Liberty release first.")) - else: - sys.exit(_("Unable to place database under Alembic's migration " - "control. Unknown database state, can't proceed " - "further.")) - - print(_("Placing database under Alembic's migration control at " - "revision:"), alembic_version) - alembic_command.stamp(a_config, alembic_version) - - def get_alembic_branch_head(branch): """Return head revision name for particular branch""" a_config = get_alembic_config() diff --git a/glance/tests/unit/test_manage.py b/glance/tests/unit/test_manage.py index 2ebd2c9b05..6be965a125 100644 --- a/glance/tests/unit/test_manage.py +++ b/glance/tests/unit/test_manage.py @@ -258,11 +258,8 @@ class TestManage(TestManageBase): 'glance.db.sqlalchemy.alembic_migrations.get_current_alembic_heads') @mock.patch( 'glance.db.sqlalchemy.alembic_migrations.get_alembic_branch_head') - @mock.patch('glance.db.sqlalchemy.alembic_migrations.' - 'place_database_under_alembic_control') @mock.patch('alembic.command.upgrade') def test_sync_db_is_already_sync(self, mock_upgrade, - mock_db_under_alembic_control, mock_get_alembic_branch_head, mock_get_current_alembic_heads): mock_get_current_alembic_heads.return_value = ['pike_contract01'] diff --git a/releasenotes/notes/drop-support-for-sqlalchemy-migrate-4bcbe7b200697586.yaml b/releasenotes/notes/drop-support-for-sqlalchemy-migrate-4bcbe7b200697586.yaml new file mode 100644 index 0000000000..1cfc542215 --- /dev/null +++ b/releasenotes/notes/drop-support-for-sqlalchemy-migrate-4bcbe7b200697586.yaml @@ -0,0 +1,8 @@ +--- +upgrade: + - | + The database migration engine used by Glance for database upgrades was + changed from *SQLAlchemy Migrate* to *Alembic* in the 14.0.0 (Ocata) + release. Support for *SQLAlchemy Migrate* has now been removed. This + means in order to upgrade from a pre-Ocata release to Xena or later, + you must upgrade to Wallaby or earlier first.