fix data-integrity: timestamp convert to datetime scenario
This commit is contained in:
parent
fef83af378
commit
a07ddae80f
@ -181,7 +181,9 @@ func (this *Inspector) inspectOriginalAndGhostTables() (err error) {
|
||||
column := this.migrationContext.SharedColumns.Columns()[i]
|
||||
mappedColumn := this.migrationContext.MappedSharedColumns.Columns()[i]
|
||||
if column.Name == mappedColumn.Name && column.Type == sql.DateTimeColumnType && mappedColumn.Type == sql.TimestampColumnType {
|
||||
this.migrationContext.MappedSharedColumns.SetConvertDatetimeToTimestamp(column.Name, this.migrationContext.ApplierTimeZone)
|
||||
this.migrationContext.MappedSharedColumns.SetConvertDatetimeToTimestamp(column.Name, this.migrationContext.ApplierTimeZone, "+00:00")
|
||||
} else if column.Name == mappedColumn.Name && column.Type == sql.TimestampColumnType && mappedColumn.Type == sql.DateTimeColumnType {
|
||||
this.migrationContext.MappedSharedColumns.SetConvertDatetimeToTimestamp(column.Name, "+00:00", this.migrationContext.ApplierTimeZone)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ func buildColumnsPreparedValues(columns *ColumnList) []string {
|
||||
for i, column := range columns.Columns() {
|
||||
var token string
|
||||
if column.timezoneConversion != nil {
|
||||
token = fmt.Sprintf("convert_tz(?, '%s', '%s')", column.timezoneConversion.ToTimezone, "+00:00")
|
||||
token = fmt.Sprintf("convert_tz(?, '%s', '%s')", column.timezoneConversion.FromTimezone, column.timezoneConversion.ToTimezone)
|
||||
} else if column.Type == JSONColumnType {
|
||||
token = "convert(? using utf8mb4)"
|
||||
} else {
|
||||
@ -107,7 +107,7 @@ func BuildSetPreparedClause(columns *ColumnList) (result string, err error) {
|
||||
for _, column := range columns.Columns() {
|
||||
var setToken string
|
||||
if column.timezoneConversion != nil {
|
||||
setToken = fmt.Sprintf("%s=convert_tz(?, '%s', '%s')", EscapeName(column.Name), column.timezoneConversion.ToTimezone, "+00:00")
|
||||
setToken = fmt.Sprintf("%s=convert_tz(?, '%s', '%s')", EscapeName(column.Name), column.timezoneConversion.FromTimezone, column.timezoneConversion.ToTimezone)
|
||||
} else if column.Type == JSONColumnType {
|
||||
setToken = fmt.Sprintf("%s=convert(? using utf8mb4)", EscapeName(column.Name))
|
||||
} else {
|
||||
|
@ -29,6 +29,7 @@ const (
|
||||
const maxMediumintUnsigned int32 = 16777215
|
||||
|
||||
type TimezoneConversion struct {
|
||||
FromTimezone string
|
||||
ToTimezone string
|
||||
}
|
||||
|
||||
@ -190,8 +191,12 @@ func (this *ColumnList) GetColumnType(columnName string) ColumnType {
|
||||
return this.GetColumn(columnName).Type
|
||||
}
|
||||
|
||||
func (this *ColumnList) SetConvertDatetimeToTimestamp(columnName string, toTimezone string) {
|
||||
this.GetColumn(columnName).timezoneConversion = &TimezoneConversion{ToTimezone: toTimezone}
|
||||
func (this *ColumnList) SetConvertDatetimeToTimestamp(columnName string, fromTimezone, toTimezone string) {
|
||||
this.GetColumn(columnName).timezoneConversion = &TimezoneConversion{FromTimezone: fromTimezone, ToTimezone: toTimezone}
|
||||
}
|
||||
|
||||
func (this *ColumnList) SetConvertTimestampToDatetime(columnName string, fromTimezone, toTimezone string) {
|
||||
this.GetColumn(columnName).timezoneConversion = &TimezoneConversion{FromTimezone: fromTimezone, ToTimezone: toTimezone}
|
||||
}
|
||||
|
||||
func (this *ColumnList) HasTimezoneConversion(columnName string) bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user