Fix for migration 062 on MySQL
MySQL creates indexes for foreign key columns automatically on InnoDB, so we should remove this index as well now that we have dropped the FK. Related-Bug: #1292591 Change-Id: Ie8c69cc10ebdd805fc5cef82cb08c7d73c70b6e1
This commit is contained in:
parent
102032597d
commit
12a9121e6e
|
@ -0,0 +1,25 @@
|
|||
# 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.
|
||||
|
||||
import sqlalchemy
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
# NOTE(viktors): Migration 062 removed FK from `assignment` table, but
|
||||
# MySQL silently creates indexes on FK constraints, so we should remove
|
||||
# this index manually.
|
||||
if migrate_engine.name == 'mysql':
|
||||
meta = sqlalchemy.MetaData(bind=migrate_engine)
|
||||
table = sqlalchemy.Table('assignment', meta, autoload=True)
|
||||
for index in table.indexes:
|
||||
if [c.name for c in index.columns] == ['role_id']:
|
||||
index.drop(migrate_engine)
|
|
@ -532,6 +532,21 @@ class SqlUpgradeTests(SqlMigrateBase):
|
|||
extra = fetch_service_extra(service_id)
|
||||
self.assertDictEqual(exp_extra, extra, msg)
|
||||
|
||||
def _does_index_exist(self, table_name, index_name):
|
||||
meta = sqlalchemy.MetaData(bind=self.engine)
|
||||
table = sqlalchemy.Table('assignment', meta, autoload=True)
|
||||
return index_name in [idx.name for idx in table.indexes]
|
||||
|
||||
def test_drop_assignment_role_id_index_mysql(self):
|
||||
self.upgrade(66)
|
||||
if self.engine.name == "mysql":
|
||||
self.assertTrue(self._does_index_exist('assignment',
|
||||
'assignment_role_id_fkey'))
|
||||
self.upgrade(67)
|
||||
if self.engine.name == "mysql":
|
||||
self.assertFalse(self._does_index_exist('assignment',
|
||||
'assignment_role_id_fkey'))
|
||||
|
||||
def populate_user_table(self, with_pass_enab=False,
|
||||
with_pass_enab_domain=False):
|
||||
# Populate the appropriate fields in the user
|
||||
|
|
Loading…
Reference in New Issue