Skip to content

Commit 71a63c4

Browse files
committed
Fix string matching for PanicOnWarnings to correctly suppress warnings when renaming unique keys
Error message formats are different across mysql distributions and versions
1 parent 1ca8ffc commit 71a63c4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

go/logic/applier.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package logic
88
import (
99
gosql "database/sql"
1010
"fmt"
11+
"regexp"
1112
"strings"
1213
"sync/atomic"
1314
"time"
@@ -777,8 +778,10 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
777778
this.migrationContext.Log.Warningf("Failed to read SHOW WARNINGS row")
778779
continue
779780
}
780-
migrationUniqueKeySuffix := fmt.Sprintf("for key '%s.%s'", this.migrationContext.GetGhostTableName(), this.migrationContext.UniqueKey.NameInGhostTable)
781-
if strings.HasPrefix(message, "Duplicate entry") && strings.HasSuffix(message, migrationUniqueKeySuffix) {
781+
// Duplicate warnings are formatted differently across mysql versions, hence the optional table name prefix
782+
migrationUniqueKeyExpression := fmt.Sprintf("for key '(%s\\.)?%s'", this.migrationContext.GetGhostTableName(), this.migrationContext.UniqueKey.NameInGhostTable)
783+
matched, _ := regexp.MatchString(migrationUniqueKeyExpression, message)
784+
if strings.Contains(message, "Duplicate entry") && matched {
782785
continue
783786
}
784787
sqlWarnings = append(sqlWarnings, fmt.Sprintf("%s: %s (%d)", level, message, code))

0 commit comments

Comments
 (0)