From 850f5248ef0af2a275a44d605b25eb8d30b7b23a Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Wed, 28 Apr 2021 17:13:03 -0400 Subject: [PATCH] last: fix schema --- plugins/last/last.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/last/last.go b/plugins/last/last.go index 879538c..ef1d629 100644 --- a/plugins/last/last.go +++ b/plugins/last/last.go @@ -43,11 +43,12 @@ func (p *LastPlugin) migrate() error { return err } _, err = tx.Exec(`create table if not exists last ( - day integer primary key, - ts int not null, + day integer, channel string not null, + ts int not null, who string not null, - message string not null + message string not null, + constraint last_key primary key (day, channel) on conflict replace )`) if err != nil { tx.Rollback() @@ -120,11 +121,8 @@ func (p *LastPlugin) recordLast(r bot.Request) bool { } _, err := p.db.Exec( - `insert into last values (?, ?, ?, ?, ?) - on conflict(day) do update set - ts=excluded.ts, channel=excluded.channel, who=excluded.who, message=excluded.message - where day=excluded.day`, - day.Unix(), time.Now().Unix(), ch, who, r.Msg.Body) + `insert into last values (?, ?, ?, ?, ?)`, + day.Unix(), ch, time.Now().Unix(), who, r.Msg.Body) if err != nil { log.Error().Err(err).Msgf("Could not record last.") }