Skip to content

Commit ff7a661

Browse files
committed
Merge branch 'main' into lunny/code_review_line_number
2 parents 6f6d956 + 54fe47f commit ff7a661

37 files changed

+244
-2822
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ require (
131131
mvdan.cc/xurls/v2 v2.6.0
132132
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
133133
xorm.io/builder v0.3.13
134-
xorm.io/xorm v1.3.9
134+
xorm.io/xorm v1.3.10
135135
)
136136

137137
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,5 +955,5 @@ strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 h1:mUcz5b3
955955
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251/go.mod h1:FJGmPh3vz9jSos1L/F91iAgnC/aejc0wIIrF2ZwJxdY=
956956
xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo=
957957
xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
958-
xorm.io/xorm v1.3.9 h1:TUovzS0ko+IQ1XnNLfs5dqK1cJl1H5uHpWbWqAQ04nU=
959-
xorm.io/xorm v1.3.9/go.mod h1:LsCCffeeYp63ssk0pKumP6l96WZcHix7ChpurcLNuMw=
958+
xorm.io/xorm v1.3.10 h1:yR83hTT4mKIPyA/lvWFTzS35xjLwkiYnwdw0Qupeh0o=
959+
xorm.io/xorm v1.3.10/go.mod h1:Lo7hmsFF0F0GbDE7ubX5ZKa+eCf0eCuiJAUG3oI5cxQ=

models/migrations/migrations.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,9 @@ func prepareMigrationTasks() []*migration {
384384
newMigration(319, "Add ExclusiveOrder to Label table", v1_24.AddExclusiveOrderColumnToLabelTable),
385385
newMigration(320, "Migrate two_factor_policy to login_source table", v1_24.MigrateSkipTwoFactor),
386386

387-
// Gitea 1.24.0-rc0 ends at migration ID number 320 (database version 321)
388-
newMigration(321, "Add BeforeCommitID to Comment table", v1_25.AddBeforeCommitIDForComment),
387+
// Gitea 1.24.0 ends at database version 321
388+
newMigration(321, "Use LONGTEXT for some columns and fix review_state.updated_files column", v1_25.UseLongTextInSomeColumnsAndFixBugs),
389+
newMigration(322, "Add BeforeCommitID to Comment table", v1_25.AddBeforeCommitIDForComment),
389390
}
390391
return preparedMigrations
391392
}

models/migrations/v1_25/v321.go

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,49 @@
44
package v1_25
55

66
import (
7+
"code.gitea.io/gitea/models/migrations/base"
8+
"code.gitea.io/gitea/modules/setting"
9+
710
"xorm.io/xorm"
11+
"xorm.io/xorm/schemas"
812
)
913

