From 4a40da15fe0e9688c363371fd998ef7c3ba321ee Mon Sep 17 00:00:00 2001 From: Stefan Nica Date: Tue, 13 Feb 2018 14:09:19 +0100 Subject: [PATCH] Fix db migration for mariadb >= 10.2.8 Starting with mariadb 10.2.8, removing a column that is part of a primary key requires that the primary key constraint be dropped and recreated. Change-Id: I43e4dae325dd6561a9fe0fd4ce595cea4c2ef7a6 Closes-Bug: #1749184 (cherry picked from commit 2beb7ac13ab640c6178a711fc39c75bd71b2bc2c) --- .../e8ea58723178_remove_host_from_driver_private_data.py | 7 +++++++ releasenotes/notes/bug-1749184-eb06929e76a14fce.yaml | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 releasenotes/notes/bug-1749184-eb06929e76a14fce.yaml diff --git a/manila/db/migrations/alembic/versions/e8ea58723178_remove_host_from_driver_private_data.py b/manila/db/migrations/alembic/versions/e8ea58723178_remove_host_from_driver_private_data.py index 4dd885cada..48f2c03b05 100644 --- a/manila/db/migrations/alembic/versions/e8ea58723178_remove_host_from_driver_private_data.py +++ b/manila/db/migrations/alembic/versions/e8ea58723178_remove_host_from_driver_private_data.py @@ -38,10 +38,17 @@ COLUMN_HOST = 'host' DEFAULT_HOST = 'unknown' COLUMN_ENTITY = 'entity_uuid' COLUMN_KEY = 'key' +MYSQL_ENGINE = 'mysql' def upgrade(): + bind = op.get_bind() + engine = bind.engine try: + if (engine.name == MYSQL_ENGINE): + op.drop_constraint('PRIMARY', TABLE_NAME, type_='primary') + op.create_primary_key('DRIVERS_PRIVATE_PK', TABLE_NAME, + ['entity_uuid', 'key']) op.drop_column(TABLE_NAME, COLUMN_HOST) except Exception: LOG.error("Column '%s' could not be dropped", COLUMN_HOST) diff --git a/releasenotes/notes/bug-1749184-eb06929e76a14fce.yaml b/releasenotes/notes/bug-1749184-eb06929e76a14fce.yaml new file mode 100644 index 0000000000..411bc47a10 --- /dev/null +++ b/releasenotes/notes/bug-1749184-eb06929e76a14fce.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - The database migration has been adjusted to work with mariadb >= 10.2.8 + by ensuring that a primary key constraint is first dropped and re-added + when a column is removed that is part of it