Fix alembic migration on MySQL 5.7

Presently, attempting to run alembic migrations for Octavia on a host
using MySQL 5.7 as the database back-end fails with an error about a
nullable field in a primary key. This commit fixes the offending
migration and introduces a second, similar migration so that any
existing installation using MySQL 5.6 or older also have this field set
to be non-nullable.

Change-Id: Iae3d4f627c1124b1d913aab283e6e19d9c0f0dbb
Closes-Bug: #1590145
This commit is contained in:
Stephen Balukoff 2016-06-07 13:44:44 -07:00
parent 0f8e913b3e
commit 2d72ac69df
3 changed files with 35 additions and 2 deletions

View File

@ -0,0 +1,33 @@
# Copyright 2016 IBM
#
# 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.
"""Fix migration for MySQL 5.7
Revision ID: 62816c232310
Revises: 36b94648fef8
Create Date: 2016-06-07 12:59:21.059619
"""
# revision identifiers, used by Alembic.
revision = '62816c232310'
down_revision = '36b94648fef8'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.alter_column(u'sni', u'tls_container_id', type_=sa.String(128),
existing_type=sa.String(36), nullable=False)

View File

@ -30,4 +30,4 @@ import sqlalchemy as sa
def upgrade():
op.alter_column(u'sni', u'tls_container_id', type_=sa.String(128),
existing_type=sa.String(36), nullable=True)
existing_type=sa.String(36), nullable=False)

View File

@ -418,7 +418,7 @@ class SNI(base_models.BASE):
sa.String(36),
sa.ForeignKey("listener.id", name="fk_sni_listener_id"),
nullable=False)
tls_container_id = sa.Column(sa.String(36), nullable=False)
tls_container_id = sa.Column(sa.String(128), nullable=False)
position = sa.Column(sa.Integer(), nullable=True)
listener = orm.relationship("Listener", uselist=False,
backref=orm.backref("sni_containers",