mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 16:50:01 +00:00
[quote] Fix: Add primary key to quote table
in order to allow migrating them using copy-database Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
2772286b71
commit
24aa1b5d67
1 changed files with 3 additions and 2 deletions
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
type (
|
type (
|
||||||
quote struct {
|
quote struct {
|
||||||
|
ID uint64 `gorm:"primaryKey"`
|
||||||
Channel string `gorm:"not null;uniqueIndex:ensure_sort_idx;size:32"`
|
Channel string `gorm:"not null;uniqueIndex:ensure_sort_idx;size:32"`
|
||||||
CreatedAt int64 `gorm:"uniqueIndex:ensure_sort_idx"`
|
CreatedAt int64 `gorm:"uniqueIndex:ensure_sort_idx"`
|
||||||
Quote string
|
Quote string
|
||||||
|
@ -22,7 +23,7 @@ type (
|
||||||
func AddQuote(db database.Connector, channel, quoteStr string) error {
|
func AddQuote(db database.Connector, channel, quoteStr string) error {
|
||||||
return errors.Wrap(
|
return errors.Wrap(
|
||||||
helpers.RetryTransaction(db.DB(), func(tx *gorm.DB) error {
|
helpers.RetryTransaction(db.DB(), func(tx *gorm.DB) error {
|
||||||
return tx.Create(quote{
|
return tx.Create("e{
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
CreatedAt: time.Now().UnixNano(),
|
CreatedAt: time.Now().UnixNano(),
|
||||||
Quote: quoteStr,
|
Quote: quoteStr,
|
||||||
|
@ -121,7 +122,7 @@ func SetQuotes(db database.Connector, channel string, quotes []string) error {
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
for _, quoteStr := range quotes {
|
for _, quoteStr := range quotes {
|
||||||
if err := tx.Create(quote{
|
if err := tx.Create("e{
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
CreatedAt: t.UnixNano(),
|
CreatedAt: t.UnixNano(),
|
||||||
Quote: quoteStr,
|
Quote: quoteStr,
|
||||||
|
|
Loading…
Reference in a new issue