| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- //go:build migrate
- package server
- import (
- "IotAdmin/common/database"
- "IotAdmin/core/config/source/file"
- "IotAdmin/core/sdk/config"
- "IotAdmin/migration"
- "fmt"
- _ "IotAdmin/migration/version"
- _ "IotAdmin/migration/version-local"
- "github.com/spf13/pflag"
- )
- var (
- generate = pflag.BoolP("generate", "g", false, "生成迁移文件")
- migrateFile = pflag.BoolP("file", "f", false, "生成IotAdmin迁移文件")
- domain = pflag.StringP("domain", "d", "*", "选择租户域名")
- )
- func init() {
- if *generate {
- fmt.Println(`生成迁移文件`)
- } else {
- fmt.Println(`开始迁移数据库`)
- //1. 读取配置
- config.Setup(
- file.NewSource(file.WithPath(*configYml)),
- database.Setup,
- )
- }
- }
- func Init() {
- if *generate {
- err := migration.GenFile(*migrateFile)
- if err != nil {
- return
- }
- } else {
- // 数据库迁移
- fmt.Println("数据库迁移开始")
- err := migration.MigrateModel(*domain)
- if err != nil {
- fmt.Println(`数据库基础数据初始化失败`, err.Error())
- return
- }
- fmt.Println(`数据库基础数据初始化成功`)
- }
- }
|