Skip to content

Change some columns from text to longtext and fix column wrong type caused by xorm #35141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ require (
mvdan.cc/xurls/v2 v2.6.0
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
xorm.io/builder v0.3.13
xorm.io/xorm v1.3.9
xorm.io/xorm v1.3.10
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -955,5 +955,5 @@ strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 h1:mUcz5b3
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251/go.mod h1:FJGmPh3vz9jSos1L/F91iAgnC/aejc0wIIrF2ZwJxdY=
xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo=
xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
xorm.io/xorm v1.3.9 h1:TUovzS0ko+IQ1XnNLfs5dqK1cJl1H5uHpWbWqAQ04nU=
xorm.io/xorm v1.3.9/go.mod h1:LsCCffeeYp63ssk0pKumP6l96WZcHix7ChpurcLNuMw=
xorm.io/xorm v1.3.10 h1:yR83hTT4mKIPyA/lvWFTzS35xjLwkiYnwdw0Qupeh0o=
xorm.io/xorm v1.3.10/go.mod h1:Lo7hmsFF0F0GbDE7ubX5ZKa+eCf0eCuiJAUG3oI5cxQ=
4 changes: 4 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/models/migrations/v1_22"
"code.gitea.io/gitea/models/migrations/v1_23"
"code.gitea.io/gitea/models/migrations/v1_24"
"code.gitea.io/gitea/models/migrations/v1_25"
"code.gitea.io/gitea/models/migrations/v1_6"
"code.gitea.io/gitea/models/migrations/v1_7"
"code.gitea.io/gitea/models/migrations/v1_8"
Expand Down Expand Up @@ -382,6 +383,9 @@ func prepareMigrationTasks() []*migration {
newMigration(318, "Add anonymous_access_mode for repo_unit", v1_24.AddRepoUnitAnonymousAccessMode),
newMigration(319, "Add ExclusiveOrder to Label table", v1_24.AddExclusiveOrderColumnToLabelTable),
newMigration(320, "Migrate two_factor_policy to login_source table", v1_24.MigrateSkipTwoFactor),

// Gitea 1.24.0 ends at database version 321
newMigration(321, "Use LONGTEXT for some columns and fix review_state.updated_files column", v1_25.UseLongTextInSomeColumnsAndFixBugs),
}
return preparedMigrations
}
Expand Down
14 changes: 14 additions & 0 deletions models/migrations/v1_25/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_25

import (
"testing"

"code.gitea.io/gitea/models/migrations/base"
)

func TestMain(m *testing.M) {
base.MainTest(m)
}
52 changes: 52 additions & 0 deletions models/migrations/v1_25/v321.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_25

import (
"code.gitea.io/gitea/models/migrations/base"
"code.gitea.io/gitea/modules/setting"

"xorm.io/xorm"
"xorm.io/xorm/schemas"
)

func UseLongTextInSomeColumnsAndFixBugs(x *xorm.Engine) error {
if !setting.Database.Type.IsMySQL() {
return nil // Only mysql need to change from text to long text, for other databases, they are the same
}

if err := base.ModifyColumn(x, "review_state", &schemas.Column{
Name: "updated_files",
SQLType: schemas.SQLType{
Name: "LONGTEXT",
},
Length: 0,
Nullable: false,
DefaultIsEmpty: true,
}); err != nil {
return err
}

if err := base.ModifyColumn(x, "package_property", &schemas.Column{
Name: "value",
SQLType: schemas.SQLType{
Name: "LONGTEXT",
},
Length: 0,
Nullable: false,
DefaultIsEmpty: true,
}); err != nil {
return err
}

return base.ModifyColumn(x, "notice", &schemas.Column{
Name: "description",
SQLType: schemas.SQLType{
Name: "LONGTEXT",
},
Length: 0,
Nullable: false,
DefaultIsEmpty: true,
})
}
70 changes: 70 additions & 0 deletions models/migrations/v1_25/v321_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_25

import (
"testing"

"code.gitea.io/gitea/models/migrations/base"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"

"github.com/stretchr/testify/assert"
)

func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
if !setting.Database.Type.IsMySQL() {
t.Skip("Only MySQL needs to change from TEXT to LONGTEXT")
}

type ReviewState struct {
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"NOT NULL UNIQUE(pull_commit_user)"`
PullID int64 `xorm:"NOT NULL INDEX UNIQUE(pull_commit_user) DEFAULT 0"` // Which PR was the review on?
CommitSHA string `xorm:"NOT NULL VARCHAR(64) UNIQUE(pull_commit_user)"` // Which commit was the head commit for the review?
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
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
}

type PackageProperty struct {
ID int64 `xorm:"pk autoincr"`
RefType int `xorm:"INDEX NOT NULL"`
RefID int64 `xorm:"INDEX NOT NULL"`
Name string `xorm:"INDEX NOT NULL"`
Value string `xorm:"TEXT NOT NULL"`
}

type Notice struct {
ID int64 `xorm:"pk autoincr"`
Type int
Description string `xorm:"LONGTEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
}

// Prepare and load the testing database
x, deferable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
defer deferable()

assert.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))

tables, err := x.DBMetas()
assert.NoError(t, err)

for _, table := range tables {
switch table.Name {
case "review_state":
column := table.GetColumn("updated_files")
assert.NotNil(t, column)
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
case "package_property":
column := table.GetColumn("value")
assert.NotNil(t, column)
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
case "notice":
column := table.GetColumn("description")
assert.NotNil(t, column)
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
}
}
}
2 changes: 1 addition & 1 deletion models/packages/package_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type PackageProperty struct {
RefType PropertyType `xorm:"INDEX NOT NULL"`
RefID int64 `xorm:"INDEX NOT NULL"`
Name string `xorm:"INDEX NOT NULL"`
Value string `xorm:"TEXT NOT NULL"`
Value string `xorm:"LONGTEXT NOT NULL"`
}

// InsertProperty creates a property
Expand Down
2 changes: 1 addition & 1 deletion models/system/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
type Notice struct {
ID int64 `xorm:"pk autoincr"`
Type NoticeType
Description string `xorm:"TEXT"`
Description string `xorm:"LONGTEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
}

Expand Down