Skip to content

Commit

Permalink
fix: idempotency per-client
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Nov 13, 2023
1 parent ffabaf0 commit c735f17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE public.notifications
DROP CONSTRAINT notifications_pkey;

ALTER TABLE public.notifications
ALTER COLUMN id SET not null;

ALTER TABLE public.notifications
ADD PRIMARY KEY (id, client_id);
11 changes: 6 additions & 5 deletions src/stores/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ impl NotificationStore for sqlx::PgPool {
payload: &MessagePayload,
) -> stores::Result<Notification> {
let res = sqlx::query_as::<sqlx::postgres::Postgres, Notification>(
"INSERT INTO public.notifications (id, tenant_id, client_id, last_payload)
VALUES ($1, $2, $3, $4)
ON CONFLICT (id)
DO UPDATE SET last_received_at = now()
RETURNING *;",
"
INSERT INTO public.notifications (id, tenant_id, client_id, last_payload)
VALUES ($1, $2, $3, $4)
ON CONFLICT (id, client_id)
DO UPDATE SET last_received_at = now()
RETURNING *;",
)
.bind(id)
.bind(tenant_id)
Expand Down

0 comments on commit c735f17

Please sign in to comment.