2018-09-24 07:53:16 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-06-03 20:58:15 +00:00
|
|
|
"context"
|
2019-05-14 14:04:17 +00:00
|
|
|
"time"
|
|
|
|
|
2019-05-06 21:18:10 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2018-09-24 07:53:16 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2020-02-18 22:42:51 +00:00
|
|
|
// MigrateCommand is used to register the migrate cli command
|
2018-09-24 07:53:16 +00:00
|
|
|
var MigrateCommand = cli.Command{
|
2018-09-27 06:59:53 +00:00
|
|
|
Name: "migrate",
|
2020-12-17 17:24:55 +00:00
|
|
|
Usage: "Initializes the index database if needed",
|
2018-09-24 07:53:16 +00:00
|
|
|
Action: migrateAction,
|
|
|
|
}
|
|
|
|
|
2020-12-11 12:52:34 +00:00
|
|
|
// migrateAction initializes and migrates the database.
|
2018-11-17 05:21:39 +00:00
|
|
|
func migrateAction(ctx *cli.Context) error {
|
2019-05-14 14:04:17 +00:00
|
|
|
start := time.Now()
|
|
|
|
|
2019-05-06 21:18:10 +00:00
|
|
|
conf := config.NewConfig(ctx)
|
2020-10-08 06:52:03 +00:00
|
|
|
|
|
|
|
_, cancel := context.WithCancel(context.Background())
|
2019-06-03 20:58:15 +00:00
|
|
|
defer cancel()
|
2020-10-08 06:52:03 +00:00
|
|
|
|
|
|
|
if err := conf.Init(); err != nil {
|
2019-06-03 20:58:15 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-09-24 07:53:16 +00:00
|
|
|
|
2019-05-02 12:10:05 +00:00
|
|
|
log.Infoln("migrating database")
|
2018-09-24 07:53:16 +00:00
|
|
|
|
2020-04-30 18:07:03 +00:00
|
|
|
conf.InitDb()
|
2018-09-24 07:53:16 +00:00
|
|
|
|
2019-05-14 14:04:17 +00:00
|
|
|
elapsed := time.Since(start)
|
|
|
|
|
|
|
|
log.Infof("database migration completed in %s", elapsed)
|
2018-09-24 07:53:16 +00:00
|
|
|
|
2019-05-06 21:18:10 +00:00
|
|
|
conf.Shutdown()
|
2019-05-04 15:34:51 +00:00
|
|
|
|
2018-09-24 07:53:16 +00:00
|
|
|
return nil
|
|
|
|
}
|