add database reset flag
This commit is contained in:
parent
bf34abf5f8
commit
3aeda54404
2 changed files with 18 additions and 7 deletions
8
main.go
8
main.go
|
@ -25,7 +25,9 @@ var migrations embed.FS
|
|||
var conf config.Config
|
||||
|
||||
func main() {
|
||||
isserver := flag.Bool("server", false, "Run as Server")
|
||||
isServer := flag.Bool("server", false, "Run as Server")
|
||||
resetDB := flag.Bool("reset-db", false, "Reset DB")
|
||||
|
||||
flag.Parse()
|
||||
confPath := "config.toml"
|
||||
_, err := os.Stat(confPath)
|
||||
|
@ -48,9 +50,9 @@ func main() {
|
|||
conf.Worker.TempDir = "/tmp"
|
||||
}
|
||||
|
||||
if *isserver {
|
||||
if *isServer {
|
||||
slog.Info("Starting Server...")
|
||||
server.Start(conf, templates, static, migrations)
|
||||
server.Start(conf, templates, static, migrations, *resetDB)
|
||||
} else {
|
||||
slog.Info("Starting Worker...")
|
||||
worker.Start(conf)
|
||||
|
|
|
@ -33,7 +33,7 @@ func sub(a, b int) int {
|
|||
|
||||
var db *pgxpool.Pool
|
||||
|
||||
func Start(_conf config.Config, tmplFS embed.FS, staticFS embed.FS, migrationsFS embed.FS) {
|
||||
func Start(_conf config.Config, tmplFS embed.FS, staticFS embed.FS, migrationsFS embed.FS, resetDB bool) {
|
||||
conf = _conf
|
||||
|
||||
// Static Files
|
||||
|
@ -70,6 +70,15 @@ func Start(_conf config.Config, tmplFS embed.FS, staticFS embed.FS, migrationsFS
|
|||
return
|
||||
}
|
||||
|
||||
if resetDB {
|
||||
slog.Info("Running Down Migrations...")
|
||||
err = m.Down()
|
||||
if err != nil {
|
||||
slog.Error("Unable to Migrate Down", "err", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
//err = m.Down()
|
||||
err = m.Up()
|
||||
if err == migrate.ErrNoChange {
|
||||
|
@ -95,10 +104,10 @@ func Start(_conf config.Config, tmplFS embed.FS, staticFS embed.FS, migrationsFS
|
|||
server := &http.Server{
|
||||
Addr: conf.Server.Address,
|
||||
Handler: mux,
|
||||
ReadTimeout: 1 * time.Second,
|
||||
WriteTimeout: 1 * time.Second,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
IdleTimeout: 30 * time.Second,
|
||||
ReadHeaderTimeout: 2 * time.Second,
|
||||
ReadHeaderTimeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
serverClose := make(chan bool)
|
||||
|
|
Loading…
Add table
Reference in a new issue