This commit is contained in:
cenkore 2023-05-27 19:48:31 +00:00 committed by GitHub
commit d6a3ddd9b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 6 deletions

View File

@ -184,7 +184,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.SetConvertTimestampToDatetime(column.Name, "+00:00", this.migrationContext.ApplierTimeZone)
}
if column.Name == mappedColumn.Name && column.Type == sql.EnumColumnType && mappedColumn.Charset != "" {
this.migrationContext.MappedSharedColumns.SetEnumToTextConversion(column.Name)

View File

@ -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.enumToTextConversion {
token = fmt.Sprintf("ELT(?, %s)", column.EnumValues)
} else if column.Type == JSONColumnType {
@ -109,7 +109,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.enumToTextConversion {
setToken = fmt.Sprintf("%s=ELT(?, %s)", EscapeName(column.Name), column.EnumValues)
} else if column.Type == JSONColumnType {

View File

@ -29,7 +29,8 @@ const (
const maxMediumintUnsigned int32 = 16777215
type TimezoneConversion struct {
ToTimezone string
FromTimezone string
ToTimezone string
}
type CharacterSetConversion struct {
@ -201,8 +202,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 {

View File

@ -0,0 +1,44 @@
drop table if exists gh_ost_test;
create table gh_ost_test (
id int auto_increment,
i int not null,
ts0 timestamp default current_timestamp,
ts1 timestamp default current_timestamp,
dt2 datetime,
t timestamp default current_timestamp,
updated tinyint unsigned default 0,
primary key(id),
key i_idx(i)
) auto_increment=1;
drop event if exists gh_ost_test;
delimiter ;;
create event gh_ost_test
on schedule every 1 second
starts current_timestamp
ends current_timestamp + interval 60 second
on completion not preserve
enable
do
begin
insert into gh_ost_test values (null, 7, null, now(), now(), '2010-10-20 10:20:30', 0);
insert into gh_ost_test values (null, 11, null, now(), now(), '2010-10-20 10:20:30', 0);
update gh_ost_test set ts2=now() + interval 1 minute, updated = 1 where i = 11 order by id desc limit 1;
set session time_zone='system';
insert into gh_ost_test values (null, 13, null, now(), now(), '2010-10-20 10:20:30', 0);
update gh_ost_test set ts2=now() + interval 1 minute, updated = 1 where i = 13 order by id desc limit 1;
set session time_zone='+00:00';
insert into gh_ost_test values (null, 17, null, now(), now(), '2010-10-20 10:20:30', 0);
update gh_ost_test set ts2=now() + interval 1 minute, updated = 1 where i = 17 order by id desc limit 1;
set session time_zone='-03:00';
insert into gh_ost_test values (null, 19, null, now(), now(), '2010-10-20 10:20:30', 0);
update gh_ost_test set ts2=now() + interval 1 minute, updated = 1 where i = 19 order by id desc limit 1;
set session time_zone='+05:00';
insert into gh_ost_test values (null, 23, null, now(), now(), '2010-10-20 10:20:30', 0);
update gh_ost_test set ts2=now() + interval 1 minute, updated = 1 where i = 23 order by id desc limit 1;
end ;;

View File

@ -0,0 +1 @@
--alter="change column t t datetime not null"

View File

@ -0,0 +1 @@
(5.5)