catbase/util/migrate/first.go

34 lines
619 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"
first2 "github.com/velour/catbase/plugins/first"
"log"
"time"
)
type FirstEntrySQL struct {
first2.FirstEntry
Day int64
Time int64
}
func migrateFirst(db *sqlx.DB, store *bh.Store) error {
all := []FirstEntrySQL{}
log.Printf("Migrating %T", all)
if err := db.Select(&all, `select * from first`); err != nil {
return err
}
for _, i := range all {
fe := i.FirstEntry
fe.Day = time.Unix(i.Day, 0)
fe.Time = time.Unix(i.Time, 0)
if err := store.Insert(i.ID, fe); err != nil {
return err
}
}
return nil
}