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 on the review [1]. Anyway here migration is
proposed that will add pk on this table if it is missing, as in
other case we will have inconsistency between new deployments and
old ones.

[1] - https://gerrit.sqlalchemy.org/#/c/279/

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 d09f6e4225
commit fc075fa0d8
4 changed files with 44 additions and 1 deletions

View File

@ -212,3 +212,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

@ -1 +1 @@
5cd92597d11d
929c968efe70

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

View File

@ -0,0 +1,33 @@
# Copyright 2017 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""add_pk_version_table
Revision ID: 929c968efe70
Revises: 5cd92597d11d
Create Date: 2017-01-12 07:17:33.677770
"""
# revision identifiers, used by Alembic.
revision = '929c968efe70'
down_revision = '5cd92597d11d'
from neutron.db import migration
def upgrade():
migration.pk_on_alembic_version_table()