@@ -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}
0 commit comments