10-
type comment struct {
11-
BeforeCommitID string `xorm:"VARCHAR(64)"`
12-
}
14+
func UseLongTextInSomeColumnsAndFixBugs(x *xorm.Engine) error {
15+
if !setting.Database.Type.IsMySQL() {
16+
return nil // Only mysql need to change from text to long text, for other databases, they are the same
17+
}
1318

14-
// TableName return database table name for xorm
15-
func (comment) TableName() string {
16-
return "comment"
17-
}
19+
if err := base.ModifyColumn(x, "review_state", &schemas.Column{
20+
Name: "updated_files",
21+
SQLType: schemas.SQLType{
22+
Name: "LONGTEXT",
23+
},
24+
Length: 0,
25+
Nullable: false,
26+
DefaultIsEmpty: true,
27+
}); err != nil {
28+
return err
29+
}
1830

19-
func AddBeforeCommitIDForComment(x *xorm.Engine) error {
20-
if _, err := x.SyncWithOptions(xorm.SyncOptions{
21-
IgnoreConstrains: true,
22-
IgnoreIndices: true,
23-
}, new(comment)); err != nil {
31+
if err := base.ModifyColumn(x, "package_property", &schemas.Column{
32+
Name: "value",
33+
SQLType: schemas.SQLType{
34+
Name: "LONGTEXT",
35+
},
36+
Length: 0,
37+
Nullable: false,
38+
DefaultIsEmpty: true,
39+
}); err != nil {
2440
return err
2541
}
26-
_, err := x.Exec("UPDATE comment SET before_commit_id = (SELECT merge_base FROM pull_request WHERE pull_request.issue_id = comment.issue_id) WHERE `type`=21 AND before_commit_id IS NULL")
27-
return err
42+
43+
return base.ModifyColumn(x, "notice", &schemas.Column{
44+
Name: "description",
45+
SQLType: schemas.SQLType{
46+
Name: "LONGTEXT",
47+
},
48+
Length: 0,
49+
Nullable: false,
50+
DefaultIsEmpty: true,
51+
})
2852
}

models/migrations/v1_25/v321_test.go

Lines changed: 46 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,97 +7,64 @@ import (
77
"testing"
88

99
"code.gitea.io/gitea/models/migrations/base"
10-
"code.gitea.io/gitea/modules/references"
10+
"code.gitea.io/gitea/modules/setting"
1111
"code.gitea.io/gitea/modules/timeutil"
1212

1313
"github.com/stretchr/testify/assert"
1414
)
1515

16-
func Test_AddBeforeCommitIDForComment(t *testing.T) {
17-
type Comment struct { // old struct
18-
ID int64 `xorm:"pk autoincr"`
19-
Type int `xorm:"INDEX"`
20-
PosterID int64 `xorm:"INDEX"`
21-
OriginalAuthor string
22-
OriginalAuthorID int64
23-
IssueID int64 `xorm:"INDEX"`
24-
LabelID int64
25-
OldProjectID int64
26-
ProjectID int64
27-
OldMilestoneID int64
28-
MilestoneID int64
29-
TimeID int64
30-
AssigneeID int64
31-
RemovedAssignee bool
32-
AssigneeTeamID int64 `xorm:"NOT NULL DEFAULT 0"`
33-
ResolveDoerID int64
34-
OldTitle string
35-
NewTitle string
36-
OldRef string
37-
NewRef string
38-
DependentIssueID int64 `xorm:"index"` // This is used by issue_service.deleteIssue
39-
40-
CommitID int64
41-
Line int64 // - previous line / + proposed line
42-
TreePath string
43-
Content string `xorm:"LONGTEXT"`
44-
ContentVersion int `xorm:"NOT NULL DEFAULT 0"`
45-
46-
// Path represents the 4 lines of code cemented by this comment
47-
Patch string `xorm:"-"`
48-
PatchQuoted string `xorm:"LONGTEXT patch"`
49-
50-
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
51-
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
52-
53-
// Reference issue in commit message
54-
CommitSHA string `xorm:"VARCHAR(64)"`
55-
56-
ReviewID int64 `xorm:"index"`
57-
Invalidated bool
58-
59-
// Reference an issue or pull from another comment, issue or PR
60-
// All information is about the origin of the reference
61-
RefRepoID int64 `xorm:"index"` // Repo where the referencing
62-
RefIssueID int64 `xorm:"index"`
63-
RefCommentID int64 `xorm:"index"` // 0 if origin is Issue title or content (or PR's)
64-
RefAction references.XRefAction `xorm:"SMALLINT"` // What happens if RefIssueID resolves
65-
RefIsPull bool
66-
67-
CommentMetaData string `xorm:"JSON TEXT"` // put all non-index metadata in a single field
16+
func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
17+
if !setting.Database.Type.IsMySQL() {
18+
t.Skip("Only MySQL needs to change from TEXT to LONGTEXT")
6819
}
6920

70-
type PullRequest struct {
71-
ID int64 `xorm:"pk autoincr"`
72-
Type int
73-
Status int
74-
ConflictedFiles []string `xorm:"TEXT JSON"`
75-
CommitsAhead int
76-
CommitsBehind int
77-
78-
ChangedProtectedFiles []string `xorm:"TEXT JSON"`
79-
80-
IssueID int64 `xorm:"INDEX"`
81-
Index int64
82-
83-
HeadRepoID int64 `xorm:"INDEX"`
84-
BaseRepoID int64 `xorm:"INDEX"`
85-
HeadBranch string
86-
BaseBranch string
87-
MergeBase string `xorm:"VARCHAR(64)"`
88-
AllowMaintainerEdit bool `xorm:"NOT NULL DEFAULT false"`
21+
type ReviewState struct {
22+
ID int64 `xorm:"pk autoincr"`
23+
UserID int64 `xorm:"NOT NULL UNIQUE(pull_commit_user)"`
24+
PullID int64 `xorm:"NOT NULL INDEX UNIQUE(pull_commit_user) DEFAULT 0"` // Which PR was the review on?
25+
CommitSHA string `xorm:"NOT NULL VARCHAR(64) UNIQUE(pull_commit_user)"` // Which commit was the head commit for the review?
26+
UpdatedFiles map[string]int `xorm:"NOT NULL TEXT JSON"` // Stores for each of the changed files of a PR whether they have been viewed, changed since last viewed, or not viewed
27+
UpdatedUnix timeutil.TimeStamp `xorm:"updated"` // Is an accurate indicator of the order of commits as we do not expect it to be possible to make reviews on previous commits
28+
}
8929

90-
HasMerged bool `xorm:"INDEX"`
91-
MergedCommitID string `xorm:"VARCHAR(64)"`
92-
MergerID int64 `xorm:"INDEX"`
93-
MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"`
30+
type PackageProperty struct {
31+
ID int64 `xorm:"pk autoincr"`
32+
RefType int `xorm:"INDEX NOT NULL"`
33+
RefID int64 `xorm:"INDEX NOT NULL"`
34+
Name string `xorm:"INDEX NOT NULL"`
35+
Value string `xorm:"TEXT NOT NULL"`
36+
}
9437

95-
Flow int `xorm:"NOT NULL DEFAULT 0"`
38+
type Notice struct {
39+
ID int64 `xorm:"pk autoincr"`
40+
Type int
41+
Description string `xorm:"LONGTEXT"`
42+
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
9643
}
9744

9845
// Prepare and load the testing database
99-
x, deferable := base.PrepareTestEnv(t, 0, new(Comment), new(PullRequest))
46+
x, deferable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
10047
defer deferable()
10148

102-
assert.NoError(t, AddBeforeCommitIDForComment(x))
49+
assert.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
50+
51+
tables, err := x.DBMetas()
52+
assert.NoError(t, err)
53+
54+
for _, table := range tables {
55+
switch table.Name {
56+
case "review_state":
57+
column := table.GetColumn("updated_files")
58+
assert.NotNil(t, column)
59+
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
60+
case "package_property":
61+
column := table.GetColumn("value")
62+
assert.NotNil(t, column)
63+
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
64+
case "notice":
65+
column := table.GetColumn("description")
66+
assert.NotNil(t, column)
67+
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
68+
}
69+
}
10370
}

models/migrations/v1_25/v322.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_25
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
type comment struct {
11+
BeforeCommitID string `xorm:"VARCHAR(64)"`
12+
}
13+
14+
// TableName return database table name for xorm
15+
func (comment) TableName() string {
16+
return "comment"
17+
}
18+
19+
func AddBeforeCommitIDForComment(x *xorm.Engine) error {
20+
if _, err := x.SyncWithOptions(xorm.SyncOptions{
21+
IgnoreConstrains: true,
22+
IgnoreIndices: true,
23+
}, new(comment)); err != nil {
24+
return err
25+
}
26+
_, err := x.Exec("UPDATE comment SET before_commit_id = (SELECT merge_base FROM pull_request WHERE pull_request.issue_id = comment.issue_id) WHERE `type`=21 AND before_commit_id IS NULL")
27+
return err
28+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_25
5+
6+
import (
7+
"testing"
8+
9+
"code.gitea.io/gitea/models/migrations/base"
10+
"code.gitea.io/gitea/modules/references"
11+
"code.gitea.io/gitea/modules/timeutil"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func Test_AddBeforeCommitIDForComment(t *testing.T) {
17+
type Comment struct { // old struct
18+
ID int64 `xorm:"pk autoincr"`
19+
Type int `xorm:"INDEX"`
20+
PosterID int64 `xorm:"INDEX"`
21+
OriginalAuthor string
22+
OriginalAuthorID int64
23+
IssueID int64 `xorm:"INDEX"`
24+
LabelID int64
25+
OldProjectID int64
26+
ProjectID int64
27+
OldMilestoneID int64
28+
MilestoneID int64
29+
TimeID int64
30+
AssigneeID int64
31+
RemovedAssignee bool
32+
AssigneeTeamID int64 `xorm:"NOT NULL DEFAULT 0"`
33+
ResolveDoerID int64
34+
OldTitle string
35+
NewTitle string
36+
OldRef string
37+
NewRef string
38+
DependentIssueID int64 `xorm:"index"` // This is used by issue_service.deleteIssue
39+
40+
CommitID int64
41+
Line int64 // - previous line / + proposed line
42+
TreePath string
43+
Content string `xorm:"LONGTEXT"`
44+
ContentVersion int `xorm:"NOT NULL DEFAULT 0"`
45+
46+
// Path represents the 4 lines of code cemented by this comment
47+
Patch string `xorm:"-"`
48+
PatchQuoted string `xorm:"LONGTEXT patch"`
49+
50+
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
51+
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
52+
53+
// Reference issue in commit message
54+
CommitSHA string `xorm:"VARCHAR(64)"`
55+
56+
ReviewID int64 `xorm:"index"`
57+
Invalidated bool
58+
59+
// Reference an issue or pull from another comment, issue or PR
60+
// All information is about the origin of the reference
61+
RefRepoID int64 `xorm:"index"` // Repo where the referencing
62+
RefIssueID int64 `xorm:"index"`
63+
RefCommentID int64 `xorm:"index"` // 0 if origin is Issue title or content (or PR's)
64+
RefAction references.XRefAction `xorm:"SMALLINT"` // What happens if RefIssueID resolves
65+
RefIsPull bool
66+
67+
CommentMetaData string `xorm:"JSON TEXT"` // put all non-index metadata in a single field
68+
}
69+
70+
type PullRequest struct {
71+
ID int64 `xorm:"pk autoincr"`
72+
Type int
73+
Status int
74+
ConflictedFiles []string `xorm:"TEXT JSON"`
75+
CommitsAhead int
76+
CommitsBehind int
77+
78+
ChangedProtectedFiles []string `xorm:"TEXT JSON"`
79+
80+
IssueID int64 `xorm:"INDEX"`
81+
Index int64
82+
83+
HeadRepoID int64 `xorm:"INDEX"`
84+
BaseRepoID int64 `xorm:"INDEX"`
85+
HeadBranch string
86+
BaseBranch string
87+
MergeBase string `xorm:"VARCHAR(64)"`
88+
AllowMaintainerEdit bool `xorm:"NOT NULL DEFAULT false"`
89+
90+
HasMerged bool `xorm:"INDEX"`
91+
MergedCommitID string `xorm:"VARCHAR(64)"`
92+
MergerID int64 `xorm:"INDEX"`
93+
MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"`
94+
95+
Flow int `xorm:"NOT NULL DEFAULT 0"`
96+
}
97+
98+
// Prepare and load the testing database
99+
x, deferable := base.PrepareTestEnv(t, 0, new(Comment), new(PullRequest))
100+
defer deferable()
101+
102+
assert.NoError(t, AddBeforeCommitIDForComment(x))
103+
}

models/packages/package_property.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type PackageProperty struct {
3232
RefType PropertyType `xorm:"INDEX NOT NULL"`
3333
RefID int64 `xorm:"INDEX NOT NULL"`
3434
Name string `xorm:"INDEX NOT NULL"`
35-
Value string `xorm:"TEXT NOT NULL"`
35+
Value string `xorm:"LONGTEXT NOT NULL"`
3636
}
3737

3838
// InsertProperty creates a property

models/system/notice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929
type Notice struct {
3030
ID int64 `xorm:"pk autoincr"`
3131
Type NoticeType
32-
Description string `xorm:"TEXT"`
32+
Description string `xorm:"LONGTEXT"`
3333
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
3434
}
3535

0 commit comments

Comments
 (0)