catbase/util/migrate/webshit.go

49 lines
948 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 {
2021-12-22 07:53:02 +00:00
if err := store.Insert(bh.NextSequence(), &b); err != nil {
2021-12-22 03:36:08 +00:00
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)
2021-12-22 07:53:02 +00:00
if err := store.Insert(bh.NextSequence(), &bid); err != nil {
2021-12-22 03:36:08 +00:00
return err
}
}
return nil
}