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 <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2020-10-29 16:14:13 +00:00
parent 77676e833f
commit 7fb274f6db
5 changed files with 8 additions and 74 deletions

View File

@ -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()

View File

@ -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',
)

View File

@ -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()

View File

@ -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']

View File

@ -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.