From 7971b8ab6030013168bf300ccec62398c0383deb Mon Sep 17 00:00:00 2001 From: Sahid Orentino Ferdjaoui Date: Tue, 30 Apr 2019 10:10:44 +0200 Subject: [PATCH] db: add missing primary key in spares_pool table In commit a205ab3ebe4ae14668f25328c062f9383d6c69cb a new model spares_pool has been introduced but the definition introduced by 0b468090e6eef1483f6f7c53708f500802a57d51 was missing the primary key. In this commit we fixed the definition and add an update script for already deployed env. Note: without the PK this creates an error when Running Percona with pxc_strict_mode == ENFORCING Story: 2005531 Task: 30658 Change-Id: If70e5df5aea008e8998eaad912ba85dfb6bda77a Signed-off-by: Sahid Orentino Ferdjaoui --- ...b85b4419_add_primary_key_to_spares_pool.py | 47 +++++++++++++++++++ .../6ffc710674ef_spares_pool_table.py | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 octavia/db/migration/alembic_migrations/versions/392fb85b4419_add_primary_key_to_spares_pool.py diff --git a/octavia/db/migration/alembic_migrations/versions/392fb85b4419_add_primary_key_to_spares_pool.py b/octavia/db/migration/alembic_migrations/versions/392fb85b4419_add_primary_key_to_spares_pool.py new file mode 100644 index 0000000000..cdfb2f115c --- /dev/null +++ b/octavia/db/migration/alembic_migrations/versions/392fb85b4419_add_primary_key_to_spares_pool.py @@ -0,0 +1,47 @@ +# Copyright 2016 Rackspace +# +# 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 primary key to spares_pool + +Revision ID: 392fb85b4419 +Revises: 46d914b2a5e5 +Create Date: 2019-04-30 09:58:54.159823 + +""" + +from alembic import op +from sqlalchemy.engine import reflection + +from oslo_log import log as logging + + +# revision identifiers, used by Alembic. +revision = '392fb85b4419' +down_revision = '46d914b2a5e5' + +LOG = logging.getLogger(__name__) + + +def upgrade(): + bind = op.get_bind() + inspector = reflection.Inspector.from_engine(bind.engine) + pk = inspector.get_pk_constraint('spares_pool') + if not pk['constrained_columns']: + op.create_primary_key( + u'pk_spares_pool', u'spares_pool', [u'updated_at']) + else: + # Revision '46d914b2a5e5' has been updated to create the + # missing PK. Depending whether the env is already deployed or + # not we may or not have to add the primary key. + LOG.info("The primary key in spares_pool already exists, continuing.") diff --git a/octavia/db/migration/alembic_migrations/versions/6ffc710674ef_spares_pool_table.py b/octavia/db/migration/alembic_migrations/versions/6ffc710674ef_spares_pool_table.py index ff42e65497..07a091228c 100644 --- a/octavia/db/migration/alembic_migrations/versions/6ffc710674ef_spares_pool_table.py +++ b/octavia/db/migration/alembic_migrations/versions/6ffc710674ef_spares_pool_table.py @@ -31,5 +31,5 @@ down_revision = '7432f1d4ea83' def upgrade(): op.create_table( u'spares_pool', - sa.Column(u'updated_at', sa.DateTime(), nullable=True, + sa.Column(u'updated_at', sa.DateTime(), primary_key=True, server_default=sa.func.current_timestamp()))