2020-11-01 22:14:10 +03:00
|
|
|
|
package common
|
|
|
|
|
|
|
|
|
|
import (
|
2021-01-30 13:17:37 +03:00
|
|
|
|
"github.com/emvi/logbuch"
|
2020-11-01 22:14:10 +03:00
|
|
|
|
"github.com/muety/wakapi/config"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var customPostMigrations []migrationFunc
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
customPostMigrations = []migrationFunc{
|
|
|
|
|
{
|
|
|
|
|
f: func(db *gorm.DB, cfg *config.Config) error {
|
|
|
|
|
return cfg.GetFixturesFunc(cfg.Db.Dialect)(db)
|
|
|
|
|
},
|
|
|
|
|
name: "apply fixtures",
|
|
|
|
|
},
|
|
|
|
|
// TODO: add function to modify aggregated summaries according to configured custom language mappings
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RunCustomPostMigrations(db *gorm.DB, cfg *config.Config) {
|
|
|
|
|
for _, m := range customPostMigrations {
|
2021-01-30 13:17:37 +03:00
|
|
|
|
logbuch.Info("potentially running migration '%s'", m.name)
|
2020-11-01 22:14:10 +03:00
|
|
|
|
if err := m.f(db, cfg); err != nil {
|
2021-01-30 13:17:37 +03:00
|
|
|
|
logbuch.Fatal("migration '%s' failed – %v", m.name, err)
|
2020-11-01 22:14:10 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|