Skip to content

Commit 0806da7

Browse files
committed
add missing file
1 parent 8b4e077 commit 0806da7

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
)
11+
12+
func TestMain(m *testing.M) {
13+
base.MainTest(m)
14+
}

models/migrations/v1_25/v321.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+
x.Exec("UPDATE comment SET before_commit_id = (SELECT merge_base FROM pull_request WHERE pull_request.issue_id = comment.issue_id) WHERE before_commit_id IS NULL")
27+
return nil
28+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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_AddCombinedIndexToIssueUser(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+
// Prepare and load the testing database
71+
x, deferable := base.PrepareTestEnv(t, 0, new(Comment))
72+
defer deferable()
73+
74+
assert.NoError(t, AddBeforeCommitIDForComment(x))
75+
}

0 commit comments

Comments
 (0)