Skip to content

Commit 15fbf23

Browse files
v180 migration should be standalone (#16151)
Unfortunately the v180 migration picked up a few non-standalone dependencies. This PR forcibly copies the important parts back into the migration. Fix #16150 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent f374789 commit 15fbf23

File tree

1 file changed

+56
-7
lines changed

1 file changed

+56
-7
lines changed

models/migrations/v180.go

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
package migrations
66

77
import (
8-
"code.gitea.io/gitea/models"
9-
"code.gitea.io/gitea/modules/migrations/base"
10-
"code.gitea.io/gitea/modules/structs"
118
"code.gitea.io/gitea/modules/util"
129

1310
jsoniter "github.com/json-iterator/go"
@@ -16,20 +13,38 @@ import (
1613
)
1714

1815
func deleteMigrationCredentials(x *xorm.Engine) (err error) {
16+
// Task represents a task
17+
type Task struct {
18+
ID int64
19+
DoerID int64 `xorm:"index"` // operator
20+
OwnerID int64 `xorm:"index"` // repo owner id, when creating, the repoID maybe zero
21+
RepoID int64 `xorm:"index"`
22+
Type int
23+
Status int `xorm:"index"`
24+
StartTime int64
25+
EndTime int64
26+
PayloadContent string `xorm:"TEXT"`
27+
Errors string `xorm:"TEXT"` // if task failed, saved the error reason
28+
Created int64 `xorm:"created"`
29+
}
30+
31+
const TaskTypeMigrateRepo = 0
32+
const TaskStatusStopped = 2
33+
1934
const batchSize = 100
2035

2136
// only match migration tasks, that are not pending or running
2237
cond := builder.Eq{
23-
"type": structs.TaskTypeMigrateRepo,
38+
"type": TaskTypeMigrateRepo,
2439
}.And(builder.Gte{
25-
"status": structs.TaskStatusStopped,
40+
"status": TaskStatusStopped,
2641
})
2742

2843
sess := x.NewSession()
2944
defer sess.Close()
3045

3146
for start := 0; ; start += batchSize {
32-
tasks := make([]*models.Task, 0, batchSize)
47+
tasks := make([]*Task, 0, batchSize)
3348
if err = sess.Limit(batchSize, start).Where(cond, 0).Find(&tasks); err != nil {
3449
return
3550
}
@@ -55,7 +70,41 @@ func deleteMigrationCredentials(x *xorm.Engine) (err error) {
5570
}
5671

5772
func removeCredentials(payload string) (string, error) {
58-
var opts base.MigrateOptions
73+
// MigrateOptions defines the way a repository gets migrated
74+
// this is for internal usage by migrations module and func who interact with it
75+
type MigrateOptions struct {
76+
// required: true
77+
CloneAddr string `json:"clone_addr" binding:"Required"`
78+
CloneAddrEncrypted string `json:"clone_addr_encrypted,omitempty"`
79+
AuthUsername string `json:"auth_username"`
80+
AuthPassword string `json:"-"`
81+
AuthPasswordEncrypted string `json:"auth_password_encrypted,omitempty"`
82+
AuthToken string `json:"-"`
83+
AuthTokenEncrypted string `json:"auth_token_encrypted,omitempty"`
84+
// required: true
85+
UID int `json:"uid" binding:"Required"`
86+
// required: true
87+
RepoName string `json:"repo_name" binding:"Required"`
88+
Mirror bool `json:"mirror"`
89+
LFS bool `json:"lfs"`
90+
LFSEndpoint string `json:"lfs_endpoint"`
91+
Private bool `json:"private"`
92+
Description string `json:"description"`
93+
OriginalURL string
94+
GitServiceType int
95+
Wiki bool
96+
Issues bool
97+
Milestones bool
98+
Labels bool
99+
Releases bool
100+
Comments bool
101+
PullRequests bool
102+
ReleaseAssets bool
103+
MigrateToRepoID int64
104+
MirrorInterval string `json:"mirror_interval"`
105+
}
106+
107+
var opts MigrateOptions
59108
json := jsoniter.ConfigCompatibleWithStandardLibrary
60109
err := json.Unmarshal([]byte(payload), &opts)
61110
if err != nil {

0 commit comments

Comments
 (0)