mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 02:04:09 +00:00
修改数据表迁移用法
This commit is contained in:
@@ -3,9 +3,11 @@ package models
|
||||
import (
|
||||
orm "go-admin/common/global"
|
||||
"go-admin/tools"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type SysFileDir struct {
|
||||
gorm.Model
|
||||
Id int `json:"id" gorm:"type:int(11);primary_key;AUTO_INCREMENT"` //
|
||||
Label string `json:"label" gorm:"type:varchar(255);"` // 名称
|
||||
PId int `json:"pId" gorm:"type:int(11);"` // 父id
|
||||
@@ -16,7 +18,6 @@ type SysFileDir struct {
|
||||
Children []SysFileDir `json:"children" gorm:"-"`
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
func (SysFileDir) TableName() string {
|
||||
|
||||
@@ -41,7 +41,7 @@ func (e *Migration) Migrate() {
|
||||
var err error
|
||||
var count int64
|
||||
for _, v := range versions {
|
||||
err = e.db.Table("sys_migration").Where("version = ?", v).Count(&count).Error
|
||||
err = e.db.Debug().Table("sys_migration").Where("version = ?", v).Count(&count).Error
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func (e *Migration) Migrate() {
|
||||
count = 0
|
||||
continue
|
||||
}
|
||||
err = (e.version[v])(e.db, v)
|
||||
err = (e.version[v])(e.db.Debug(), v)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
@@ -18,9 +18,7 @@ func init() {
|
||||
}
|
||||
|
||||
func _1599190683659Tables(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
//
|
||||
err := tx.Migrator().AutoMigrate(
|
||||
err := db.Migrator().AutoMigrate(
|
||||
new(models.CasbinRule),
|
||||
new(models.SysDept),
|
||||
new(models.SysConfig),
|
||||
@@ -41,12 +39,12 @@ func _1599190683659Tables(db *gorm.DB, version string) error {
|
||||
new(models.SysSetting),
|
||||
new(models.SysFileDir),
|
||||
new(models.SysCategory),
|
||||
new(models.SysContent))
|
||||
new(models.SysContent),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Create(&common.Migration{
|
||||
return db.Create(&common.Migration{
|
||||
Version: version,
|
||||
}).Error
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user