catbase/util/migrate/blackwhite.go

33 lines
744 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"
"github.com/velour/catbase/bot"
"log"
)
func migrateBlackWhite(db *sqlx.DB, store *bh.Store) error {
allBlack := []bot.BlacklistItem{}
allWhite := []bot.WhitelistItem{}
log.Printf("Migrating %T", allBlack)
if err := db.Select(&allBlack, `select * from pluginBlacklist`); err != nil {
return err
}
for _, i := range allBlack {
if err := store.Insert(i.Key(), i); err != nil {
return err
}
}
log.Printf("Migrating %T", allWhite)
if err := db.Select(&allWhite, `select * from pluginWhitelist`); err != nil {
return err
}
for _, i := range allWhite {
if err := store.Insert(i.Name, i); err != nil {
return err
}
}
return nil
}