forked from ebhomengo/niki
feat(niki): add migrate flag to main for running migrations
This commit is contained in:
parent
659cba01d3
commit
02c16595b1
18
main.go
18
main.go
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/adapter/redis"
|
||||
"git.gocasts.ir/ebhomengo/niki/config"
|
||||
httpserver "git.gocasts.ir/ebhomengo/niki/delivery/http_server"
|
||||
|
@ -17,9 +19,17 @@ type Dependencies struct {
|
|||
initial.Services
|
||||
}
|
||||
|
||||
func parseFlags() bool {
|
||||
migrateFlag := flag.Bool("migrate", false, "perform database migration")
|
||||
flag.Parse()
|
||||
return *migrateFlag
|
||||
}
|
||||
|
||||
func main() {
|
||||
migrate := parseFlags()
|
||||
|
||||
cfg := config.C()
|
||||
db := initDatabase(cfg)
|
||||
db := initDatabase(cfg, migrate)
|
||||
redisAdapter := initRedis(cfg)
|
||||
|
||||
dependencies := initDependencies(cfg, redisAdapter, db)
|
||||
|
@ -68,8 +78,10 @@ func initAndRunServer(cfg config.Config, dependencies *Dependencies) {
|
|||
server.Serve()
|
||||
}
|
||||
|
||||
func initDatabase(cfg config.Config) *mysql.DB {
|
||||
migrateDatabase(cfg)
|
||||
func initDatabase(cfg config.Config, migrate bool) *mysql.DB {
|
||||
if migrate {
|
||||
migrateDatabase(cfg)
|
||||
}
|
||||
|
||||
return initial.InitMysql(cfg)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue