Skip to content

Commit

Permalink
fix failed to extract PK error
Browse files Browse the repository at this point in the history
  • Loading branch information
morgo committed Jul 24, 2024
1 parent 255d089 commit 79e61cd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
20 changes: 18 additions & 2 deletions pkg/migration/cutover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestCutOver(t *testing.T) {
assert.Equal(t, 0, db.Stats().InUse) // no connections in use.

t1 := table.NewTableInfo(db, "test", "cutovert1")
assert.NoError(t, t1.SetInfo(context.Background())) // required to extract PK.
t1new := table.NewTableInfo(db, "test", "_cutovert1_new")
t1old := "_cutovert1_old"
logger := logrus.New()
Expand Down Expand Up @@ -100,6 +101,7 @@ func TestMDLLockFails(t *testing.T) {
assert.NoError(t, err)

t1 := table.NewTableInfo(db, "test", "mdllocks")
assert.NoError(t, t1.SetInfo(context.Background())) // required to extract PK.
t1new := table.NewTableInfo(db, "test", "_mdllocks_new")
t1old := "test_old"
logger := logrus.New()
Expand Down Expand Up @@ -136,11 +138,25 @@ func TestInvalidOptions(t *testing.T) {
assert.NoError(t, err)
logger := logrus.New()

testutils.RunSQL(t, `DROP TABLE IF EXISTS invalid_t1, _invalid_t1_new`)
tbl := `CREATE TABLE invalid_t1 (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
PRIMARY KEY (id)
)`
testutils.RunSQL(t, tbl)
tbl = `CREATE TABLE _invalid_t1_new (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
PRIMARY KEY (id)
)`
testutils.RunSQL(t, tbl)
// Invalid options
_, err = NewCutOver(db, nil, nil, "", nil, dbconn.NewDBConfig(), logger)
assert.Error(t, err)
t1 := table.NewTableInfo(db, "test", "t1")
t1new := table.NewTableInfo(db, "test", "t1_new")
t1 := table.NewTableInfo(db, "test", "invalid_t1")
assert.NoError(t, t1.SetInfo(context.Background())) // required to extract PK.
t1new := table.NewTableInfo(db, "test", "_invalid_t1_new")
t1old := "test_old"
cfg, err := mysql.ParseDSN(testutils.DSN())
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/migration/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestRenameInMySQL80(t *testing.T) {
migration.Database = cfg.DBName
migration.Threads = 16
migration.Checksum = true
migration.Table = "t1"
migration.Table = "renamet1"
migration.Alter = "CHANGE name nameNew varchar(255) not null"

err = migration.Run()
Expand Down
3 changes: 2 additions & 1 deletion pkg/repl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ func (c *Client) startCanal() {
// but since canal is now closed we can safely return
return
}
c.logger.Errorf("canal has failed. error: %v", err)

c.logger.Errorf("canal has failed. error: %v, table: %s", err, c.table.TableName)
panic("canal has failed")
}
}
Expand Down

0 comments on commit 79e61cd

Please sign in to comment.