Skip to content

Commit

Permalink
restore: fix error lost in create schema (pingcap#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer authored Dec 23, 2020
1 parent c3fc041 commit 8510040
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lightning/restore/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"

"github.com/pingcap/tidb-lightning/lightning/glue"

. "github.com/pingcap/tidb-lightning/lightning/checkpoints"
Expand Down Expand Up @@ -154,6 +155,7 @@ func InitSchema(ctx context.Context, g glue.Glue, database string, tablesSchema

task := logger.Begin(zap.InfoLevel, "create tables")
var sqlCreateStmts []string
loopCreate:
for tbl, sqlCreateTable := range tablesSchema {
task.Debug("create table", zap.String("schema", sqlCreateTable))

Expand All @@ -171,7 +173,7 @@ func InitSchema(ctx context.Context, g glue.Glue, database string, tablesSchema
logger.With(zap.String("table", common.UniqueTable(database, tbl))),
)
if err != nil {
break
break loopCreate
}
}
}
Expand Down
27 changes: 26 additions & 1 deletion lightning/restore/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
tmysql "github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb-lightning/lightning/glue"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/util/mock"

"github.com/pingcap/tidb-lightning/lightning/glue"

"github.com/pingcap/tidb-lightning/lightning/checkpoints"
"github.com/pingcap/tidb-lightning/lightning/mydump"
)
Expand Down Expand Up @@ -224,6 +225,30 @@ func (s *tidbSuite) TestInitSchemaSyntaxError(c *C) {
c.Assert(err, NotNil)
}

func (s *tidbSuite) TestInitSchemaErrorLost(c *C) {
ctx := context.Background()

s.mockDB.
ExpectExec("CREATE DATABASE IF NOT EXISTS `db`").
WillReturnResult(sqlmock.NewResult(1, 1))

s.mockDB.
ExpectExec("CREATE TABLE IF NOT EXISTS.*").
WillReturnError(&mysql.MySQLError{
Number: tmysql.ErrTooBigFieldlength,
Message: "Column length too big",
})

s.mockDB.
ExpectClose()

err := InitSchema(ctx, s.tiGlue, "db", map[string]string{
"t1": "create table `t1` (a int);",
"t2": "create table t2 (a int primary key, b varchar(200));",
})
c.Assert(err, ErrorMatches, ".*Column length too big.*")
}

func (s *tidbSuite) TestInitSchemaUnsupportedSchemaError(c *C) {
ctx := context.Background()

Expand Down

0 comments on commit 8510040

Please sign in to comment.