photoprism/internal/migrate/options.go
Michael Mayer 74772aea97 Config: Always initialize fixtures, even when skipping migrations #3215
Signed-off-by: Michael Mayer <michael@photoprism.app>
2023-02-21 04:44:08 +01: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(runAll, runFailed bool, ids []string) Options {
runAll = len(ids) == 0 && (runAll || runFailed)
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
}
}