From 02255240fe56ef4e3eed01ab57a83c1c808c17f8 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Tue, 21 Apr 2020 13:44:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/migrate/server.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/migrate/server.go b/cmd/migrate/server.go index 5fe34199..db9511ad 100644 --- a/cmd/migrate/server.go +++ b/cmd/migrate/server.go @@ -9,6 +9,7 @@ import ( tools2 "go-admin/models/tools" "go-admin/tools" config2 "go-admin/tools/config" + "log" "github.com/spf13/cobra" ) @@ -41,8 +42,17 @@ func run() { database.Setup() //4. 数据库迁移 gorm.AutoMigrate(orm.Eloquent) - //db := gdb.GetDB() - //db.AutoMigrate(migrateModel()...) + log.Println("数据库结构初始化成功!") + //5. 数据初始化完成 + if config2.ApplicationConfig.IsInit { + if err := models.InitDb(); err != nil { + log.Fatal("数据库基础数据初始化失败!") + } else { + config2.SetApplicationIsInit() + } + log.Println("数据库基础数据初始化成功!") + } + usage = `finish` fmt.Println(usage) }