catbase/util/migrate/awards.go

64 lines
1.2 KiB
Go
Raw Normal View History

2021-12-22 03:36:08 +00:00
package main
import (
"database/sql"
"github.com/jmoiron/sqlx"
"github.com/rs/zerolog/log"
bh "github.com/timshannon/bolthold"
goals2 "github.com/velour/catbase/plugins/goals"
)
type Trophy struct {
Emojy string
Description string
Creator string
}
type Award struct {
ID int64 `boltholderid:"ID"`
Holder string
Emojy string
Description string
Granted sql.NullTime
Amount int64
}
func migrateAwards(db *sqlx.DB, store *bh.Store) error {
awards := []Award{}
log.Printf("Migrating %T", awards)
err := db.Select(&awards, `select * from awards`)
if err != nil {
return err
}
for _, a := range awards {
err := store.Insert(a.ID, a)
if err != nil {
return err
}
}
log.Printf("Migrated %d awards", len(awards))
trophies := []Trophy{}
err = db.Select(&trophies, `select * from trophies`)
for _, t := range trophies {
err := store.Insert(t.Emojy, t)
if err != nil {
return err
}
}
log.Printf("Migrated %d trophies", len(trophies))
goals := []goals2.Goal{}
log.Printf("Migrating %T", goals)
if err := db.Select(&goals, `select * from goals`); err != nil {
return err
}
for _, i := range goals {
if err := store.Insert(i.ID, i); err != nil {
return err
}
}
return nil
}