From b6d9cbe5dff1f255d091c763b86cd6a05589bd65 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Wed, 2 Mar 2022 14:03:46 +0800 Subject: [PATCH] sync-diff: turn off new collation (#597) close pingcap/tidb-tools#596 --- pkg/dbutil/table.go | 5 ++++ pkg/dbutil/table_test.go | 50 +++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/pkg/dbutil/table.go b/pkg/dbutil/table.go index e28be8a9b..80eb5c0c7 100644 --- a/pkg/dbutil/table.go +++ b/pkg/dbutil/table.go @@ -26,8 +26,13 @@ import ( _ "github.com/pingcap/tidb/planner/core" // to setup expression.EvalAstExpr. See: https://github.com/pingcap/tidb/blob/a94cff903cd1e7f3b050db782da84273ef5592f4/planner/core/optimizer.go#L202 "github.com/pingcap/tidb/types" _ "github.com/pingcap/tidb/types/parser_driver" // for parser driver + "github.com/pingcap/tidb/util/collate" ) +func init() { + collate.SetNewCollationEnabledForTest(false) +} + // GetTableInfo returns table information. func GetTableInfo(ctx context.Context, db QueryExecutor, schemaName string, tableName string) (*model.TableInfo, error) { createTableSQL, err := GetCreateTableSQL(ctx, db, schemaName, tableName) diff --git a/pkg/dbutil/table_test.go b/pkg/dbutil/table_test.go index 6dea9cdb0..14324ce59 100644 --- a/pkg/dbutil/table_test.go +++ b/pkg/dbutil/table_test.go @@ -17,10 +17,11 @@ import ( "testing" . "github.com/pingcap/check" - "github.com/pingcap/tidb-tools/pkg/schemacmp" "github.com/pingcap/tidb/parser" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/types" + + "github.com/pingcap/tidb-tools/pkg/schemacmp" ) func TestClient(t *testing.T) { @@ -43,13 +44,24 @@ type testCase struct { func (*testDBSuite) TestTable(c *C) { testCases := []*testCase{ { + ` + CREATE TABLE htest ( + a int(11) PRIMARY KEY + ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin + `, + []string{"a"}, + []string{mysql.PrimaryKeyName}, + [][]int{{types.UnspecifiedLength}}, + "c", + false, + }, { ` CREATE TABLE itest (a int(11) NOT NULL, - b double NOT NULL DEFAULT '2', - c varchar(10) NOT NULL, - d time DEFAULT NULL, - PRIMARY KEY (a, b), - UNIQUE KEY d (d)) + b double NOT NULL DEFAULT '2', + c varchar(10) NOT NULL, + d time DEFAULT NULL, + PRIMARY KEY (a, b), + UNIQUE KEY d (d)) `, []string{"a", "b", "c", "d"}, []string{mysql.PrimaryKeyName, "d"}, @@ -81,6 +93,31 @@ func (*testDBSuite) TestTable(c *C) { [][]int{{types.UnspecifiedLength}}, "d", false, + }, { + ` + CREATE TABLE ntest ( + a int(24) PRIMARY KEY CLUSTERED + ) + `, + []string{"a"}, + []string{mysql.PrimaryKeyName}, + [][]int{{types.UnspecifiedLength}}, + "d", + false, + }, { + ` + CREATE TABLE otest ( + a int(11) NOT NULL, + b varchar(10) DEFAULT NULL, + c varchar(255) DEFAULT NULL, + PRIMARY KEY (a) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci + `, + []string{"a", "b", "c"}, + []string{mysql.PrimaryKeyName}, + [][]int{{types.UnspecifiedLength}}, + "c", + true, }, } @@ -91,6 +128,7 @@ func (*testDBSuite) TestTable(c *C) { c.Assert(testCase.columns[i], Equals, column.Name.O) } + c.Assert(tableInfo.Indices, HasLen, len(testCase.indexs)) for j, index := range tableInfo.Indices { c.Assert(testCase.indexs[j], Equals, index.Name.O) for k, indexCol := range index.Columns {