Merge pull request #661 from esnunes/fix-inspector-column-types

Fix inspector column types
This commit is contained in:
Shlomi Noach 2018-12-16 11:14:27 +02:00 committed by GitHub
commit 17233fc6b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 // 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 // the `getTableColumns()` function, but it's a later patch and introduces some complexity; I feel
// comfortable in doing this as a separate step. // 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.OriginalTableColumns, this.migrationContext.SharedColumns, &this.migrationContext.UniqueKey.Columns)
this.applyColumnTypes(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &this.migrationContext.UniqueKey.Columns)
this.applyColumnTypes(this.migrationContext.DatabaseName, this.migrationContext.GetGhostTableName(), this.migrationContext.GhostTableColumns, this.migrationContext.MappedSharedColumns) this.applyColumnTypes(this.migrationContext.DatabaseName, this.migrationContext.GetGhostTableName(), this.migrationContext.GhostTableColumns, this.migrationContext.MappedSharedColumns)
for i := range this.migrationContext.SharedColumns.Columns() { 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 { err := sqlutils.QueryRowsMap(this.db, query, func(m sqlutils.RowMap) error {
columnName := m.GetString("COLUMN_NAME") columnName := m.GetString("COLUMN_NAME")
columnType := m.GetString("COLUMN_TYPE") columnType := m.GetString("COLUMN_TYPE")
if strings.Contains(columnType, "unsigned") {
for _, columnsList := range columnsLists { for _, columnsList := range columnsLists {
columnsList.SetUnsigned(columnName) column := columnsList.GetColumn(columnName)
if column == nil {
continue
} }
if strings.Contains(columnType, "unsigned") {
column.IsUnsigned = true
} }
if strings.Contains(columnType, "mediumint") { if strings.Contains(columnType, "mediumint") {
for _, columnsList := range columnsLists { column.Type = sql.MediumIntColumnType
columnsList.GetColumn(columnName).Type = sql.MediumIntColumnType
}
} }
if strings.Contains(columnType, "timestamp") { if strings.Contains(columnType, "timestamp") {
for _, columnsList := range columnsLists { column.Type = sql.TimestampColumnType
columnsList.GetColumn(columnName).Type = sql.TimestampColumnType
}
} }
if strings.Contains(columnType, "datetime") { if strings.Contains(columnType, "datetime") {
for _, columnsList := range columnsLists { column.Type = sql.DateTimeColumnType
columnsList.GetColumn(columnName).Type = sql.DateTimeColumnType
}
} }
if strings.Contains(columnType, "json") { if strings.Contains(columnType, "json") {
for _, columnsList := range columnsLists { column.Type = sql.JSONColumnType
columnsList.GetColumn(columnName).Type = sql.JSONColumnType
}
} }
if strings.Contains(columnType, "float") { if strings.Contains(columnType, "float") {
for _, columnsList := range columnsLists { column.Type = sql.FloatColumnType
columnsList.GetColumn(columnName).Type = sql.FloatColumnType
}
} }
if strings.HasPrefix(columnType, "enum") { if strings.HasPrefix(columnType, "enum") {
for _, columnsList := range columnsLists { column.Type = sql.EnumColumnType
columnsList.GetColumn(columnName).Type = sql.EnumColumnType
}
} }
if charset := m.GetString("CHARACTER_SET_NAME"); charset != "" { if charset := m.GetString("CHARACTER_SET_NAME"); charset != "" {
for _, columnsList := range columnsLists { column.Charset = charset
columnsList.SetCharset(columnName, charset)
} }
} }
return nil return nil