@@ -899,6 +899,25 @@ func (this *Applier) ShowStatusVariable(variableName string) (result int64, err
899899 return result , nil
900900}
901901
902+ func (this * Applier ) validateUpdateDoesNotModifyMigrationUniqueKeyColumns (dmlEvent * binlog.BinlogDMLEvent ) error {
903+ // log.Debugf("............ UPDATE")
904+ // log.Debugf("............ UPDATE: %+v", this.migrationContext.UniqueKey.Columns.String())
905+ // log.Debugf("............ UPDATE: %+v", dmlEvent.WhereColumnValues.String())
906+ // log.Debugf("............ UPDATE: %+v", dmlEvent.NewColumnValues.String())
907+ for _ , column := range this .migrationContext .UniqueKey .Columns .Columns () {
908+ tableOrdinal := this .migrationContext .OriginalTableColumns .Ordinals [column .Name ]
909+ whereColumnValue := dmlEvent .WhereColumnValues .AbstractValues ()[tableOrdinal ]
910+ newColumnValue := dmlEvent .NewColumnValues .AbstractValues ()[tableOrdinal ]
911+ // log.Debugf("............ UPDATE: old value= %+v", whereColumnValue)
912+ // log.Debugf("............ UPDATE: new value= %+v", newColumnValue)
913+ // log.Debugf("............ UPDATE: equals? %+v", newColumnValue == whereColumnValue)
914+ if newColumnValue != whereColumnValue {
915+ return log .Errorf ("gh-ost detected an UPDATE to a unique key column this migration is iterating on. Such update is not supported. Column is %s" , column .Name )
916+ }
917+ }
918+ return nil
919+ }
920+
902921// buildDMLEventQuery creates a query to operate on the ghost table, based on an intercepted binlog
903922// event entry on the original table.
904923func (this * Applier ) buildDMLEventQuery (dmlEvent * binlog.BinlogDMLEvent ) (query string , args []interface {}, rowsDelta int64 , err error ) {
@@ -915,6 +934,9 @@ func (this *Applier) buildDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) (query
915934 }
916935 case binlog .UpdateDML :
917936 {
937+ if err := this .validateUpdateDoesNotModifyMigrationUniqueKeyColumns (dmlEvent ); err != nil {
938+ return query , args , rowsDelta , err
939+ }
918940 query , sharedArgs , uniqueKeyArgs , err := sql .BuildDMLUpdateQuery (dmlEvent .DatabaseName , this .migrationContext .GetGhostTableName (), this .migrationContext .OriginalTableColumns , this .migrationContext .SharedColumns , this .migrationContext .MappedSharedColumns , & this .migrationContext .UniqueKey .Columns , dmlEvent .NewColumnValues .AbstractValues (), dmlEvent .WhereColumnValues .AbstractValues ())
919941 args = append (args , sharedArgs ... )
920942 args = append (args , uniqueKeyArgs ... )
0 commit comments