fix:优化代码

This commit is contained in:
zhangwenjian
2021-02-19 10:48:27 +08:00
parent 981e992f28
commit 9186c6ce04
5 changed files with 62 additions and 12 deletions
@@ -24,13 +24,13 @@ func _1599190683659Tables(db *gorm.DB, version string) error {
new(system.SysConfig),
new(tools.SysTables),
new(tools.SysColumns),
new(models.Menu),
new(models.SysMenu),
new(system.SysLoginLog),
new(system.SysOperaLog),
new(models.RoleMenu),
new(models.SysRoleDept),
new(models.SysUser),
new(models.SysRole),
new(system.SysRole),
new(models.Post),
new(models.DictData),
new(models.DictType),
@@ -20,7 +20,7 @@ func _1600089797118Migrate(db *gorm.DB, version string) error {
f := &models.SysFileDir{
Label: "根目录",
PId: 0,
//Sort: "0",
Sort: "0",
Path: "",
ControlBy: common.ControlBy{
CreateBy: 1,
@@ -0,0 +1,50 @@
package version
import (
"go-admin/app/admin/models"
"go-admin/app/admin/models/system"
//"go-admin/app/admin/models"
"gorm.io/gorm"
"runtime"
"go-admin/cmd/migrate/migration"
common "go-admin/common/models"
)
func init() {
_, fileName, _, _ := runtime.Caller(0)
migration.Migrate.SetVersion(migration.GetFilename(fileName), _1613638159444Test)
}
func _1613638159444Test(db *gorm.DB, version string) error {
return db.Transaction(func(tx *gorm.DB) error {
// TODO: 这里开始写入要变更的内容
// TODO: 例如 修改表字段 使用过程中请删除此段代码
err := tx.Migrator().AlterColumn(&system.SysRole{}, "create_by")
if err != nil {
return err
}
err = tx.Migrator().AlterColumn(&system.SysRole{}, "update_by")
if err != nil {
return err
}
err = tx.Migrator().AlterColumn(&models.SysMenu{}, "update_by")
if err != nil {
return err
}
err = tx.Migrator().AlterColumn(&models.SysMenu{}, "create_by")
if err != nil {
return err
}
return tx.Create(&common.Migration{
Version: version,
}).Error
})
}