mirror of https://github.com/velour/catbase.git
last: fix schema
This commit is contained in:
parent
c5d468c723
commit
850f5248ef
|
@ -43,11 +43,12 @@ func (p *LastPlugin) migrate() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec(`create table if not exists last (
|
_, err = tx.Exec(`create table if not exists last (
|
||||||
day integer primary key,
|
day integer,
|
||||||
ts int not null,
|
|
||||||
channel string not null,
|
channel string not null,
|
||||||
|
ts int not null,
|
||||||
who string 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 {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
|
@ -120,11 +121,8 @@ func (p *LastPlugin) recordLast(r bot.Request) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := p.db.Exec(
|
_, err := p.db.Exec(
|
||||||
`insert into last values (?, ?, ?, ?, ?)
|
`insert into last values (?, ?, ?, ?, ?)`,
|
||||||
on conflict(day) do update set
|
day.Unix(), ch, time.Now().Unix(), who, r.Msg.Body)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("Could not record last.")
|
log.Error().Err(err).Msgf("Could not record last.")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue