Fix column rename migration for mariadb 10.2

MariaDB 10.2 introduced an issue where an automatic check constraint is
applied to boolean columns and is not automatically updated on a column
rename alter operation[1]. A similar issue preventing dropping such a
column was already fixed[2], so this patch changes the migration to drop
and readd the column instead of attempting a column rename.

Unfortunately since the mistake was already made, it is possible for
deployments out in the wild to have made it past the expand step and be
currently stuck in the contract step. To accomodate them, we add the new
column as part of the contract step if necessary. Again, since there
should be no data in this table, we don't need to worry about online
upgrades here.

[1] https://jira.mariadb.org/browse/MDEV-13508
[2] https://jira.mariadb.org/browse/MDEV-11114

Change-Id: Icbd58464182b082854fb5d73ccc93c900ede020c
Closes-bug: #1744948
This commit is contained in:
Colleen Murphy 2018-01-23 16:36:15 +01:00
parent 9cd5f198da
commit 59b1aacdba
2 changed files with 16 additions and 4 deletions

View File

@ -28,5 +28,13 @@ def upgrade(migrate_engine):
new_table.rename('application_credential')
else:
table = application_credential_table
# NOTE(cmurphy) because of lb#1744948, some deployments could already
# have made it past the expand step and be stuck on the contract step.
# If necessary, do the expand step here.
# At this point this API is not yet exposed and there should be no data
# in this table.
if 'unrestricted' not in table.columns:
unrestricted = sql.Column('unrestricted', sql.Boolean())
table.create_column(unrestricted)
column = table.c.allow_application_credential_creation
column.alter(name='unrestricted')
column.drop()

View File

@ -18,13 +18,14 @@ def upgrade(migrate_engine):
meta = sql.MetaData()
meta.bind = migrate_engine
table = sql.Table(
'application_credential', meta, autoload=True
)
# MySQL and PostgreSQL can handle a column rename.
# Only Sqlite is special. Since Sqlite can't support an online upgrade
# anyway, just brute-force the migration by copying the table.
if migrate_engine.name == 'sqlite':
old_table = sql.Table(
'application_credential', meta, autoload=True
)
old_table = table
args = []
for column in old_table.columns:
@ -38,3 +39,6 @@ def upgrade(migrate_engine):
new_table = sql.Table('application_credential_temp',
old_table.metadata, *args)
new_table.create(migrate_engine, checkfirst=True)
else:
unrestricted = sql.Column('unrestricted', sql.Boolean())
table.create_column(unrestricted)