fix(revision): Increase content field size in revision entity

Modified the "content" field in the "revision_entity.go" file from 'TEXT' to 'MEDIUMTEXT'. Added a new migration file "v14.go" to handle the transition of the database 'content' field to 'MEDIUMTEXT'. Also adapted the 'command.go' and 'migrations.go' files to handle the new migration. These changes were necessary to accommodate larger revision content sizes.
This commit is contained in:
LinkinStars 2023-07-31 15:04:32 +08:00
parent aa606ed01a
commit 4004c0b674
4 changed files with 40 additions and 4 deletions

View File

@ -114,7 +114,7 @@ To run answer, use:
fmt.Println("read config failed: ", err.Error())
return
}
if err = migrations.Migrate(c.Data.Database, c.Data.Cache, upgradeVersion); err != nil {
if err = migrations.Migrate(c.Debug, c.Data.Database, c.Data.Cache, upgradeVersion); err != nil {
fmt.Println("migrate failed: ", err.Error())
return
}

View File

@ -24,7 +24,7 @@ type Revision struct {
ObjectType int `xorm:"not null default 0 INT(11) object_type"`
ObjectID string `xorm:"not null default 0 BIGINT(20) INDEX object_id"`
Title string `xorm:"not null default '' VARCHAR(255) title"`
Content string `xorm:"not null TEXT content"`
Content string `xorm:"not null MEDIUMTEXT content"`
Log string `xorm:"VARCHAR(255) log"`
Status int `xorm:"not null default 1 INT(11) status"`
ReviewUserID int64 `xorm:"not null default 0 BIGINT(20) review_user_id"`

View File

@ -70,6 +70,7 @@ var migrations = []Migration{
NewMigration("v1.1.0-beta.1", "update user pin hide features", updateRolePinAndHideFeatures, true),
NewMigration("v1.1.0-beta.2", "update question post time", updateQuestionPostTime, true),
NewMigration("v1.1.0", "add gravatar base url", updateCount, true),
NewMigration("v1.1.1", "update the length of revision content", updateTheLengthOfRevisionContent, false),
}
func GetMigrations() []Migration {
@ -103,12 +104,12 @@ func ExpectedVersion() int64 {
}
// Migrate database to current version
func Migrate(dbConf *data.Database, cacheConf *data.CacheConf, upgradeToSpecificVersion string) error {
func Migrate(debug bool, dbConf *data.Database, cacheConf *data.CacheConf, upgradeToSpecificVersion string) error {
cache, cacheCleanup, err := data.NewCache(cacheConf)
if err != nil {
fmt.Println("new check failed:", err.Error())
}
engine, err := data.NewDB(false, dbConf)
engine, err := data.NewDB(debug, dbConf)
if err != nil {
fmt.Println("new database failed: ", err.Error())
return err

View File

@ -0,0 +1,35 @@
package migrations
import (
"context"
"time"
"xorm.io/xorm/schemas"
"xorm.io/xorm"
)
func updateTheLengthOfRevisionContent(ctx context.Context, x *xorm.Engine) (err error) {
sess := x.Context(ctx)
if x.Dialect().URI().DBType == schemas.MYSQL {
_, err = sess.Exec("ALTER TABLE `revision` CHANGE `content` `content` MEDIUMTEXT NOT NULL;")
}
return err
}
type RevisionV14 struct {
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
UserID string `xorm:"not null default 0 BIGINT(20) user_id"`
ObjectType int `xorm:"not null default 0 INT(11) object_type"`
ObjectID string `xorm:"not null default 0 BIGINT(20) INDEX object_id"`
Title string `xorm:"not null default '' VARCHAR(255) title"`
Content string `xorm:"not null MEDIUMTEXT content"`
Log string `xorm:"VARCHAR(255) log"`
Status int `xorm:"not null default 1 INT(11) status"`
ReviewUserID int64 `xorm:"not null default 0 BIGINT(20) review_user_id"`
}
func (RevisionV14) TableName() string {
return "revision"
}