1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

refactor: migrate to latest gorm version

refactor: language mappings implementation
This commit is contained in:
Ferdinand Mütsch
2020-11-01 20:14:10 +01:00
parent 755cabb5f4
commit 8efc3854ab
36 changed files with 549 additions and 545 deletions

View File

@ -0,0 +1,33 @@
package common
import (
"github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
"gorm.io/gorm"
"log"
)
var customPreMigrations []migrationFunc
func init() {
customPreMigrations = []migrationFunc{
{
f: func(db *gorm.DB, cfg *config.Config) error {
if db.Migrator().HasTable("custom_rules") {
return db.Migrator().RenameTable("custom_rules", &models.LanguageMapping{})
}
return nil
},
name: "rename language mappings table",
},
}
}
func RunCustomPreMigrations(db *gorm.DB, cfg *config.Config) {
for _, m := range customPreMigrations {
log.Printf("running migration '%s'\n", m.name)
if err := m.f(db, cfg); err != nil {
log.Fatalf("migration '%s' failed %v\n", m.name, err)
}
}
}