mirror of
https://github.com/ZSCNetSupportDept/scheduler.git
synced 2025-10-28 20:45:05 +08:00
数据库AutoMigrate现在是可选的,添加了启动参数
This commit is contained in:
@@ -25,6 +25,7 @@ func Load() {
|
||||
}
|
||||
|
||||
func readconfig() {
|
||||
viper.SetConfigFile(pathToConfigure)
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
fmt.Printf("Error reading config file: %v\n", err)
|
||||
os.Exit(1)
|
||||
@@ -36,8 +37,9 @@ func readconfig() {
|
||||
|
||||
func parseArgs() {
|
||||
pflag.String("config", "./config.yaml", "the path to config file.")
|
||||
pflag.Bool("init-db", false, "whether to initialize the database,useful when migrating to a new one.")
|
||||
viper.BindPFlags(pflag.CommandLine)
|
||||
pflag.Parse()
|
||||
pathToConfigure = viper.GetString("config")
|
||||
viper.SetConfigFile(pathToConfigure)
|
||||
InitDB = viper.GetBool("init-db")
|
||||
}
|
||||
|
||||
@@ -24,3 +24,4 @@ type Config struct {
|
||||
|
||||
var pathToConfigure string
|
||||
var Default Config
|
||||
var InitDB bool
|
||||
|
||||
@@ -33,9 +33,10 @@ func connectSQLite() {
|
||||
fmt.Printf("error in connecting to SQLite:")
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
|
||||
}
|
||||
if config.InitDB == true {
|
||||
Main.AutoMigrate(&model.Member{}, &model.Tweak{})
|
||||
}
|
||||
}
|
||||
|
||||
func connectPGSQL() {
|
||||
@@ -43,5 +44,7 @@ func connectPGSQL() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if config.InitDB == true {
|
||||
Main.AutoMigrate(&model.Member{}, &model.Tweak{})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user