You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// remove possible duplicated records in table user_badge
32
+
typeresultstruct {
33
+
UserIDint64
34
+
BadgeIDint64
35
+
Cntint
36
+
}
37
+
varresults []result
38
+
iferr:=x.Select("user_id, badge_id, count(*) as cnt").
39
+
Table("user_badge").
40
+
GroupBy("user_id, badge_id").
41
+
Having("count(*) > 1").
42
+
Find(&results); err!=nil {
43
+
returnerr
44
+
}
45
+
for_, r:=rangeresults {
46
+
ifx.Dialect().URI().DBType==schemas.MSSQL {
47
+
if_, err:=x.Exec(fmt.Sprintf("delete from user_badge where id in (SELECT top %d id FROM user_badge WHERE user_id = ? and badge_id = ?)", r.Cnt-1), r.UserID, r.BadgeID); err!=nil {
48
+
returnerr
49
+
}
50
+
} else {
51
+
varids []int64
52
+
iferr:=x.SQL("SELECT id FROM user_badge WHERE user_id = ? and badge_id = ? limit ?", r.UserID, r.BadgeID, r.Cnt-1).Find(&ids); err!=nil {
0 commit comments