summaryrefslogtreecommitdiffstats
path: root/models/migrations
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-02-25 22:04:59 +0800
committerGitHub <noreply@github.com>2022-02-25 15:04:59 +0100
commita5e8daee737fa2c3c191cc542d0f8e239f81f0f9 (patch)
treed51b71f4b779c9996caa857b66ecbcf775490f60 /models/migrations
parent49cab2b01fc40c04dbd847e12a76516ced6b29b5 (diff)
downloadgitea-a5e8daee737fa2c3c191cc542d0f8e239f81f0f9.tar.gz
gitea-a5e8daee737fa2c3c191cc542d0f8e239f81f0f9.zip
Fix migration v210 (#18892)
Diffstat (limited to 'models/migrations')
-rw-r--r--models/migrations/v210.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/models/migrations/v210.go b/models/migrations/v210.go
index 9da8ca9db6..dafe355fe2 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)