mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 02:04:09 +00:00
refactor🎨 : 系统登录日志和操作日志代码优化
This commit is contained in:
@@ -25,8 +25,8 @@ func _1599190683659Tables(db *gorm.DB, version string) error {
|
||||
new(tools.SysTables),
|
||||
new(tools.SysColumns),
|
||||
new(models.Menu),
|
||||
new(models.LoginLog),
|
||||
new(models.SysOperLog),
|
||||
new(system.SysLoginLog),
|
||||
new(system.SysOperaLog),
|
||||
new(models.RoleMenu),
|
||||
new(models.SysRoleDept),
|
||||
new(models.SysUser),
|
||||
|
||||
@@ -20,11 +20,6 @@ func init() {
|
||||
func _1599190683670Test(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
list1 := []models.RoleMenu{
|
||||
}
|
||||
list2 := []models.CasbinRule{
|
||||
}
|
||||
|
||||
list3 := []models.SysDept{
|
||||
{DeptId: 1, ParentId: 0, DeptPath: "/0/1", DeptName: "爱拓科技", Sort: 0, Leader: "aituo", Phone: "13782218188", Email: "atuo@aituo.com", Status: "0", CreateBy: "1", UpdateBy: "1", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||
{DeptId: 7, ParentId: 1, DeptPath: "/0/1/7", DeptName: "研发部", Sort: 1, Leader: "aituo", Phone: "13782218188", Email: "atuo@aituo.com", Status: "0", CreateBy: "1", UpdateBy: "1", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||
@@ -109,16 +104,7 @@ func _1599190683670Test(db *gorm.DB, version string) error {
|
||||
{2, "函数测试", "DEFAULT", 2, "0/5 * * * * ", "ExamplesOne", "参数", 1, 1, 1, 0, "", "", models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}, ""},
|
||||
}
|
||||
|
||||
err := tx.Create(list1).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tx.Create(list2).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Create(list3).Error
|
||||
err := tx.Create(list3).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models"
|
||||
//"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), _1603465014697Test)
|
||||
}
|
||||
|
||||
func _1603465014697Test(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
err := tx.Debug().Model(&models.Menu{}).Where("path = ?", "/api/v1/syscategoryList").Update("path", "/api/v1/syscategory").Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Create(&common.Migration{
|
||||
Version: version,
|
||||
}).Error
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-admin/app/admin/models/system"
|
||||
"go-admin/cmd/migrate/migration"
|
||||
common "go-admin/common/models"
|
||||
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func init() {
|
||||
_, fileName, _, _ := runtime.Caller(0)
|
||||
migration.Migrate.SetVersion(migration.GetFilename(fileName), _1603516925109Test)
|
||||
}
|
||||
|
||||
func _1603516925109Test(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
_ = tx.Migrator().RenameTable("sys_operlog", "sys_opera_log")
|
||||
_ = tx.Migrator().RenameTable("sys_loginlog", "sys_login_log")
|
||||
|
||||
if tx.Migrator().HasColumn(&system.SysLoginLog{}, "info_id") {
|
||||
err := tx.Migrator().RenameColumn(&system.SysLoginLog{}, "info_id", "id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if tx.Migrator().HasColumn(&system.SysOperaLog{}, "oper_id") {
|
||||
err := tx.Migrator().RenameColumn(&system.SysOperaLog{}, "oper_id", "id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return tx.Create(&common.Migration{
|
||||
Version: version,
|
||||
}).Error
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user