Update "updated" column on duplicate keys
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2020-11-29 22:50:40 +01:00
parent 85ac5fb6f2
commit 5452cabf7e
2 changed files with 10 additions and 2 deletions

View File

@ -25,8 +25,15 @@ func (s *postgres) Close() error {
} }
func (s *postgres) Subscribe(topic string, sub Subscriber) error { func (s *postgres) Subscribe(topic string, sub Subscriber) error {
_, err := s.db.Exec( _, err := s.db.Exec(`
`INSERT INTO "subscribers" ("topic", "callback", "lease_seconds", "secret", "created") VALUES ($1, $2, $3, $4, now())`, 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, topic,
sub.Callback, sub.Callback,
sub.LeaseSeconds, sub.LeaseSeconds,

1
db/03_updated.sql Normal file
View File

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