Skip to content

Commit

Permalink
fix: fetch the primary key when we are trying to compare differences …
Browse files Browse the repository at this point in the history
…row by row
  • Loading branch information
程飞 committed Nov 19, 2022
1 parent 0f35a0d commit ef8cef4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 9 additions & 0 deletions conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ func (c *config) checkAndFix() error {
return fmt.Errorf("bad configuration item(%s) of the right table", "diff cols")
}
}
contain := false
for _, col := range c.DiffColumns {
if col == c.PrimaryKey {
contain = true
}
}
if !contain {
c.DiffColumns = append(c.DiffColumns, c.PrimaryKey)
}
maxKey := func(db *gorm.DB, table string) (int64, error) {
id := int64(0)
row := db.Raw(fmt.Sprintf("SELECT max(%s) FROM `%s`", c.PrimaryKey, table)).Row()
Expand Down
1 change: 0 additions & 1 deletion diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ func (d *differ) diff() (err error) {
}
res = append(res, row)
}
//spew.Dump(res)
return res, err
}
var (
Expand Down

0 comments on commit ef8cef4

Please sign in to comment.