Skip to content

Commit ded0f91

Browse files
authored
Merge pull request #32 from openark/existing-date-with-zero
Support tables with existing zero dates
2 parents addd7bf + 0ea04fb commit ded0f91

File tree

9 files changed

+75
-7
lines changed

9 files changed

+75
-7
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function build {
1818
GOOS=$3
1919
GOARCH=$4
2020

21-
if ! go version | egrep -q 'go(1\.1[56])' ; then
21+
if ! go version | egrep -q 'go(1\.1[567])' ; then
2222
echo "go version must be 1.15 or above"
2323
exit 1
2424
fi

go/logic/applier.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,33 @@ func (this *Applier) CreateGhostTable() error {
200200
sql.EscapeName(this.migrationContext.DatabaseName),
201201
sql.EscapeName(this.migrationContext.GetGhostTableName()),
202202
)
203-
if _, err := sqlutils.ExecNoPrepare(this.db, query); err != nil {
204-
return err
205-
}
206-
this.migrationContext.Log.Infof("Ghost table created")
207-
return nil
203+
204+
err := func() error {
205+
tx, err := this.db.Begin()
206+
if err != nil {
207+
return err
208+
}
209+
defer tx.Rollback()
210+
211+
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.migrationContext.ApplierTimeZone)
212+
sessionQuery = fmt.Sprintf("%s, %s", sessionQuery, this.generateSqlModeQuery())
213+
214+
if _, err := tx.Exec(sessionQuery); err != nil {
215+
return err
216+
}
217+
if _, err := tx.Exec(query); err != nil {
218+
return err
219+
}
220+
this.migrationContext.Log.Infof("Ghost table created")
221+
if err := tx.Commit(); err != nil {
222+
// Neither SET SESSION nor ALTER are really transactional, so strictly speaking
223+
// there's no need to commit; but let's do this the legit way anyway.
224+
return err
225+
}
226+
return nil
227+
}()
228+
229+
return err
208230
}
209231

210232
// AlterGhost applies `alter` statement on ghost table
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
set session sql_mode='';
2+
drop table if exists gh_ost_test;
3+
create table gh_ost_test (
4+
id int unsigned auto_increment,
5+
i int not null,
6+
dt datetime not null default '1970-00-00 00:00:00',
7+
primary key(id)
8+
) auto_increment=1;
9+
10+
drop event if exists gh_ost_test;
11+
delimiter ;;
12+
create event gh_ost_test
13+
on schedule every 1 second
14+
starts current_timestamp
15+
ends current_timestamp + interval 60 second
16+
on completion not preserve
17+
enable
18+
do
19+
begin
20+
insert into gh_ost_test values (null, 7, '2010-10-20 10:20:30');
21+
end ;;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--allow-zero-in-date --alter="engine=innodb"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
set session sql_mode='';
2+
drop table if exists gh_ost_test;
3+
create table gh_ost_test (
4+
id int unsigned auto_increment,
5+
i int not null,
6+
dt datetime not null default '1970-00-00 00:00:00',
7+
primary key(id)
8+
) auto_increment=1;
9+
10+
drop event if exists gh_ost_test;
11+
delimiter ;;
12+
create event gh_ost_test
13+
on schedule every 1 second
14+
starts current_timestamp
15+
ends current_timestamp + interval 60 second
16+
on completion not preserve
17+
enable
18+
do
19+
begin
20+
insert into gh_ost_test values (null, 7, '2010-10-20 10:20:30');
21+
end ;;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Invalid default value for 'dt'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--alter="engine=innodb"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(5.5|5.6)

script/ensure-go-installed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
PREFERRED_GO_VERSION=go1.16.4
4-
SUPPORTED_GO_VERSIONS='go1.1[56]'
4+
SUPPORTED_GO_VERSIONS='go1.1[567]'
55

66
GO_PKG_DARWIN=${PREFERRED_GO_VERSION}.darwin-amd64.pkg
77
GO_PKG_DARWIN_SHA=0f215de06019a054a3da46a0722989986c956d719c7a0a8fc38a5f3c216d6f6b

0 commit comments

Comments
 (0)