Ensure migration script use correct alembic table

At the moment migration script does misbehave and will fail on attempt
to migrate database from old SQLAlchemy Migrate to Alembic due to
misconfigured alembic_table.

Right now alembic_version table is being used by taskflow. With that it
was existing before 2024.1, where Masakari has adopted alembic as well.

As a result, masakari-manage db sync returns early from
_migrate_legacy_database as it treats taskflow alembic DB as it's own.
And when it tries to apply migrations - it fails as table already exist.

masakari-manage db version also shows taskflow version instead of
masakari version which is misleading.

Passing correct version_table to MigrationContext fixes the issue.

Change-Id: I67e04640ec76cf000aadfc5834d89da7a772a8d6
This commit is contained in:
Dmitriy Rabotyagov 2024-05-20 14:38:44 +02:00
parent 15def73bb8
commit ca1e09dee2

View File

@ -47,7 +47,9 @@ def _migrate_legacy_database(engine, connection, config):
# Likewise, if we've already migrated to alembic, we don't have anything to # Likewise, if we've already migrated to alembic, we don't have anything to
# do # do
context = alembic_migration.MigrationContext.configure(connection) context = alembic_migration.MigrationContext.configure(
connection,
opts={'version_table': 'masakari_alembic_version'})
if context.get_current_revision(): if context.get_current_revision():
return return
@ -175,5 +177,8 @@ def db_version():
"""Get database version.""" """Get database version."""
engine = db_api.get_engine() engine = db_api.get_engine()
with engine.connect() as connection: with engine.connect() as connection:
m_context = alembic_migration.MigrationContext.configure(connection) m_context = alembic_migration.MigrationContext.configure(
connection,
opts={'version_table': 'masakari_alembic_version'}
)
return m_context.get_current_revision() return m_context.get_current_revision()