Skip to content

Commit 7d5749b

Browse files
committed
add --skip-strict-mode option
1 parent a8fae98 commit 7d5749b

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

doc/command-line-flags.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ See also: [`concurrent-migrations`](cheatsheet.md#concurrent-migrations) on the
173173

174174
By default `gh-ost` verifies no foreign keys exist on the migrated table. On servers with large number of tables this check can take a long time. If you're absolutely certain no foreign keys exist (table does not reference other table nor is referenced by other tables) and wish to save the check time, provide with `--skip-foreign-key-checks`.
175175

176+
### skip-strict-mode
177+
178+
By default `gh-ost` enforces STRICT_ALL_TABLES sql_mode as a safety measure. In some cases this changes the behaviour of other modes (namely ERROR_FOR_DIVISION_BY_ZERO, NO_ZERO_DATE, and NO_ZERO_IN_DATE) which may lead to errors during migration. Use `--skip-strict-mode` to explicitly tell `gh-ost` not to enforce this. **Danger** This may have some unexpected disastrous side effects.
179+
176180
### skip-renamed-columns
177181

178182
See [`approve-renamed-columns`](#approve-renamed-columns)

go/base/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type MigrationContext struct {
8686
SwitchToRowBinlogFormat bool
8787
AssumeRBR bool
8888
SkipForeignKeyChecks bool
89+
SkipStrictMode bool
8990
NullableUniqueKeyAllowed bool
9091
ApproveRenamedColumns bool
9192
SkipRenamedColumns bool

go/cmd/gh-ost/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func main() {
7272
flag.BoolVar(&migrationContext.IsTungsten, "tungsten", false, "explicitly let gh-ost know that you are running on a tungsten-replication based topology (you are likely to also provide --assume-master-host)")
7373
flag.BoolVar(&migrationContext.DiscardForeignKeys, "discard-foreign-keys", false, "DANGER! This flag will migrate a table that has foreign keys and will NOT create foreign keys on the ghost table, thus your altered table will have NO foreign keys. This is useful for intentional dropping of foreign keys")
7474
flag.BoolVar(&migrationContext.SkipForeignKeyChecks, "skip-foreign-key-checks", false, "set to 'true' when you know for certain there are no foreign keys on your table, and wish to skip the time it takes for gh-ost to verify that")
75+
flag.BoolVar(&migrationContext.SkipStrictMode, "skip-strict-mode", false, "explicitly tell gh-ost binlog applier not to enforce strict sql mode")
7576
flag.BoolVar(&migrationContext.AliyunRDS, "aliyun-rds", false, "set to 'true' when you execute on Aliyun RDS.")
7677
flag.BoolVar(&migrationContext.GoogleCloudPlatform, "gcp", false, "set to 'true' when you execute on a 1st generation Google Cloud Platform (GCP).")
7778

go/logic/applier.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
482482
return nil, err
483483
}
484484
defer tx.Rollback()
485-
sessionQuery := fmt.Sprintf(`SET
486-
SESSION time_zone = '%s',
487-
sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES')
488-
`, this.migrationContext.ApplierTimeZone)
485+
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.migrationContext.ApplierTimeZone)
486+
if !this.migrationContext.SkipStrictMode {
487+
sessionQuery += ", sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES')"
488+
}
489489
if _, err := tx.Exec(sessionQuery); err != nil {
490490
return nil, err
491491
}
@@ -1005,10 +1005,10 @@ func (this *Applier) ApplyDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) error {
10051005
tx.Rollback()
10061006
return err
10071007
}
1008-
sessionQuery := `SET
1009-
SESSION time_zone = '+00:00',
1010-
sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES')
1011-
`
1008+
sessionQuery := fmt.Sprintf("SET SESSION time_zone = '+00:00'")
1009+
if !this.migrationContext.SkipStrictMode {
1010+
sessionQuery += ", sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES')"
1011+
}
10121012
if _, err := tx.Exec(sessionQuery); err != nil {
10131013
return rollback(err)
10141014
}
@@ -1050,10 +1050,10 @@ func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent))
10501050
return err
10511051
}
10521052

1053-
sessionQuery := `SET
1054-
SESSION time_zone = '+00:00',
1055-
sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES')
1056-
`
1053+
sessionQuery := "SET SESSION time_zone = '+00:00'"
1054+
if !this.migrationContext.SkipStrictMode {
1055+
sessionQuery += ", sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES')"
1056+
}
10571057
if _, err := tx.Exec(sessionQuery); err != nil {
10581058
return rollback(err)
10591059
}

0 commit comments

Comments
 (0)