Lunny Xiao 54fe47fbca
Change some columns from text to longtext and fix column wrong type caused by xorm (#35141)
This PR upgrade xorm to v1.3.10 which fixed a bug when both `longtext
json` tags in the struct field. The `longtext` will be ignored and
`json` will be considered as `text`.

A migration has been introduced to modify the column directly to
longtext. And another two columns should also be migrated from text to
longtext.

All these changes only affect mysql database because for other databases
Gitea supported, text is the same as longtext.

Fix #27244 
Fix #34764 
Fix #35042
2025-07-23 22:24:44 -07:00

53 lines
1.1 KiB
Go

// 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,
})
}