From 2d72ac69df756d9f48cc9b82df16eb760f144eec Mon Sep 17 00:00:00 2001 From: Stephen Balukoff Date: Tue, 7 Jun 2016 13:44:44 -0700 Subject: [PATCH] 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 --- ...2816c232310_fix_migration_for_mysql_5_7.py | 33 +++++++++++++++++++ ..._change_tls_container_id_length_in_sni_.py | 2 +- octavia/db/models.py | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 octavia/db/migration/alembic_migrations/versions/62816c232310_fix_migration_for_mysql_5_7.py diff --git a/octavia/db/migration/alembic_migrations/versions/62816c232310_fix_migration_for_mysql_5_7.py b/octavia/db/migration/alembic_migrations/versions/62816c232310_fix_migration_for_mysql_5_7.py new file mode 100644 index 0000000000..fdf7db4cfa --- /dev/null +++ b/octavia/db/migration/alembic_migrations/versions/62816c232310_fix_migration_for_mysql_5_7.py @@ -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) diff --git a/octavia/db/migration/alembic_migrations/versions/8c0851bdf6c3_change_tls_container_id_length_in_sni_.py b/octavia/db/migration/alembic_migrations/versions/8c0851bdf6c3_change_tls_container_id_length_in_sni_.py index 49bce3eaba..5ee9b17765 100644 --- a/octavia/db/migration/alembic_migrations/versions/8c0851bdf6c3_change_tls_container_id_length_in_sni_.py +++ b/octavia/db/migration/alembic_migrations/versions/8c0851bdf6c3_change_tls_container_id_length_in_sni_.py @@ -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) diff --git a/octavia/db/models.py b/octavia/db/models.py index c1d5cfe1b7..9821ea3481 100644 --- a/octavia/db/models.py +++ b/octavia/db/models.py @@ -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",