mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 00:30:02 +00:00
35 lines
716 B
Go
35 lines
716 B
Go
package v2migrator
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/Luzifer/twitch-bot/pkg/database"
|
|
)
|
|
|
|
type (
|
|
storageModQuoteDB struct {
|
|
ChannelQuotes map[string][]string `json:"channel_quotes"`
|
|
}
|
|
)
|
|
|
|
func (s storageModQuoteDB) migrate(db database.Connector) (err error) {
|
|
for channel, quotes := range s.ChannelQuotes {
|
|
t := time.Now()
|
|
for _, quote := range quotes {
|
|
if _, err = db.DB().Exec(
|
|
`INSERT INTO quotedb
|
|
(channel, created_at, quote)
|
|
VALUES ($1, $2, $3);`,
|
|
channel, t.UnixNano(), quote,
|
|
); err != nil {
|
|
return errors.Wrap(err, "adding quote for channel")
|
|
}
|
|
|
|
t = t.Add(time.Nanosecond) // Increase by one ns to adhere to unique index
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|