catbase/util/migrate/webshit.go

49 lines
922 B
Go
Raw Normal View History

2021-12-22 03:36:08 +00:00
package main
import (
"github.com/jmoiron/sqlx"
bh "github.com/timshannon/bolthold"
webshit2 "github.com/velour/catbase/plugins/newsbid/webshit"
"log"
"time"
)
type BidSQL struct {
webshit2.Bid
Placed int64
Processed int64
}
func migrateWebshit(db *sqlx.DB, store *bh.Store) error {
balances := []webshit2.Balance{}
bids := []BidSQL{}
log.Printf("Migrating %T", balances)
if err := db.Select(&balances, `select * from webshit_balances`); err != nil {
return err
}
for _, b := range balances {
if err := store.Insert(b.User, b); err != nil {
return err
}
}
log.Printf("Migrating %T", bids)
if err := db.Select(&bids, `select * from webshit_bids`); err != nil {
return err
}
for _, b := range bids {
bid := b.Bid
bid.Placed = time.Unix(b.Placed, 0)
bid.Processed = time.Unix(b.Processed, 0)
if err := store.Insert(b.ID, bid); err != nil {
return err
}
}
return nil
}