Skip to content

Commit 6c998e6

Browse files
committed
more columns needs longtext
1 parent 82b2d4b commit 6c998e6

File tree

5 files changed

+65
-12
lines changed

5 files changed

+65
-12
lines changed

models/migrations/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func prepareMigrationTasks() []*migration {
385385
newMigration(320, "Migrate two_factor_policy to login_source table", v1_24.MigrateSkipTwoFactor),
386386

387387
// Gitea 1.24.0 ends at database version 321
388-
newMigration(321, "Fix review_state.updated_files column", v1_25.FixReviewStateUpdatedFilesColumn),
388+
newMigration(321, "Use LONGTEXT for some columns and fix review_state.updated_files column", v1_25.UseLongTextInSomeColumnsAndFixBugs),
389389
}
390390
return preparedMigrations
391391
}

models/migrations/v1_25/v321.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,42 @@ import (
1111
"xorm.io/xorm/schemas"
1212
)
1313

14-
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
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
1717
}
1818

19-
return base.ModifyColumn(x, "review_state", &schemas.Column{
19+
if err := base.ModifyColumn(x, "review_state", &schemas.Column{
2020
Name: "updated_files",
2121
SQLType: schemas.SQLType{
2222
Name: "LONGTEXT",
2323
},
2424
Length: 0,
2525
Nullable: false,
2626
DefaultIsEmpty: true,
27+
}); err != nil {
28+
return err
29+
}
30+
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 {
40+
return err
41+
}
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,
2751
})
2852
}

models/migrations/v1_25/v321_test.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"github.com/stretchr/testify/assert"
1414
)
1515

16-
func Test_FixReviewStateUpdatedFilesColumn(t *testing.T) {
17-
if setting.Database.Type == "sqlite3" {
18-
t.Skip("SQLite does not support modify column type")
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")
1919
}
2020

2121
type ReviewState struct {
@@ -27,16 +27,45 @@ func Test_FixReviewStateUpdatedFilesColumn(t *testing.T) {
2727
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
2828
}
2929

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+
}
37+
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"`
43+
}
44+
3045
// Prepare and load the testing database
31-
x, deferable := base.PrepareTestEnv(t, 0, new(ReviewState))
46+
x, deferable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
3247
defer deferable()
3348

34-
assert.NoError(t, FixReviewStateUpdatedFilesColumn(x))
49+
assert.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
3550

3651
tableInfo, err := x.TableInfo(&ReviewState{})
3752
assert.NoError(t, err)
3853
assert.NotNil(t, tableInfo)
3954
column := tableInfo.GetColumn("updated_files")
4055
assert.NotNil(t, column)
4156
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
57+
58+
tableInfo, err = x.TableInfo(&PackageProperty{})
59+
assert.NoError(t, err)
60+
assert.NotNil(t, tableInfo)
61+
column = tableInfo.GetColumn("value")
62+
assert.NotNil(t, column)
63+
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
64+
65+
tableInfo, err = x.TableInfo(&Notice{})
66+
assert.NoError(t, err)
67+
assert.NotNil(t, tableInfo)
68+
column = tableInfo.GetColumn("description")
69+
assert.NotNil(t, column)
70+
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
4271
}

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)