mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 02:04:09 +00:00
@@ -1,14 +1,14 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cast"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var Migrate = &Migration{
|
||||
@@ -40,11 +40,12 @@ func (e *Migration) Migrate() {
|
||||
for k := range e.version {
|
||||
versions = append(versions, k)
|
||||
}
|
||||
sort.IntsAreSorted(versions)
|
||||
if !sort.IntsAreSorted(versions) {
|
||||
sort.Ints(versions)
|
||||
}
|
||||
var err error
|
||||
var count int64
|
||||
for _, v := range versions {
|
||||
fmt.Println(v)
|
||||
err = e.db.Debug().Table("sys_migration").Where("version = ?", v).Count(&count).Error
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package version_local
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
/**
|
||||
开发者项目的迁移脚本放在这个目录里,init写法参考version目录里的migrate或者自动生成
|
||||
*/
|
||||
@@ -1,6 +1,7 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models/system"
|
||||
"runtime"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -20,7 +21,7 @@ func _1599190683659Tables(db *gorm.DB, version string) error {
|
||||
err := db.Debug().Migrator().AutoMigrate(
|
||||
new(models.CasbinRule),
|
||||
new(models.SysDept),
|
||||
new(models.SysConfig),
|
||||
new(system.SysConfig),
|
||||
new(tools.SysTables),
|
||||
new(tools.SysColumns),
|
||||
new(models.Menu),
|
||||
@@ -34,7 +35,7 @@ func _1599190683659Tables(db *gorm.DB, version string) error {
|
||||
new(models.DictData),
|
||||
new(models.DictType),
|
||||
new(models.SysJob),
|
||||
new(models.SysConfig),
|
||||
new(system.SysConfig),
|
||||
new(models.SysSetting),
|
||||
new(models.SysFileDir),
|
||||
new(models.SysFileInfo),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models/system"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
@@ -260,7 +261,7 @@ func _1599190683670Test(db *gorm.DB, version string) error {
|
||||
{DeptId: 10, ParentId: 1, DeptPath: "/0/1/10", DeptName: "人力资源", Sort: 3, Leader: "aituo", Phone: "13782218188", Email: "atuo@aituo.com", Status: "1", CreateBy: "1", UpdateBy: "1", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||
}
|
||||
|
||||
list4 := []models.SysConfig{
|
||||
list4 := []system.SysConfig{
|
||||
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: gorm.DeletedAt{}}, ControlBy: common.ControlBy{CreateBy: 1, UpdateBy: 1}, ConfigName: "主框架页-默认皮肤样式名称", ConfigKey: "sys_index_skinName", ConfigValue: "skin-blue", ConfigType: "Y", Remark: "蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow"},
|
||||
{Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: gorm.DeletedAt{}}, ControlBy: common.ControlBy{CreateBy: 1, UpdateBy: 1}, ConfigName: "用户管理-账号初始密码", ConfigKey: "sys.user.initPassword", ConfigValue: "123456", ConfigType: "Y", Remark: "初始化密码 123456"},
|
||||
{Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: gorm.DeletedAt{}}, ControlBy: common.ControlBy{CreateBy: 1, UpdateBy: 1}, ConfigName: "主框架页-侧边栏主题", ConfigKey: "sys_index_sideTheme", ConfigValue: "theme-dark", ConfigType: "Y", Remark: "深色主题theme-dark,浅色主题theme-light"},
|
||||
|
||||
@@ -2,6 +2,7 @@ package version
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/app/admin/models/system"
|
||||
"gorm.io/gorm"
|
||||
"runtime"
|
||||
|
||||
@@ -16,14 +17,16 @@ func init() {
|
||||
|
||||
func _1602644950000Test(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
err := db.Migrator().RenameColumn(&models.SysConfig{}, "config_id", "id")
|
||||
if err != nil {
|
||||
return err
|
||||
if tx.Migrator().HasColumn(&system.SysConfig{}, "config_id") {
|
||||
err := tx.Migrator().RenameColumn(&system.SysConfig{}, "config_id", "id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
list2 := []models.CasbinRule{
|
||||
{PType: "p", V0: "admin", V1: "/api/v1/config", V2: "GET"},
|
||||
}
|
||||
err = tx.Create(list2).Error
|
||||
err := tx.Create(list2).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -34,7 +37,7 @@ func _1602644950000Test(db *gorm.DB, version string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return db.Create(&common.Migration{
|
||||
return tx.Create(&common.Migration{
|
||||
Version: version,
|
||||
}).Error
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user