Skip to content

Commit 5daeee2

Browse files
committed
Fix test
1 parent 4b63a4d commit 5daeee2

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ package v1_25
55

66
import (
77
"code.gitea.io/gitea/models/migrations/base"
8+
"code.gitea.io/gitea/modules/setting"
89

910
"xorm.io/xorm"
1011
"xorm.io/xorm/schemas"
1112
)
1213

1314
func FixReviewStateUpdatedFilesColumn(x *xorm.Engine) error {
15+
if setting.Database.Type == "sqlite3" {
16+
return nil // SQLite does not support modify column type and the text type is already sufficient
17+
}
18+
1419
return base.ModifyColumn(x, "review_state", &schemas.Column{
1520
Name: "updated_files",
1621
SQLType: schemas.SQLType{
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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/setting"
11+
"code.gitea.io/gitea/modules/timeutil"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func Test_FixReviewStateUpdatedFilesColumn(t *testing.T) {
17+
if setting.Database.Type == "sqlite3" {
18+
t.Skip("SQLite does not support modify column type")
19+
}
20+
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+
}
29+
30+
// Prepare and load the testing database
31+
x, deferable := base.PrepareTestEnv(t, 0, new(ReviewState))
32+
defer deferable()
33+
34+
assert.NoError(t, FixReviewStateUpdatedFilesColumn(x))
35+
36+
tableInfo, err := x.TableInfo(&ReviewState{})
37+
assert.NoError(t, err)
38+
assert.NotNil(t, tableInfo)
39+
column := tableInfo.GetColumn("updated_files")
40+
assert.NotNil(t, column)
41+
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
42+
}

0 commit comments

Comments
 (0)