Merge "Fix DB migrations after alembic integration" into stable/2024.2
This commit is contained in:
@@ -440,7 +440,7 @@ class DbSync(BaseApp):
|
||||
except db_exception.DBMigrationError:
|
||||
contract_version = None
|
||||
|
||||
heads = upgrades.get_current_heads()
|
||||
heads = upgrades.get_head_revisions()
|
||||
|
||||
if (
|
||||
upgrades.EXPAND_BRANCH not in heads
|
||||
|
||||
@@ -19,6 +19,7 @@ import os
|
||||
from alembic import command as alembic_api
|
||||
from alembic import config as alembic_config
|
||||
from alembic import migration as alembic_migration
|
||||
from alembic.runtime import environment as alembic_environment
|
||||
from alembic import script as alembic_script
|
||||
from oslo_db import exception as db_exception
|
||||
from oslo_log import log as logging
|
||||
@@ -112,6 +113,11 @@ def _get_current_heads(engine, config):
|
||||
context = alembic_migration.MigrationContext.configure(conn)
|
||||
heads = context.get_current_heads()
|
||||
|
||||
heads_map = _get_head_maps(heads, script)
|
||||
return heads_map
|
||||
|
||||
|
||||
def _get_head_maps(heads, script):
|
||||
heads_map = {}
|
||||
|
||||
for head in heads:
|
||||
@@ -149,6 +155,17 @@ def get_current_heads():
|
||||
return heads
|
||||
|
||||
|
||||
def get_head_revisions():
|
||||
"""Get the available head for each the expand and contract branches."""
|
||||
config = _find_alembic_conf()
|
||||
script = alembic_script.ScriptDirectory.from_config(config)
|
||||
context = alembic_environment.EnvironmentContext(config, script)
|
||||
heads = context.get_head_revisions()
|
||||
heads_map = _get_head_maps(heads, script)
|
||||
|
||||
return heads_map
|
||||
|
||||
|
||||
def _is_database_under_alembic_control(engine):
|
||||
with engine.connect() as conn:
|
||||
context = alembic_migration.MigrationContext.configure(conn)
|
||||
|
||||
Reference in New Issue
Block a user