2020-10-16 17:11:14 +03:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/muety/wakapi/config"
|
|
|
|
"github.com/muety/wakapi/models"
|
2020-11-01 22:14:10 +03:00
|
|
|
"gorm.io/gorm"
|
2020-10-16 17:11:14 +03:00
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
|
|
|
log.Fatal(result.Error)
|
|
|
|
}
|
|
|
|
if result.RowsAffected > 0 {
|
|
|
|
log.Printf("Migrated %+v rows for custom language %+s.\n", result.RowsAffected, k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|