diff --git a/cmd/command.go b/cmd/command.go index e74cd636..3404ddfc 100644 --- a/cmd/command.go +++ b/cmd/command.go @@ -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 } diff --git a/internal/entity/revision_entity.go b/internal/entity/revision_entity.go index 34edc7f8..584a823e 100644 --- a/internal/entity/revision_entity.go +++ b/internal/entity/revision_entity.go @@ -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"` diff --git a/internal/migrations/migrations.go b/internal/migrations/migrations.go index 357aa786..ecfff1b7 100644 --- a/internal/migrations/migrations.go +++ b/internal/migrations/migrations.go @@ -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 diff --git a/internal/migrations/v14.go b/internal/migrations/v14.go new file mode 100644 index 00000000..e9f960b4 --- /dev/null +++ b/internal/migrations/v14.go @@ -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" +}