summaryrefslogtreecommitdiffstats
path: root/models/migrations/v1_6
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-12-12 23:57:56 +0100
commite68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch)
tree97775d6c13b0f416af55314eb6a89ef792474615 /models/migrations/v1_6
parentInitial commit. (diff)
downloadforgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz
forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to '')
-rw-r--r--models/migrations/v1_6/v70.go110
-rw-r--r--models/migrations/v1_6/v71.go79
-rw-r--r--models/migrations/v1_6/v72.go30
3 files changed, 219 insertions, 0 deletions
diff --git a/models/migrations/v1_6/v70.go b/models/migrations/v1_6/v70.go
new file mode 100644
index 0000000..74434a8
--- /dev/null
+++ b/models/migrations/v1_6/v70.go
@@ -0,0 +1,110 @@
+// Copyright 2018 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_6 //nolint
+
+import (
+ "fmt"
+ "time"
+
+ "code.gitea.io/gitea/modules/setting"
+
+ "xorm.io/xorm"
+)
+
+func AddIssueDependencies(x *xorm.Engine) (err error) {
+ type IssueDependency struct {
+ ID int64 `xorm:"pk autoincr"`
+ UserID int64 `xorm:"NOT NULL"`
+ IssueID int64 `xorm:"NOT NULL"`
+ DependencyID int64 `xorm:"NOT NULL"`
+ Created time.Time `xorm:"-"`
+ CreatedUnix int64 `xorm:"created"`
+ Updated time.Time `xorm:"-"`
+ UpdatedUnix int64 `xorm:"updated"`
+ }
+
+ const (
+ v16UnitTypeCode = iota + 1 // 1 code
+ v16UnitTypeIssues // 2 issues
+ v16UnitTypePRs // 3 PRs
+ v16UnitTypeCommits // 4 Commits
+ v16UnitTypeReleases // 5 Releases
+ v16UnitTypeWiki // 6 Wiki
+ v16UnitTypeSettings // 7 Settings
+ v16UnitTypeExternalWiki // 8 ExternalWiki
+ v16UnitTypeExternalTracker // 9 ExternalTracker
+ )
+
+ if err = x.Sync(new(IssueDependency)); err != nil {
+ return fmt.Errorf("Error creating issue_dependency_table column definition: %w", err)
+ }
+
+ // Update Comment definition
+ // This (copied) struct does only contain fields used by xorm as the only use here is to update the database
+
+ // CommentType defines the comment type
+ type CommentType int
+
+ // TimeStamp defines a timestamp
+ type TimeStamp int64
+
+ type Comment struct {
+ ID int64 `xorm:"pk autoincr"`
+ Type CommentType
+ PosterID int64 `xorm:"INDEX"`
+ IssueID int64 `xorm:"INDEX"`
+ LabelID int64
+ OldMilestoneID int64
+ MilestoneID int64
+ OldAssigneeID int64
+ AssigneeID int64
+ OldTitle string
+ NewTitle string
+ DependentIssueID int64
+
+ CommitID int64
+ Line int64
+ Content string `xorm:"TEXT"`
+
+ CreatedUnix TimeStamp `xorm:"INDEX created"`
+ UpdatedUnix TimeStamp `xorm:"INDEX updated"`
+
+ // Reference issue in commit message
+ CommitSHA string `xorm:"VARCHAR(40)"`
+ }
+
+ if err = x.Sync(new(Comment)); err != nil {
+ return fmt.Errorf("Error updating issue_comment table column definition: %w", err)
+ }
+
+ // RepoUnit describes all units of a repository
+ type RepoUnit struct {
+ ID int64
+ RepoID int64 `xorm:"INDEX(s)"`
+ Type int `xorm:"INDEX(s)"`
+ Config map[string]any `xorm:"JSON"`
+ CreatedUnix int64 `xorm:"INDEX CREATED"`
+ Created time.Time `xorm:"-"`
+ }
+
+ // Updating existing issue units
+ units := make([]*RepoUnit, 0, 100)
+ err = x.Where("`type` = ?", v16UnitTypeIssues).Find(&units)
+ if err != nil {
+ return fmt.Errorf("Query repo units: %w", err)
+ }
+ for _, unit := range units {
+ if unit.Config == nil {
+ unit.Config = make(map[string]any)
+ }
+ if _, ok := unit.Config["EnableDependencies"]; !ok {
+ unit.Config["EnableDependencies"] = setting.Service.DefaultEnableDependencies
+ }
+ if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
+ return err
+ }
+ }
+
+ return err
+}
diff --git a/models/migrations/v1_6/v71.go b/models/migrations/v1_6/v71.go
new file mode 100644
index 0000000..5861872
--- /dev/null
+++ b/models/migrations/v1_6/v71.go
@@ -0,0 +1,79 @@
+// Copyright 2018 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_6 //nolint
+
+import (
+ "fmt"
+
+ "code.gitea.io/gitea/models/migrations/base"
+ "code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
+
+ "xorm.io/xorm"
+)
+
+func AddScratchHash(x *xorm.Engine) error {
+ // TwoFactor see models/twofactor.go
+ type TwoFactor struct {
+ ID int64 `xorm:"pk autoincr"`
+ UID int64 `xorm:"UNIQUE"`
+ Secret string
+ ScratchToken string
+ ScratchSalt string
+ ScratchHash string
+ LastUsedPasscode string `xorm:"VARCHAR(10)"`
+ CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
+ UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
+ }
+
+ if err := x.Sync(new(TwoFactor)); err != nil {
+ return fmt.Errorf("Sync: %w", err)
+ }
+
+ sess := x.NewSession()
+ defer sess.Close()
+
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+
+ // transform all tokens to hashes
+ const batchSize = 100
+ for start := 0; ; start += batchSize {
+ tfas := make([]*TwoFactor, 0, batchSize)
+ if err := sess.Limit(batchSize, start).Find(&tfas); err != nil {
+ return err
+ }
+ if len(tfas) == 0 {
+ break
+ }
+
+ for _, tfa := range tfas {
+ // generate salt
+ salt, err := util.CryptoRandomString(10)
+ if err != nil {
+ return err
+ }
+ tfa.ScratchSalt = salt
+ tfa.ScratchHash = base.HashToken(tfa.ScratchToken, salt)
+
+ if _, err := sess.ID(tfa.ID).Cols("scratch_salt, scratch_hash").Update(tfa); err != nil {
+ return fmt.Errorf("couldn't add in scratch_hash and scratch_salt: %w", err)
+ }
+ }
+ }
+
+ // Commit and begin new transaction for dropping columns
+ if err := sess.Commit(); err != nil {
+ return err
+ }
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+
+ if err := base.DropTableColumns(sess, "two_factor", "scratch_token"); err != nil {
+ return err
+ }
+ return sess.Commit()
+}
diff --git a/models/migrations/v1_6/v72.go b/models/migrations/v1_6/v72.go
new file mode 100644
index 0000000..04cef9a
--- /dev/null
+++ b/models/migrations/v1_6/v72.go
@@ -0,0 +1,30 @@
+// Copyright 2018 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_6 //nolint
+
+import (
+ "fmt"
+
+ "code.gitea.io/gitea/modules/timeutil"
+
+ "xorm.io/xorm"
+)
+
+func AddReview(x *xorm.Engine) error {
+ // Review see models/review.go
+ type Review struct {
+ ID int64 `xorm:"pk autoincr"`
+ Type string
+ ReviewerID int64 `xorm:"index"`
+ IssueID int64 `xorm:"index"`
+ Content string
+ CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
+ UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
+ }
+
+ if err := x.Sync(new(Review)); err != nil {
+ return fmt.Errorf("Sync: %w", err)
+ }
+ return nil
+}