Skip to content

Commit

Permalink
defer restoring original collation
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed May 22, 2024
1 parent 38bc519 commit e1c2b97
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion go/vt/schemadiff/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,15 @@ func (c *ColumnDefinitionEntity) ColumnDiff(
) (*ModifyColumnDiff, error) {
if c.IsTextual() || other.IsTextual() {
// We will now denormalize the columns charset & collate as needed (if empty, populate from table.)
// This column definition
if c.columnDefinition.Type.Charset.Name != "" && c.columnDefinition.Type.Options.Collate == "" {
collation := env.CollationEnv().DefaultCollationForCharset(c.columnDefinition.Type.Charset.Name)
if collation == collations.Unknown {
return nil, &UnknownColumnCharsetCollationError{Column: c.columnDefinition.Name.String(), Charset: t1cc.charset}
}
defer func() {
c.columnDefinition.Type.Options.Collate = ""
}()
c.columnDefinition.Type.Options.Collate = env.CollationEnv().LookupName(collation)
}
if c.columnDefinition.Type.Charset.Name == "" && c.columnDefinition.Type.Options.Collate != "" {
Expand Down Expand Up @@ -143,11 +147,15 @@ func (c *ColumnDefinitionEntity) ColumnDiff(
c.columnDefinition.Type.Options.Collate = env.CollationEnv().LookupName(collation)
}
}
// other column definition
if other.columnDefinition.Type.Charset.Name != "" && other.columnDefinition.Type.Options.Collate == "" {
collation := env.CollationEnv().DefaultCollationForCharset(other.columnDefinition.Type.Charset.Name)
if collation == collations.Unknown {
return nil, &UnknownColumnCharsetCollationError{Column: other.columnDefinition.Name.String(), Charset: t1cc.charset}
return nil, &UnknownColumnCharsetCollationError{Column: other.columnDefinition.Name.String(), Charset: t2cc.charset}
}
defer func() {
other.columnDefinition.Type.Options.Collate = ""
}()
other.columnDefinition.Type.Options.Collate = env.CollationEnv().LookupName(collation)
}
if other.columnDefinition.Type.Charset.Name == "" && other.columnDefinition.Type.Options.Collate != "" {
Expand Down

0 comments on commit e1c2b97

Please sign in to comment.