diff options
author | Lunny Xiao | 2022-02-25 22:08:00 +0800 |
---|---|---|
committer | GitHub | 2022-02-25 15:08:00 +0100 |
commit | c077a0361ab2a2799e51aa54216fa4348f5d166f (patch) | |
tree | 33428eb6baf5fc3c6975a84a9bb71c2b4f1adeb1 | |
parent | 6f21a94d1885086ffdb56ba5ea2137820d469164 (diff) |
Fix migration v210 (#18893)
-rw-r--r-- | models/migrations/v210.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/models/migrations/v210.go b/models/migrations/v210.go index cf50760b9..53461c03e 100644 --- a/models/migrations/v210.go +++ b/models/migrations/v210.go @@ -137,17 +137,23 @@ func remigrateU2FCredentials(x *xorm.Engine) error { CreatedUnix: reg.CreatedUnix, } - has, err := sess.ID(reg.ID).Where("id = ?", reg.ID).Get(new(webauthnCredential)) + has, err := sess.ID(reg.ID).Get(new(webauthnCredential)) if err != nil { return fmt.Errorf("unable to get webauthn_credential[%d]. Error: %w", reg.ID, err) } if !has { - _, err = sess.Insert(remigrated) + has, err := sess.Where("`lower_name`=?", remigrated.LowerName).And("`user_id`=?", remigrated.UserID).Exist(new(webauthnCredential)) if err != nil { - return fmt.Errorf("unable to (re)insert webauthn_credential[%d]. Error: %w", reg.ID, err) + return fmt.Errorf("unable to check webauthn_credential[lower_name: %s, user_id:%v]. Error: %w", remigrated.LowerName, remigrated.UserID, err) } + if !has { + _, err = sess.Insert(remigrated) + if err != nil { + return fmt.Errorf("unable to (re)insert webauthn_credential[%d]. Error: %w", reg.ID, err) + } - continue + continue + } } _, err = sess.ID(remigrated.ID).AllCols().Update(remigrated) |