更新migrate 更名为init
This commit is contained in:
1 parent
e35efac419
commit
130a5feb72
5 files changed
+27
-29
No files matched your search
@@ -134,7 +134,7 @@ vi ./config/setting.yml
|
||||
### 初始化数据库,以及服务启动
|
||||
```
|
||||
# 首次配置需要初始化数据库资源信息
|
||||
./go-admin migrate -c config/settings.yml -m dev
|
||||
./go-admin init -c config/settings.yml -m dev
|
||||
|
||||
|
||||
# 启动项目,也可以用IDE进行调试
|
||||
|
||||
+6
-1
@@ -10,6 +10,7 @@ import (
|
||||
"go-admin/router"
|
||||
"go-admin/tools"
|
||||
config2 "go-admin/tools/config"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -76,7 +77,11 @@ func run() error {
|
||||
log.Fatalf("listen: %s\n", err)
|
||||
}
|
||||
}()
|
||||
log.Println("Server Run ", config2.ApplicationConfig.Host+":"+config2.ApplicationConfig.Port)
|
||||
content, _ := ioutil.ReadFile("./static/go-admin.txt")
|
||||
log.Println(string(content))
|
||||
log.Println("Server Run http://127.0.0.1:"+config2.ApplicationConfig.Port+"/")
|
||||
log.Println("Swagger URL http://127.0.0.1:"+config2.ApplicationConfig.Port+"/swagger/index.html")
|
||||
|
||||
log.Println("Enter Control + C Shutdown Server")
|
||||
// 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间)
|
||||
quit := make(chan os.Signal)
|
||||
|
||||
+5
-23
@@ -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)
|
||||
}
|
||||
@@ -4,13 +4,9 @@ import (
|
||||
"github.com/jinzhu/gorm"
|
||||
"go-admin/models"
|
||||
"go-admin/models/tools"
|
||||
config2 "go-admin/tools/config"
|
||||
)
|
||||
|
||||
func AutoMigrate(db *gorm.DB) error {
|
||||
if config2.DatabaseConfig.Dbtype == "mysql" {
|
||||
db = db.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4")
|
||||
}
|
||||
db.SingularTable(true)
|
||||
return db.AutoMigrate(
|
||||
new(models.CasbinRule),
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
____
|
||||
,---, ,' , `. ,--,
|
||||
,---. ,---,. ,---.'| ,-+-,.' _ |,--.'| ,---,
|
||||
,----._,. ' ,'\ ,' .' | | | : ,-+-. ; , ||| |, ,-+-. / |
|
||||
/ / ' / / / |,---.' , ,--.--. | | | ,--.'|' | ||`--'_ ,--.'|' |
|
||||
| : |. ; ,. :| | |/ \ ,--.__| || | ,', | |,,' ,'| | | ,"' |
|
||||
| | .\ .' | |: :: : .'.--. .-. | / ,' || | / | |--' ' | | | | / | |
|
||||
. ; '; |' | .; :: |.' \__\/: . .. ' / || : | | , | | : | | | | |
|
||||
' . . || : |`---' ," .--.; |' ; |: || : | |/ ' : |__ | | | |/
|
||||
`---`-'| | \ \ / / / ,. || | '/ '| | |`-' | | '.'|| | |--'
|
||||
.'__/\_: | `----' ; : .' \ : :|| ;/ ; : ;| |/
|
||||
| : : | , .-./\ \ / '---' | , / '---'
|
||||
\ \ / `--`---' `----' ---`-'
|
||||
`--`-'
|
||||
Reference in new issue
Block a user