File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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" )
You can’t perform that action at this time.
0 commit comments