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

26 lines
587 B
Go
Raw Normal View History

2020-10-16 17:11:14 +03:00
package common
import (
"github.com/emvi/logbuch"
2020-10-16 17:11:14 +03:00
"github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
"gorm.io/gorm"
2020-10-16 17:11:14 +03:00
)
func MigrateLanguages(db *gorm.DB) {
cfg := config.Get()
for k, v := range cfg.App.CustomLanguages {
result := db.Model(models.Heartbeat{}).
Where("language = ?", "").
Where("entity LIKE ?", "%."+k).
Updates(models.Heartbeat{Language: v})
if result.Error != nil {
logbuch.Fatal(result.Error.Error())
2020-10-16 17:11:14 +03:00
}
if result.RowsAffected > 0 {
logbuch.Info("migrated %+v rows for custom language %+s", result.RowsAffected, k)
2020-10-16 17:11:14 +03:00
}
}
}