photoprism/internal/migrate/auto.go
Michael Mayer a61470dfc7 Migrations: Implement "photoprism migrations ls" command #2216
Lists the status of migrations. Changed "migrate" to "migrations run".
2022-04-01 16:02:58 +02:00

32 lines
726 B
Go

package migrate
import (
"fmt"
"github.com/jinzhu/gorm"
)
// Auto automatically migrates the schema of the database passed as argument.
func Auto(db *gorm.DB, runFailed bool, ids []string) error {
if db == nil {
return fmt.Errorf("migrate: database connection required")
}
name := db.Dialect().GetName()
if name == "" {
return fmt.Errorf("migrate: database has no dialect name")
}
if err := db.AutoMigrate(&Migration{}).Error; err != nil {
return fmt.Errorf("migrate: %s (create migrations table)", err)
}
if migrations, ok := Dialects[name]; ok && len(migrations) > 0 {
migrations.Start(db, runFailed, ids)
return nil
} else {
return fmt.Errorf("migrate: no migrations found for %s", name)
}
}