Skip to content

Commit ef8cef4

Browse files
author
程飞
committed
fix: fetch the primary key when we are trying to compare differences row by row
1 parent 0f35a0d commit ef8cef4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

conf.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ func (c *config) checkAndFix() error {
134134
return fmt.Errorf("bad configuration item(%s) of the right table", "diff cols")
135135
}
136136
}
137+
contain := false
138+
for _, col := range c.DiffColumns {
139+
if col == c.PrimaryKey {
140+
contain = true
141+
}
142+
}
143+
if !contain {
144+
c.DiffColumns = append(c.DiffColumns, c.PrimaryKey)
145+
}
137146
maxKey := func(db *gorm.DB, table string) (int64, error) {
138147
id := int64(0)
139148
row := db.Raw(fmt.Sprintf("SELECT max(%s) FROM `%s`", c.PrimaryKey, table)).Row()

diff.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ func (d *differ) diff() (err error) {
181181
}
182182
res = append(res, row)
183183
}
184-
//spew.Dump(res)
185184
return res, err
186185
}
187186
var (

0 commit comments

Comments
 (0)