mirror of https://gitee.com/answerdev/answer.git
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:
parent
aa606ed01a
commit
4004c0b674
|
@ -114,7 +114,7 @@ To run answer, use:
|
||||||
fmt.Println("read config failed: ", err.Error())
|
fmt.Println("read config failed: ", err.Error())
|
||||||
return
|
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())
|
fmt.Println("migrate failed: ", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Revision struct {
|
||||||
ObjectType int `xorm:"not null default 0 INT(11) object_type"`
|
ObjectType int `xorm:"not null default 0 INT(11) object_type"`
|
||||||
ObjectID string `xorm:"not null default 0 BIGINT(20) INDEX object_id"`
|
ObjectID string `xorm:"not null default 0 BIGINT(20) INDEX object_id"`
|
||||||
Title string `xorm:"not null default '' VARCHAR(255) title"`
|
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"`
|
Log string `xorm:"VARCHAR(255) log"`
|
||||||
Status int `xorm:"not null default 1 INT(11) status"`
|
Status int `xorm:"not null default 1 INT(11) status"`
|
||||||
ReviewUserID int64 `xorm:"not null default 0 BIGINT(20) review_user_id"`
|
ReviewUserID int64 `xorm:"not null default 0 BIGINT(20) review_user_id"`
|
||||||
|
|
|
@ -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.1", "update user pin hide features", updateRolePinAndHideFeatures, true),
|
||||||
NewMigration("v1.1.0-beta.2", "update question post time", updateQuestionPostTime, 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.0", "add gravatar base url", updateCount, true),
|
||||||
|
NewMigration("v1.1.1", "update the length of revision content", updateTheLengthOfRevisionContent, false),
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMigrations() []Migration {
|
func GetMigrations() []Migration {
|
||||||
|
@ -103,12 +104,12 @@ func ExpectedVersion() int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate database to current version
|
// 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)
|
cache, cacheCleanup, err := data.NewCache(cacheConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("new check failed:", err.Error())
|
fmt.Println("new check failed:", err.Error())
|
||||||
}
|
}
|
||||||
engine, err := data.NewDB(false, dbConf)
|
engine, err := data.NewDB(debug, dbConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("new database failed: ", err.Error())
|
fmt.Println("new database failed: ", err.Error())
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
Loading…
Reference in New Issue