mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-10-26 14:29:36 +00:00
7388ab9c65
The pre-check on response_timestamp was a read-then-write race: concurrent submits all passed it and all wrote. Guard the UPDATE with response_timestamp IS NULL and treat a zero-row update as already submitted.
27 lines
538 B
SQL
27 lines
538 B
SQL
-- name: insert
|
|
INSERT INTO csat_responses (conversation_id)
|
|
SELECT $1
|
|
WHERE NOT EXISTS (SELECT 1 FROM csat_responses WHERE conversation_id = $1)
|
|
RETURNING uuid;
|
|
|
|
-- name: get
|
|
SELECT id,
|
|
uuid,
|
|
created_at,
|
|
updated_at,
|
|
conversation_id,
|
|
rating,
|
|
feedback,
|
|
meta,
|
|
response_timestamp
|
|
FROM csat_responses
|
|
WHERE uuid = $1;
|
|
|
|
-- name: update
|
|
UPDATE csat_responses
|
|
SET rating = $2,
|
|
feedback = $3,
|
|
meta = COALESCE($4::jsonb, '{}'),
|
|
response_timestamp = NOW()
|
|
WHERE uuid = $1 AND response_timestamp IS NULL;
|