Manually add pk for alembic_version table

We hit a problem that Neutron migrations cannot be applied
on galera cluster with ENFORCING mode as alembic_version table
missing primary key on the table and it is expected that all tables
will have primary keys.

alembic_version is created and managed by Alembic and fixes for this
on Alembic side are available since 0.8.10.
We cannot bump requirements for stable/newton but we can add
pk manually to allow new deployments with Newton code on Galera.

Change-Id: I543a1ee286bdf11ae35adb87125d044a351a2648
Closes-bug: #1655610
This commit is contained in:
Ann 2017-01-12 08:12:50 +00:00 committed by Ann Kamyshnikova
parent a79da4c310
commit bd272cb059
2 changed files with 10 additions and 0 deletions

View File

@ -210,3 +210,11 @@ def remove_fks_from_table(table, remove_unique_constraints=False):
yield
finally:
create_foreign_keys(table, foreign_keys)
def pk_on_alembic_version_table():
inspector = reflection.Inspector.from_engine(op.get_bind())
pk = inspector.get_pk_constraint('alembic_version')
if not pk['constrained_columns']:
op.create_primary_key(op.f('pk_alembic_version'),
'alembic_version', ['version_num'])

View File

@ -25,6 +25,7 @@ revision = 'kilo'
down_revision = None
from neutron.db import migration
from neutron.db.migration.alembic_migrations import agent_init_ops
from neutron.db.migration.alembic_migrations import brocade_init_ops
from neutron.db.migration.alembic_migrations import cisco_init_ops
@ -49,6 +50,7 @@ from neutron.db.migration.alembic_migrations import vpn_init_ops
def upgrade():
migration.pk_on_alembic_version_table()
agent_init_ops.upgrade()
core_init_ops.upgrade()
l3_init_ops.upgrade()