Skip to content

Commit

Permalink
sync-diff: turn off new collation (#597)
Browse files Browse the repository at this point in the history
close #596
  • Loading branch information
lance6716 authored Mar 2, 2022
1 parent 00998a9 commit b6d9cbe
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
5 changes: 5 additions & 0 deletions pkg/dbutil/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 44 additions & 6 deletions pkg/dbutil/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"},
Expand Down Expand Up @@ -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,
},
}

Expand All @@ -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 {
Expand Down

0 comments on commit b6d9cbe

Please sign in to comment.