chore: move setOptimizerSwitch to InitDBConnections

This commit is contained in:
Cyril Levis 2022-12-28 10:07:40 +01:00
parent eec7aa5fee
commit 4fa7c865ad
No known key found for this signature in database
GPG Key ID: 6DB88737C11F5A48

View File

@ -49,12 +49,12 @@ func newDmlBuildResultError(err error) *dmlBuildResult {
} }
} }
func (this *Applier) setOptimizerSwitch(tx *gosql.Tx) error { func (this *Applier) setOptimizerSwitch() error {
if this.migrationContext.OptimizerSwitch == "" { if this.migrationContext.OptimizerSwitch == "" {
return nil return nil
} }
optimizerString := fmt.Sprintf("SET SESSION optimizer_switch=%q", this.migrationContext.OptimizerSwitch) optimizerString := fmt.Sprintf("SET SESSION optimizer_switch=%q", this.migrationContext.OptimizerSwitch)
_, err := tx.Query(optimizerString) _, err := this.db.Query(optimizerString)
return err return err
} }
@ -109,6 +109,10 @@ func (this *Applier) InitDBConnections() (err error) {
this.connectionConfig.ImpliedKey = impliedKey this.connectionConfig.ImpliedKey = impliedKey
} }
} }
err = this.setOptimizerSwitch()
if err != nil {
return err
}
if err := this.readTableColumns(); err != nil { if err := this.readTableColumns(); err != nil {
return err return err
} }
@ -556,11 +560,6 @@ func (this *Applier) ReadMigrationRangeValues() error {
} }
defer tx.Rollback() defer tx.Rollback()
err = this.setOptimizerSwitch(tx)
if err != nil {
return err
}
if err := this.readMigrationMinValues(tx, this.migrationContext.UniqueKey); err != nil { if err := this.readMigrationMinValues(tx, this.migrationContext.UniqueKey); err != nil {
return err return err
} }