Browse Source

Update "updated" column on duplicate keys

master
Peter Stuifzand 8 months ago
parent
commit
5452cabf7e
  1. 11
      cmd/hubserver/storage/postgres.go
  2. 1
      db/03_updated.sql

11
cmd/hubserver/storage/postgres.go

@ -25,8 +25,15 @@ func (s *postgres) Close() error {
}
func (s *postgres) Subscribe(topic string, sub Subscriber) error {
_, err := s.db.Exec(
`INSERT INTO "subscribers" ("topic", "callback", "lease_seconds", "secret", "created") VALUES ($1, $2, $3, $4, now())`,
_, err := s.db.Exec(`
INSERT INTO "subscribers"
("topic", "callback", "lease_seconds", "secret", "created")
VALUES ($1, $2, $3, $4, now())
ON CONFLICT ON CONSTRAINT subscribers_topic_callback
DO UPDATE SET lease_seconds = excluded.lease_seconds,
secret = excluded.secret,
updated = excluded.created
`,
topic,
sub.Callback,
sub.LeaseSeconds,

1
db/03_updated.sql

@ -0,0 +1 @@
ALTER TABLE "subscribers" ADD COLUMN "updated" TIMESTAMP NULL;
Loading…
Cancel
Save