From bd272cb0599436bba5414037ca33bf80c52bb784 Mon Sep 17 00:00:00 2001 From: Ann Date: Thu, 12 Jan 2017 08:12:50 +0000 Subject: [PATCH] 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 --- neutron/db/migration/__init__.py | 8 ++++++++ .../migration/alembic_migrations/versions/kilo_initial.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/neutron/db/migration/__init__.py b/neutron/db/migration/__init__.py index 3a641ed9e43..6a242bc2218 100644 --- a/neutron/db/migration/__init__.py +++ b/neutron/db/migration/__init__.py @@ -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']) diff --git a/neutron/db/migration/alembic_migrations/versions/kilo_initial.py b/neutron/db/migration/alembic_migrations/versions/kilo_initial.py index cb305f73f8a..5bd9a9528b1 100644 --- a/neutron/db/migration/alembic_migrations/versions/kilo_initial.py +++ b/neutron/db/migration/alembic_migrations/versions/kilo_initial.py @@ -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()