diff options
Diffstat (limited to 'models/migrations/v1_24')
-rw-r--r-- | models/migrations/v1_24/v312.go | 6 | ||||
-rw-r--r-- | models/migrations/v1_24/v315.go | 7 | ||||
-rw-r--r-- | models/migrations/v1_24/v316.go | 6 | ||||
-rw-r--r-- | models/migrations/v1_24/v318.go | 6 | ||||
-rw-r--r-- | models/migrations/v1_24/v319.go | 7 | ||||
-rw-r--r-- | models/migrations/v1_24/v320.go | 57 |
6 files changed, 82 insertions, 7 deletions
diff --git a/models/migrations/v1_24/v312.go b/models/migrations/v1_24/v312.go index 9766dc1ccf..367a6c4947 100644 --- a/models/migrations/v1_24/v312.go +++ b/models/migrations/v1_24/v312.go @@ -17,5 +17,9 @@ func (pullAutoMerge) TableName() string { } func AddDeleteBranchAfterMergeForAutoMerge(x *xorm.Engine) error { - return x.Sync(new(pullAutoMerge)) + _, err := x.SyncWithOptions(xorm.SyncOptions{ + IgnoreConstrains: true, + IgnoreIndices: true, + }, new(pullAutoMerge)) + return err } diff --git a/models/migrations/v1_24/v315.go b/models/migrations/v1_24/v315.go index aefb872d0f..22a72c31e9 100644 --- a/models/migrations/v1_24/v315.go +++ b/models/migrations/v1_24/v315.go @@ -11,6 +11,9 @@ func AddEphemeralToActionRunner(x *xorm.Engine) error { type ActionRunner struct { Ephemeral bool `xorm:"ephemeral NOT NULL DEFAULT false"` } - - return x.Sync(new(ActionRunner)) + _, err := x.SyncWithOptions(xorm.SyncOptions{ + IgnoreConstrains: true, + IgnoreIndices: true, + }, new(ActionRunner)) + return err } diff --git a/models/migrations/v1_24/v316.go b/models/migrations/v1_24/v316.go index 0378133e53..e7f04333cc 100644 --- a/models/migrations/v1_24/v316.go +++ b/models/migrations/v1_24/v316.go @@ -16,5 +16,9 @@ func AddDescriptionForSecretsAndVariables(x *xorm.Engine) error { Description string `xorm:"TEXT"` } - return x.Sync(new(Secret), new(ActionVariable)) + _, err := x.SyncWithOptions(xorm.SyncOptions{ + IgnoreConstrains: true, + IgnoreIndices: true, + }, new(Secret), new(ActionVariable)) + return err } diff --git a/models/migrations/v1_24/v318.go b/models/migrations/v1_24/v318.go index 83fb0061d3..3e08c3d504 100644 --- a/models/migrations/v1_24/v318.go +++ b/models/migrations/v1_24/v318.go @@ -13,5 +13,9 @@ func AddRepoUnitAnonymousAccessMode(x *xorm.Engine) error { type RepoUnit struct { //revive:disable-line:exported AnonymousAccessMode perm.AccessMode `xorm:"NOT NULL DEFAULT 0"` } - return x.Sync(&RepoUnit{}) + _, err := x.SyncWithOptions(xorm.SyncOptions{ + IgnoreConstrains: true, + IgnoreIndices: true, + }, new(RepoUnit)) + return err } diff --git a/models/migrations/v1_24/v319.go b/models/migrations/v1_24/v319.go index 6983c38605..6571ddf75b 100644 --- a/models/migrations/v1_24/v319.go +++ b/models/migrations/v1_24/v319.go @@ -11,6 +11,9 @@ func AddExclusiveOrderColumnToLabelTable(x *xorm.Engine) error { type Label struct { ExclusiveOrder int `xorm:"DEFAULT 0"` } - - return x.Sync(new(Label)) + _, err := x.SyncWithOptions(xorm.SyncOptions{ + IgnoreConstrains: true, + IgnoreIndices: true, + }, new(Label)) + return err } diff --git a/models/migrations/v1_24/v320.go b/models/migrations/v1_24/v320.go new file mode 100644 index 0000000000..1d34444826 --- /dev/null +++ b/models/migrations/v1_24/v320.go @@ -0,0 +1,57 @@ +// Copyright 2025 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_24 //nolint + +import ( + "code.gitea.io/gitea/modules/json" + + "xorm.io/xorm" +) + +func MigrateSkipTwoFactor(x *xorm.Engine) error { + type LoginSource struct { + TwoFactorPolicy string `xorm:"two_factor_policy NOT NULL DEFAULT ''"` + } + _, err := x.SyncWithOptions( + xorm.SyncOptions{ + IgnoreConstrains: true, + IgnoreIndices: true, + }, + new(LoginSource), + ) + if err != nil { + return err + } + + type LoginSourceSimple struct { + ID int64 + Cfg string + } + + var loginSources []LoginSourceSimple + err = x.Table("login_source").Find(&loginSources) + if err != nil { + return err + } + + for _, source := range loginSources { + if source.Cfg == "" { + continue + } + + var cfg map[string]any + err = json.Unmarshal([]byte(source.Cfg), &cfg) + if err != nil { + return err + } + + if cfg["SkipLocalTwoFA"] == true { + _, err = x.Exec("UPDATE login_source SET two_factor_policy = 'skip' WHERE id = ?", source.ID) + if err != nil { + return err + } + } + } + return nil +} |