2017-05-27 17:53:35 +08:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2018-01-26 17:17:38 +08:00
|
|
|
"time"
|
2021-03-23 15:09:17 +08:00
|
|
|
|
2021-03-26 11:34:02 +08:00
|
|
|
"github.com/beego/beego/v2/client/orm"
|
2021-03-23 15:09:17 +08:00
|
|
|
"github.com/mindoc-org/mindoc/conf"
|
2017-05-27 17:53:35 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type Migration struct {
|
2018-01-26 17:17:38 +08:00
|
|
|
MigrationId int `orm:"column(migration_id);pk;auto;unique;" json:"migration_id"`
|
|
|
|
Name string `orm:"column(name);size(500)" json:"name"`
|
|
|
|
Statements string `orm:"column(statements);type(text);null" json:"statements"`
|
|
|
|
Status string `orm:"column(status);default(update)" json:"status"`
|
|
|
|
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
|
|
|
Version int64 `orm:"type(bigint);column(version);unique" json:"version"`
|
2017-05-27 17:53:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TableName 获取对应数据库表名.
|
|
|
|
func (m *Migration) TableName() string {
|
|
|
|
return "migrations"
|
|
|
|
}
|
|
|
|
|
|
|
|
// TableEngine 获取数据使用的引擎.
|
|
|
|
func (m *Migration) TableEngine() string {
|
|
|
|
return "INNODB"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Migration) TableNameWithPrefix() string {
|
|
|
|
return conf.GetDatabasePrefix() + m.TableName()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMigration() *Migration {
|
|
|
|
return &Migration{}
|
|
|
|
}
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
func (m *Migration) FindFirst() (*Migration, error) {
|
2017-05-27 17:53:35 +08:00
|
|
|
o := orm.NewOrm()
|
|
|
|
|
|
|
|
err := o.QueryTable(m.TableNameWithPrefix()).OrderBy("-migration_id").One(m)
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
return m, err
|
|
|
|
}
|