Skip to content

Commit

Permalink
ddl: fix db charset modification panic in uppercase schema
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Aug 19, 2020
1 parent a2e2ce6 commit 7669c32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,16 @@ func (s *testIntegrationSuite5) TestChangingDBCharset(c *C) {
verifyDBCharsetAndCollate("alterdb2", "utf8mb4", "utf8mb4_general_ci")
}

func (s *testIntegrationSuite5) TestChangingUppercaseDBCharset(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("drop database if exists TEST_UPPERCASE_DB_CHARSET;")
tk.MustExec("create database TEST_UPPERCASE_DB_CHARSET;")
tk.MustExec("use TEST_UPPERCASE_DB_CHARSET;")

tk.MustExec("alter database TEST_UPPERCASE_DB_CHARSET default character set utf8;")
tk.MustExec("alter database TEST_UPPERCASE_DB_CHARSET default character set utf8mb4;")
}

func (s *testIntegrationSuite4) TestDropAutoIncrementIndex(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create database if not exists test")
Expand Down
3 changes: 2 additions & 1 deletion infoschema/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (b *Builder) applyModifySchemaCharsetAndCollate(m *meta.Meta, diff *model.S
fmt.Sprintf("(Schema ID %d)", diff.SchemaID),
)
}
newDbInfo := b.copySchemaTables(di.Name.O)
newDbInfo := b.copySchemaTables(di.Name.L)
newDbInfo.Charset = di.Charset
newDbInfo.Collate = di.Collate
return nil
Expand Down Expand Up @@ -381,6 +381,7 @@ func (b *Builder) copySchemasMap(oldIS *infoSchema) {

// copySchemaTables creates a new schemaTables instance when a table in the database has changed.
// It also does modifications on the new one because old schemaTables must be read-only.
// Note: please make sure the dbName is in lowercase.
func (b *Builder) copySchemaTables(dbName string) *model.DBInfo {
oldSchemaTables := b.is.schemaMap[dbName]
newSchemaTables := &schemaTables{
Expand Down

0 comments on commit 7669c32

Please sign in to comment.