Skip to content

Commit 3437cf4

Browse files
author
Shlomi Noach
committed
Validating shared key column types
1 parent 933901e commit 3437cf4

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

go/logic/inspect.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,33 @@ func (this *Inspector) inspectOriginalAndGhostTables() (err error) {
121121
if err != nil {
122122
return err
123123
}
124-
if len(sharedUniqueKeys) == 0 {
124+
for i, sharedUniqueKey := range sharedUniqueKeys {
125+
this.applyColumnTypes(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &sharedUniqueKey.Columns)
126+
uniqueKeyIsValid := true
127+
for _, column := range sharedUniqueKey.Columns.Columns() {
128+
switch column.Type {
129+
case sql.FloatColumnType:
130+
{
131+
log.Warning("Will not use %+v as shared key due to FLOAT data type", sharedUniqueKey.Name)
132+
uniqueKeyIsValid = false
133+
}
134+
case sql.JSONColumnType:
135+
{
136+
// Noteworthy that at this time MySQL does not allow JSON indexing anyhow, but this code
137+
// will remain in place to potentially handle the future case where JSON is supported in indexes.
138+
log.Warning("Will not use %+v as shared key due to JSON data type", sharedUniqueKey.Name)
139+
uniqueKeyIsValid = false
140+
}
141+
}
142+
}
143+
if uniqueKeyIsValid {
144+
this.migrationContext.UniqueKey = sharedUniqueKeys[i]
145+
break
146+
}
147+
}
148+
if this.migrationContext.UniqueKey == nil {
125149
return fmt.Errorf("No shared unique key can be found after ALTER! Bailing out")
126150
}
127-
this.migrationContext.UniqueKey = sharedUniqueKeys[0]
128151
log.Infof("Chosen shared unique key is %s", this.migrationContext.UniqueKey.Name)
129152
if this.migrationContext.UniqueKey.HasNullable {
130153
if this.migrationContext.NullableUniqueKeyAllowed {
@@ -550,6 +573,11 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL
550573
columnsList.GetColumn(columnName).Type = sql.JSONColumnType
551574
}
552575
}
576+
if strings.Contains(columnType, "float") {
577+
for _, columnsList := range columnsLists {
578+
columnsList.GetColumn(columnName).Type = sql.FloatColumnType
579+
}
580+
}
553581
if strings.HasPrefix(columnType, "enum") {
554582
for _, columnsList := range columnsLists {
555583
columnsList.GetColumn(columnName).Type = sql.EnumColumnType

go/sql/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
EnumColumnType = iota
2222
MediumIntColumnType = iota
2323
JSONColumnType = iota
24+
FloatColumnType = iota
2425
)
2526

2627
const maxMediumintUnsigned int32 = 16777215

0 commit comments

Comments
 (0)