-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix inspector column types #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dfc8aa2
5f15f8a
7e93451
ebba4f4
736696f
179a3c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,8 +173,7 @@ func (this *Inspector) inspectOriginalAndGhostTables() (err error) { | |
// This additional step looks at which columns are unsigned. We could have merged this within | ||
// the `getTableColumns()` function, but it's a later patch and introduces some complexity; I feel | ||
// comfortable in doing this as a separate step. | ||
this.applyColumnTypes(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, this.migrationContext.OriginalTableColumns, this.migrationContext.SharedColumns) | ||
this.applyColumnTypes(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &this.migrationContext.UniqueKey.Columns) | ||
this.applyColumnTypes(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, this.migrationContext.OriginalTableColumns, this.migrationContext.SharedColumns, &this.migrationContext.UniqueKey.Columns) | ||
this.applyColumnTypes(this.migrationContext.DatabaseName, this.migrationContext.GetGhostTableName(), this.migrationContext.GhostTableColumns, this.migrationContext.MappedSharedColumns) | ||
|
||
for i := range this.migrationContext.SharedColumns.Columns() { | ||
|
@@ -552,44 +551,35 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL | |
err := sqlutils.QueryRowsMap(this.db, query, func(m sqlutils.RowMap) error { | ||
columnName := m.GetString("COLUMN_NAME") | ||
columnType := m.GetString("COLUMN_TYPE") | ||
if strings.Contains(columnType, "unsigned") { | ||
for _, columnsList := range columnsLists { | ||
columnsList.SetUnsigned(columnName) | ||
for _, columnsList := range columnsLists { | ||
column := columnsList.GetColumn(columnName) | ||
if column == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The for loop was changed in order to prevent accessing a column that is not available in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code ignores columns that are not available in the columnsList and continues iterating over the next columns. |
||
continue | ||
} | ||
} | ||
if strings.Contains(columnType, "mediumint") { | ||
for _, columnsList := range columnsLists { | ||
columnsList.GetColumn(columnName).Type = sql.MediumIntColumnType | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code fails when |
||
|
||
if strings.Contains(columnType, "unsigned") { | ||
column.IsUnsigned = true | ||
} | ||
} | ||
if strings.Contains(columnType, "timestamp") { | ||
for _, columnsList := range columnsLists { | ||
columnsList.GetColumn(columnName).Type = sql.TimestampColumnType | ||
if strings.Contains(columnType, "mediumint") { | ||
column.Type = sql.MediumIntColumnType | ||
} | ||
} | ||
if strings.Contains(columnType, "datetime") { | ||
for _, columnsList := range columnsLists { | ||
columnsList.GetColumn(columnName).Type = sql.DateTimeColumnType | ||
if strings.Contains(columnType, "timestamp") { | ||
column.Type = sql.TimestampColumnType | ||
} | ||
} | ||
if strings.Contains(columnType, "json") { | ||
for _, columnsList := range columnsLists { | ||
columnsList.GetColumn(columnName).Type = sql.JSONColumnType | ||
if strings.Contains(columnType, "datetime") { | ||
column.Type = sql.DateTimeColumnType | ||
} | ||
} | ||
if strings.Contains(columnType, "float") { | ||
for _, columnsList := range columnsLists { | ||
columnsList.GetColumn(columnName).Type = sql.FloatColumnType | ||
if strings.Contains(columnType, "json") { | ||
column.Type = sql.JSONColumnType | ||
} | ||
} | ||
if strings.HasPrefix(columnType, "enum") { | ||
for _, columnsList := range columnsLists { | ||
columnsList.GetColumn(columnName).Type = sql.EnumColumnType | ||
if strings.Contains(columnType, "float") { | ||
column.Type = sql.FloatColumnType | ||
} | ||
} | ||
if charset := m.GetString("CHARACTER_SET_NAME"); charset != "" { | ||
for _, columnsList := range columnsLists { | ||
columnsList.SetCharset(columnName, charset) | ||
if strings.HasPrefix(columnType, "enum") { | ||
column.Type = sql.EnumColumnType | ||
} | ||
if charset := m.GetString("CHARACTER_SET_NAME"); charset != "" { | ||
column.Charset = charset | ||
} | ||
} | ||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a small improvement, instead of calling
applyColumnTypes
twice for the samedatabaseName
andtableName
, I've moved the&this.migrationContext.UniqueKey.Columns
to this call.