更新migrate 更名为init

This commit is contained in:
zhangwenjian committed 2020-05-01 20:13:46 +08:00
1 parent e35efac419
commit 130a5feb72
5 files changed
+27 -29

No files matched your search

+5 -23
View File
@@ -6,7 +6,6 @@ import (
orm "go-admin/database"
"go-admin/models"
"go-admin/models/gorm"
tools2 "go-admin/models/tools"
"go-admin/tools"
config2 "go-admin/tools/config"
"log"
@@ -18,8 +17,8 @@ var (
config string
mode string
StartCmd = &cobra.Command{
Use: "migrate",
Short: "migrate from struct to database",
Use: "init",
Short: "initialize the database",
Run: func(cmd *cobra.Command, args []string) {
run()
},
@@ -32,7 +31,7 @@ func init() {
}
func run() {
usage := `start migrate`
usage := `start init`
fmt.Println(usage)
//1. 读取配置
config2.ConfigSetup(config)
@@ -41,7 +40,7 @@ func run() {
//3. 初始化数据库链接
database.Setup()
//4. 数据库迁移
_ = gorm.AutoMigrate(orm.Eloquent)
_ = migrateModel()
log.Println("数据库结构初始化成功!")
//5. 数据初始化完成
if err := models.InitDb(); err != nil {
@@ -56,22 +55,5 @@ func migrateModel() error {
if config2.DatabaseConfig.Dbtype == "mysql" {
orm.Eloquent = orm.Eloquent.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4")
}
orm.Eloquent.SingularTable(true)
return orm.Eloquent.AutoMigrate(
new(models.CasbinRule),
new(tools2.SysTables),
new(tools2.SysColumns),
new(models.Dept),
new(models.Menu),
new(models.LoginLog),
new(models.SysOperLog),
new(models.RoleMenu),
new(models.SysRoleDept),
new(models.SysUser),
new(models.SysRole),
new(models.Post),
new(models.DictData),
new(models.SysConfig),
new(models.DictType),
).Error
return gorm.AutoMigrate(orm.Eloquent)
}