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