Skip to content

Commit e3ce501

Browse files
committed
support tables with zero date when --allow-zero-in-date provided
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
1 parent addd7bf commit e3ce501

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

go/logic/applier.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +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 {
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 altered")
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+
if err != nil {
204230
return err
205231
}
206232
this.migrationContext.Log.Infof("Ghost table created")

0 commit comments

Comments
 (0)