photoprism/internal/commands/migrate.go
Vedhavyas Singareddi 38b9889ef2 Add context for graceful shutdown #112
see pull request #114
2019-06-03 22:58:15 +02:00

40 lines
755 B
Go

package commands
import (
"context"
"time"
"github.com/photoprism/photoprism/internal/config"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
// Automatically migrates / initializes database
var MigrateCommand = cli.Command{
Name: "migrate",
Usage: "Automatically migrates / initializes database",
Action: migrateAction,
}
func migrateAction(ctx *cli.Context) error {
start := time.Now()
conf := config.NewConfig(ctx)
cctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := conf.Init(cctx); err != nil {
return err
}
log.Infoln("migrating database")
conf.MigrateDb()
elapsed := time.Since(start)
log.Infof("database migration completed in %s", elapsed)
conf.Shutdown()
return nil
}