Fixes migrations for MySQL 5.6.* and MariaDB 10.1.*
In MySQL 5.6/MariaDB 10.1 and later versions there was a change on the restrictions over foreign keys (FK). In 019-datastore-fix.py, we attempt to change a column that is part of a FK from NULL to not NULL. This sort of modifications are not longer allowed. This situation caused trove-manage db_sync and trove-manage db_migrate to fail. To workaround this, the FK check before executing the ALTER query is disabled and then reenabled. Change-Id: I666d01235f2c3225aca3fe7520ebdf6d53831cab Closes-Bug: #1473226
This commit is contained in:
parent
d6d212fe45
commit
679e2283ec
@ -20,6 +20,7 @@ from sqlalchemy.sql.expression import update
|
|||||||
|
|
||||||
from trove.common import cfg
|
from trove.common import cfg
|
||||||
from trove.db.sqlalchemy.migrate_repo.schema import Table
|
from trove.db.sqlalchemy.migrate_repo.schema import Table
|
||||||
|
from trove.db.sqlalchemy import utils as db_utils
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
LEGACY_IMAGE_ID = "00000000-0000-0000-0000-000000000000"
|
LEGACY_IMAGE_ID = "00000000-0000-0000-0000-000000000000"
|
||||||
@ -89,6 +90,9 @@ def upgrade(migrate_engine):
|
|||||||
meta.bind = migrate_engine
|
meta.bind = migrate_engine
|
||||||
|
|
||||||
instance_table = Table('instances', meta, autoload=True)
|
instance_table = Table('instances', meta, autoload=True)
|
||||||
|
datastore_versions_table = Table('datastore_versions',
|
||||||
|
meta,
|
||||||
|
autoload=True)
|
||||||
|
|
||||||
if has_instances_wo_datastore_version(instance_table):
|
if has_instances_wo_datastore_version(instance_table):
|
||||||
instances = find_all_instances_wo_datastore_version(instance_table)
|
instances = find_all_instances_wo_datastore_version(instance_table)
|
||||||
@ -97,9 +101,6 @@ def upgrade(migrate_engine):
|
|||||||
datastores_table = Table('datastores',
|
datastores_table = Table('datastores',
|
||||||
meta,
|
meta,
|
||||||
autoload=True)
|
autoload=True)
|
||||||
datastore_versions_table = Table('datastore_versions',
|
|
||||||
meta,
|
|
||||||
autoload=True)
|
|
||||||
|
|
||||||
version_id = create_legacy_version(datastores_table,
|
version_id = create_legacy_version(datastores_table,
|
||||||
datastore_versions_table,
|
datastore_versions_table,
|
||||||
@ -111,8 +112,24 @@ def upgrade(migrate_engine):
|
|||||||
values=dict(datastore_version_id=version_id)
|
values=dict(datastore_version_id=version_id)
|
||||||
).execute()
|
).execute()
|
||||||
|
|
||||||
|
constraint_names = db_utils.get_foreign_key_constraint_names(
|
||||||
|
engine=migrate_engine,
|
||||||
|
table='instances',
|
||||||
|
columns=['datastore_version_id'],
|
||||||
|
ref_table='datastore_versions',
|
||||||
|
ref_columns=['id'])
|
||||||
|
db_utils.drop_foreign_key_constraints(
|
||||||
|
constraint_names=constraint_names,
|
||||||
|
columns=[instance_table.c.datastore_version_id],
|
||||||
|
ref_columns=[datastore_versions_table.c.id])
|
||||||
|
|
||||||
instance_table.c.datastore_version_id.alter(nullable=False)
|
instance_table.c.datastore_version_id.alter(nullable=False)
|
||||||
|
|
||||||
|
db_utils.create_foreign_key_constraints(
|
||||||
|
constraint_names=constraint_names,
|
||||||
|
columns=[instance_table.c.datastore_version_id],
|
||||||
|
ref_columns=[datastore_versions_table.c.id])
|
||||||
|
|
||||||
|
|
||||||
def downgrade(migrate_engine):
|
def downgrade(migrate_engine):
|
||||||
meta.bind = migrate_engine
|
meta.bind = migrate_engine
|
||||||
|
@ -52,3 +52,18 @@ def drop_foreign_key_constraints(constraint_names, columns,
|
|||||||
refcolumns=ref_columns,
|
refcolumns=ref_columns,
|
||||||
name=constraint_name)
|
name=constraint_name)
|
||||||
fkey_constraint.drop()
|
fkey_constraint.drop()
|
||||||
|
|
||||||
|
|
||||||
|
def create_foreign_key_constraints(constraint_names, columns,
|
||||||
|
ref_columns):
|
||||||
|
"""Create the foreign key constraints that match the given
|
||||||
|
criteria.
|
||||||
|
:param constraint_names: List of foreign key constraint names
|
||||||
|
:param columns: List of the foreign key columns.
|
||||||
|
:param ref_columns: List of the referenced columns.
|
||||||
|
"""
|
||||||
|
for constraint_name in constraint_names:
|
||||||
|
fkey_constraint = ForeignKeyConstraint(columns=columns,
|
||||||
|
refcolumns=ref_columns,
|
||||||
|
name=constraint_name)
|
||||||
|
fkey_constraint.create()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user