catbase/util/migrate/awards.go

49 lines
1.1 KiB
Go
Raw Normal View History

2021-12-22 03:36:08 +00:00
package main
import (
"github.com/jmoiron/sqlx"
"github.com/rs/zerolog/log"
bh "github.com/timshannon/bolthold"
2021-12-22 07:53:02 +00:00
"github.com/velour/catbase/plugins/achievements"
2021-12-22 03:36:08 +00:00
goals2 "github.com/velour/catbase/plugins/goals"
)
func migrateAwards(db *sqlx.DB, store *bh.Store) error {
2021-12-22 07:53:02 +00:00
awards := []achievements.Award{}
2021-12-22 03:36:08 +00:00
log.Printf("Migrating %T", awards)
err := db.Select(&awards, `select * from awards`)
if err != nil {
return err
}
for _, a := range awards {
2021-12-22 07:53:02 +00:00
err := store.Insert(bh.NextSequence(), &a)
2021-12-22 03:36:08 +00:00
if err != nil {
return err
}
}
log.Printf("Migrated %d awards", len(awards))
2021-12-22 07:53:02 +00:00
trophies := []achievements.Trophy{}
2021-12-22 03:36:08 +00:00
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 {
2021-12-22 07:53:02 +00:00
if err := store.Insert(bh.NextSequence(), &i); err != nil {
2021-12-22 03:36:08 +00:00
return err
}
}
return nil
}