mirror of https://github.com/velour/catbase.git
34 lines
633 B
Go
34 lines
633 B
Go
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(bh.NextSequence(), &fe); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|