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
This commit is contained in:
Stefan Nica 2018-02-13 14:09:19 +01:00
parent 6368a9e887
commit 2beb7ac13a
2 changed files with 12 additions and 0 deletions

View File

@ -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)

View File

@ -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