photoprism/internal/migrate/options.go
Michael Mayer e3bb8b19dd Routing: Prefix frontend UI routes with /library #840 #2466
Also improves migrations and updates the db schema docs.

Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-15 21:54:11 +02:00

52 lines
1.1 KiB
Go

package migrate
// Options represents migration selection options.
type Options struct {
AutoMigrate bool
RunStage string
RunFailed bool
Migrations []string
DropDeprecated bool
}
// Opt returns migration options based on the specified parameters.
func Opt(runFailed bool, ids []string) Options {
runAll := len(ids) == 0
return Options{
AutoMigrate: runAll,
RunStage: StageMain,
RunFailed: runFailed,
Migrations: ids,
DropDeprecated: runAll,
}
}
// Stage returns options for the specified migration stage.
func (opt Options) Stage(name string) Options {
if name == "" {
return opt
}
return Options{
AutoMigrate: false,
RunStage: name,
RunFailed: opt.RunFailed,
Migrations: opt.Migrations,
DropDeprecated: opt.DropDeprecated,
}
}
// Pre returns options for the pre-migration stage.
func (opt Options) Pre() Options {
return opt.Stage(StagePre)
}
// StageName returns the stage name.
func (opt Options) StageName() string {
if opt.RunStage == "" {
return StageMain
} else {
return opt.RunStage
}
}