mindoc/models/migrations.go

42 lines
1.1 KiB
Go
Raw Normal View History

2017-05-27 17:53:35 +08:00
package models
import (
"time"
2017-06-14 09:23:29 +08:00
"github.com/lifei6671/mindoc/conf"
2017-05-27 17:53:35 +08:00
"github.com/astaxie/beego/orm"
)
type Migration struct {
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"`
}
// 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{}
}
func (m *Migration) FindFirst() (*Migration,error) {
o := orm.NewOrm()
err := o.QueryTable(m.TableNameWithPrefix()).OrderBy("-migration_id").One(m)
return m,err
}