Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

restore: fix alter auto increment id for no-primary-key table #139

Merged
merged 3 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/restore/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ func (db *DB) CreateTable(ctx context.Context, table *utils.Table) error {
zap.Error(err))
return errors.Trace(err)
}
alterAutoIncIDSQL := fmt.Sprintf("alter table %s auto_increment = %d", schema.Name, schema.AutoIncID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need EncloseName?

_, err = db.se.Execute(ctx, alterAutoIncIDSQL)
if err != nil {
log.Error("alter AutoIncID failed",
zap.String("SQL", alterAutoIncIDSQL),
zap.Stringer("db", table.Db.Name),
zap.Stringer("table", table.Schema.Name),
zap.Error(err))
return errors.Trace(err)
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/restore/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *testRestoreSchemaSuite) TestRestoreAutoIncID(c *C) {
tk.MustExec("drop table if exists t;")
// Test SQL Mode
tk.MustExec("create table t (" +
"a int not null auto_increment," +
"a int not null," +
"time timestamp not null default '0000-00-00 00:00:00'," +
"primary key (a));",
)
Expand Down