From 12812114be77a339b562b79fbcd0fe4b45fa71eb Mon Sep 17 00:00:00 2001 From: Mingxing LAI Date: Wed, 19 Oct 2016 13:12:05 +0800 Subject: [PATCH] Fix issue #7 when indexed on more than one columns,the diff-result is wrong --- .gitignore | 2 ++ mysql/utilities/common/dbcompare.py | 27 +++++++++++++++++++++++++++ mysql/utilities/common/sql_transform.py | 6 ++---- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index cd58598..47f2a3b 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,5 @@ coverage.xml # Result file used by some MUT tests mysql-test/result.txt +tags +scripts/ diff --git a/mysql/utilities/common/dbcompare.py b/mysql/utilities/common/dbcompare.py index c7ae522..82bf302 100644 --- a/mysql/utilities/common/dbcompare.py +++ b/mysql/utilities/common/dbcompare.py @@ -256,6 +256,33 @@ def server_connect(server1_val, server2_val, object1, object2, options): return (server1, server2) +def _get_difference(list1, list2): + """ + some elem exists in list1 but not in list2 + """ + res = [] + for item in list1: + if list2.count(item) == 0: + res.append(item) + return res + +def _get_common(list1, list2): + """ + elem exists in list1 and exists in list2 + """ + res = [] + for item in list1: + if list2.count(item) == 1: + res.append(item) + return res + +def get_common_lists_keep_order(list1, list2): + a_and_b = _get_common(list1, list2) + a_diff_b = _get_difference(list1, list2) + b_diff_a = _get_difference(list2, list1) + + return a_and_b, a_diff_b, b_diff_a + def get_common_lists(list1, list2): """Compare the items in two lists diff --git a/mysql/utilities/common/sql_transform.py b/mysql/utilities/common/sql_transform.py index 30989e6..578cc1d 100644 --- a/mysql/utilities/common/sql_transform.py +++ b/mysql/utilities/common/sql_transform.py @@ -996,8 +996,7 @@ def _get_indexes(self, src_db, src_name, dest_db, dest_name): Returns tuple - (drop, add/changes) """ from mysql.utilities.common.table import Table - from mysql.utilities.common.dbcompare import get_common_lists - + from mysql.utilities.common.dbcompare import get_common_lists_keep_order # Get the Table instances self.dest_tbl = Table(self.destination_db.source, "%s.%s" % (dest_db, dest_name)) @@ -1015,7 +1014,7 @@ def _get_indexes(self, src_db, src_name, dest_db, dest_name): for idx in self.src_tbl.get_tbl_indexes()] # Now we determine the indexes we need to add and those to drop - _, drop_idx, add_idx = get_common_lists(dest_idx, src_idx) + _, drop_idx, add_idx = get_common_lists_keep_order(dest_idx, src_idx) if not drop_idx and not add_idx: return ([], []) @@ -1086,7 +1085,6 @@ def _transform_table(self): Returns list - ALTER TABLE statements for transforming the table """ statements = [] - # Collect a list of all of the ALTER clauses. Order is important in # building an ALTER TABLE statement. For safety (and correct execution) # we must order the clauses as follows: