diff options
author | Daniel Baumann <daniel@debian.org> | 2024-10-18 20:33:49 +0200 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-10-18 20:33:49 +0200 |
commit | dd136858f1ea40ad3c94191d647487fa4f31926c (patch) | |
tree | 58fec94a7b2a12510c9664b21793f1ed560c6518 /models/migrations/v1_10 | |
parent | Initial commit. (diff) | |
download | forgejo-dd136858f1ea40ad3c94191d647487fa4f31926c.tar.xz forgejo-dd136858f1ea40ad3c94191d647487fa4f31926c.zip |
Adding upstream version 9.0.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to '')
-rw-r--r-- | models/migrations/v1_10/v100.go | 82 | ||||
-rw-r--r-- | models/migrations/v1_10/v101.go | 18 | ||||
-rw-r--r-- | models/migrations/v1_10/v88.go | 65 | ||||
-rw-r--r-- | models/migrations/v1_10/v89.go | 35 | ||||
-rw-r--r-- | models/migrations/v1_10/v90.go | 17 | ||||
-rw-r--r-- | models/migrations/v1_10/v91.go | 25 | ||||
-rw-r--r-- | models/migrations/v1_10/v92.go | 14 | ||||
-rw-r--r-- | models/migrations/v1_10/v93.go | 15 | ||||
-rw-r--r-- | models/migrations/v1_10/v94.go | 23 | ||||
-rw-r--r-- | models/migrations/v1_10/v95.go | 19 | ||||
-rw-r--r-- | models/migrations/v1_10/v96.go | 64 | ||||
-rw-r--r-- | models/migrations/v1_10/v97.go | 14 | ||||
-rw-r--r-- | models/migrations/v1_10/v98.go | 16 | ||||
-rw-r--r-- | models/migrations/v1_10/v99.go | 38 |
14 files changed, 445 insertions, 0 deletions
diff --git a/models/migrations/v1_10/v100.go b/models/migrations/v1_10/v100.go new file mode 100644 index 0000000..5d2fd8e --- /dev/null +++ b/models/migrations/v1_10/v100.go @@ -0,0 +1,82 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import ( + "net/url" + "strings" + "time" + + "xorm.io/xorm" +) + +func UpdateMigrationServiceTypes(x *xorm.Engine) error { + type Repository struct { + ID int64 + OriginalServiceType int `xorm:"index default(0)"` + OriginalURL string `xorm:"VARCHAR(2048)"` + } + + if err := x.Sync(new(Repository)); err != nil { + return err + } + + var last int + const batchSize = 50 + for { + results := make([]Repository, 0, batchSize) + err := x.Where("original_url <> '' AND original_url IS NOT NULL"). + And("original_service_type = 0 OR original_service_type IS NULL"). + OrderBy("id"). + Limit(batchSize, last). + Find(&results) + if err != nil { + return err + } + if len(results) == 0 { + break + } + last += len(results) + + const PlainGitService = 1 // 1 plain git service + const GithubService = 2 // 2 github.com + + for _, res := range results { + u, err := url.Parse(res.OriginalURL) + if err != nil { + return err + } + serviceType := PlainGitService + if strings.EqualFold(u.Host, "github.com") { + serviceType = GithubService + } + _, err = x.Exec("UPDATE repository SET original_service_type = ? WHERE id = ?", serviceType, res.ID) + if err != nil { + return err + } + } + } + + type ExternalLoginUser struct { + ExternalID string `xorm:"pk NOT NULL"` + UserID int64 `xorm:"INDEX NOT NULL"` + LoginSourceID int64 `xorm:"pk NOT NULL"` + RawData map[string]any `xorm:"TEXT JSON"` + Provider string `xorm:"index VARCHAR(25)"` + Email string + Name string + FirstName string + LastName string + NickName string + Description string + AvatarURL string + Location string + AccessToken string + AccessTokenSecret string + RefreshToken string + ExpiresAt time.Time + } + + return x.Sync(new(ExternalLoginUser)) +} diff --git a/models/migrations/v1_10/v101.go b/models/migrations/v1_10/v101.go new file mode 100644 index 0000000..f023a2a --- /dev/null +++ b/models/migrations/v1_10/v101.go @@ -0,0 +1,18 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import ( + "xorm.io/xorm" +) + +func ChangeSomeColumnsLengthOfExternalLoginUser(x *xorm.Engine) error { + type ExternalLoginUser struct { + AccessToken string `xorm:"TEXT"` + AccessTokenSecret string `xorm:"TEXT"` + RefreshToken string `xorm:"TEXT"` + } + + return x.Sync(new(ExternalLoginUser)) +} diff --git a/models/migrations/v1_10/v88.go b/models/migrations/v1_10/v88.go new file mode 100644 index 0000000..7e86ac3 --- /dev/null +++ b/models/migrations/v1_10/v88.go @@ -0,0 +1,65 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import ( + "crypto/sha1" + "fmt" + + "xorm.io/xorm" +) + +func hashContext(context string) string { + return fmt.Sprintf("%x", sha1.Sum([]byte(context))) +} + +func AddCommitStatusContext(x *xorm.Engine) error { + type CommitStatus struct { + ID int64 `xorm:"pk autoincr"` + ContextHash string `xorm:"char(40) index"` + Context string `xorm:"TEXT"` + } + + if err := x.Sync(new(CommitStatus)); err != nil { + return err + } + + sess := x.NewSession() + defer sess.Close() + + start := 0 + for { + statuses := make([]*CommitStatus, 0, 100) + err := sess.OrderBy("id").Limit(100, start).Find(&statuses) + if err != nil { + return err + } + if len(statuses) == 0 { + break + } + + if err = sess.Begin(); err != nil { + return err + } + + for _, status := range statuses { + status.ContextHash = hashContext(status.Context) + if _, err := sess.ID(status.ID).Cols("context_hash").Update(status); err != nil { + return err + } + } + + if err := sess.Commit(); err != nil { + return err + } + + if len(statuses) < 100 { + break + } + + start += len(statuses) + } + + return nil +} diff --git a/models/migrations/v1_10/v89.go b/models/migrations/v1_10/v89.go new file mode 100644 index 0000000..d5f27ff --- /dev/null +++ b/models/migrations/v1_10/v89.go @@ -0,0 +1,35 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import "xorm.io/xorm" + +func AddOriginalMigrationInfo(x *xorm.Engine) error { + // Issue see models/issue.go + type Issue struct { + OriginalAuthor string + OriginalAuthorID int64 + } + + if err := x.Sync(new(Issue)); err != nil { + return err + } + + // Issue see models/issue_comment.go + type Comment struct { + OriginalAuthor string + OriginalAuthorID int64 + } + + if err := x.Sync(new(Comment)); err != nil { + return err + } + + // Issue see models/repo.go + type Repository struct { + OriginalURL string + } + + return x.Sync(new(Repository)) +} diff --git a/models/migrations/v1_10/v90.go b/models/migrations/v1_10/v90.go new file mode 100644 index 0000000..295d4b1 --- /dev/null +++ b/models/migrations/v1_10/v90.go @@ -0,0 +1,17 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import "xorm.io/xorm" + +func ChangeSomeColumnsLengthOfRepo(x *xorm.Engine) error { + type Repository struct { + ID int64 `xorm:"pk autoincr"` + Description string `xorm:"TEXT"` + Website string `xorm:"VARCHAR(2048)"` + OriginalURL string `xorm:"VARCHAR(2048)"` + } + + return x.Sync(new(Repository)) +} diff --git a/models/migrations/v1_10/v91.go b/models/migrations/v1_10/v91.go new file mode 100644 index 0000000..48cac2d --- /dev/null +++ b/models/migrations/v1_10/v91.go @@ -0,0 +1,25 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import "xorm.io/xorm" + +func AddIndexOnRepositoryAndComment(x *xorm.Engine) error { + type Repository struct { + ID int64 `xorm:"pk autoincr"` + OwnerID int64 `xorm:"index"` + } + + if err := x.Sync(new(Repository)); err != nil { + return err + } + + type Comment struct { + ID int64 `xorm:"pk autoincr"` + Type int `xorm:"index"` + ReviewID int64 `xorm:"index"` + } + + return x.Sync(new(Comment)) +} diff --git a/models/migrations/v1_10/v92.go b/models/migrations/v1_10/v92.go new file mode 100644 index 0000000..9080108 --- /dev/null +++ b/models/migrations/v1_10/v92.go @@ -0,0 +1,14 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import ( + "xorm.io/builder" + "xorm.io/xorm" +) + +func RemoveLingeringIndexStatus(x *xorm.Engine) error { + _, err := x.Exec(builder.Delete(builder.NotIn("`repo_id`", builder.Select("`id`").From("`repository`"))).From("`repo_indexer_status`")) + return err +} diff --git a/models/migrations/v1_10/v93.go b/models/migrations/v1_10/v93.go new file mode 100644 index 0000000..ee59a8d --- /dev/null +++ b/models/migrations/v1_10/v93.go @@ -0,0 +1,15 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import "xorm.io/xorm" + +func AddEmailNotificationEnabledToUser(x *xorm.Engine) error { + // User see models/user.go + type User struct { + EmailNotificationsPreference string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'enabled'"` + } + + return x.Sync(new(User)) +} diff --git a/models/migrations/v1_10/v94.go b/models/migrations/v1_10/v94.go new file mode 100644 index 0000000..c131af1 --- /dev/null +++ b/models/migrations/v1_10/v94.go @@ -0,0 +1,23 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import "xorm.io/xorm" + +func AddStatusCheckColumnsForProtectedBranches(x *xorm.Engine) error { + type ProtectedBranch struct { + EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"` + StatusCheckContexts []string `xorm:"JSON TEXT"` + } + + if err := x.Sync(new(ProtectedBranch)); err != nil { + return err + } + + _, err := x.Cols("enable_status_check", "status_check_contexts").Update(&ProtectedBranch{ + EnableStatusCheck: false, + StatusCheckContexts: []string{}, + }) + return err +} diff --git a/models/migrations/v1_10/v95.go b/models/migrations/v1_10/v95.go new file mode 100644 index 0000000..3b1f67f --- /dev/null +++ b/models/migrations/v1_10/v95.go @@ -0,0 +1,19 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import "xorm.io/xorm" + +func AddCrossReferenceColumns(x *xorm.Engine) error { + // Comment see models/comment.go + type Comment struct { + RefRepoID int64 `xorm:"index"` + RefIssueID int64 `xorm:"index"` + RefCommentID int64 `xorm:"index"` + RefAction int64 `xorm:"SMALLINT"` + RefIsPull bool + } + + return x.Sync(new(Comment)) +} diff --git a/models/migrations/v1_10/v96.go b/models/migrations/v1_10/v96.go new file mode 100644 index 0000000..34c8240 --- /dev/null +++ b/models/migrations/v1_10/v96.go @@ -0,0 +1,64 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import ( + "path/filepath" + + "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" + + "xorm.io/xorm" +) + +func DeleteOrphanedAttachments(x *xorm.Engine) error { + type Attachment struct { + ID int64 `xorm:"pk autoincr"` + UUID string `xorm:"uuid UNIQUE"` + IssueID int64 `xorm:"INDEX"` + ReleaseID int64 `xorm:"INDEX"` + CommentID int64 + } + + sess := x.NewSession() + defer sess.Close() + + limit := setting.Database.IterateBufferSize + if limit <= 0 { + limit = 50 + } + + for { + attachments := make([]Attachment, 0, limit) + if err := sess.Where("`issue_id` = 0 and (`release_id` = 0 or `release_id` not in (select `id` from `release`))"). + Cols("id, uuid").Limit(limit). + Asc("id"). + Find(&attachments); err != nil { + return err + } + if len(attachments) == 0 { + return nil + } + + ids := make([]int64, 0, limit) + for _, attachment := range attachments { + ids = append(ids, attachment.ID) + } + if len(ids) > 0 { + if _, err := sess.In("id", ids).Delete(new(Attachment)); err != nil { + return err + } + } + + for _, attachment := range attachments { + uuid := attachment.UUID + if err := util.RemoveAll(filepath.Join(setting.Attachment.Storage.Path, uuid[0:1], uuid[1:2], uuid)); err != nil { + return err + } + } + if len(attachments) < limit { + return nil + } + } +} diff --git a/models/migrations/v1_10/v97.go b/models/migrations/v1_10/v97.go new file mode 100644 index 0000000..dee45b3 --- /dev/null +++ b/models/migrations/v1_10/v97.go @@ -0,0 +1,14 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import "xorm.io/xorm" + +func AddRepoAdminChangeTeamAccessColumnForUser(x *xorm.Engine) error { + type User struct { + RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"` + } + + return x.Sync(new(User)) +} diff --git a/models/migrations/v1_10/v98.go b/models/migrations/v1_10/v98.go new file mode 100644 index 0000000..bdd9aed --- /dev/null +++ b/models/migrations/v1_10/v98.go @@ -0,0 +1,16 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import "xorm.io/xorm" + +func AddOriginalAuthorOnMigratedReleases(x *xorm.Engine) error { + type Release struct { + ID int64 + OriginalAuthor string + OriginalAuthorID int64 `xorm:"index"` + } + + return x.Sync(new(Release)) +} diff --git a/models/migrations/v1_10/v99.go b/models/migrations/v1_10/v99.go new file mode 100644 index 0000000..ebe6597 --- /dev/null +++ b/models/migrations/v1_10/v99.go @@ -0,0 +1,38 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_10 //nolint + +import ( + "code.gitea.io/gitea/modules/timeutil" + + "xorm.io/xorm" +) + +func AddTaskTable(x *xorm.Engine) error { + // TaskType defines task type + type TaskType int + + // TaskStatus defines task status + type TaskStatus int + + type Task struct { + ID int64 + DoerID int64 `xorm:"index"` // operator + OwnerID int64 `xorm:"index"` // repo owner id, when creating, the repoID maybe zero + RepoID int64 `xorm:"index"` + Type TaskType + Status TaskStatus `xorm:"index"` + StartTime timeutil.TimeStamp + EndTime timeutil.TimeStamp + PayloadContent string `xorm:"TEXT"` + Errors string `xorm:"TEXT"` // if task failed, saved the error reason + Created timeutil.TimeStamp `xorm:"created"` + } + + type Repository struct { + Status int `xorm:"NOT NULL DEFAULT 0"` + } + + return x.Sync(new(Task), new(Repository)) +} |