Update "updated" column on duplicate keys
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
85ac5fb6f2
commit
5452cabf7e
|
@ -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
1
db/03_updated.sql
Normal file
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE "subscribers" ADD COLUMN "updated" TIMESTAMP NULL;
|
Loading…
Reference in New Issue
Block a user