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:
33
migrations/common/custom_pre.go
Normal file
33
migrations/common/custom_pre.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user