fix(data-drains): convert unique-name violations to 409 on POST/PUT#4471
fix(data-drains): convert unique-name violations to 409 on POST/PUT#4471waleedlatif1 merged 1 commit intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview Reviewed by Cursor Bugbot for commit 4f02445. Configure here. |
Greptile SummaryThis PR wraps the
Confidence Score: 5/5Safe to merge — the change is a focused UX fix that converts an unhandled DB exception into a clean HTTP 409 without touching any data-integrity logic. Both handlers correctly handle the race window between the pre-check SELECT and the actual write: non-23505 errors are re-thrown so they still surface as 500s via the route handler wrapper, the null guard on the POST return row was added as requested in the prior review thread, and the getPostgresErrorCode utility already walks cause chains to handle all common Drizzle/postgres driver shapes. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant POST/PUT Handler
participant Pre-check SELECT
participant DB INSERT/UPDATE
participant Postgres
Client->>POST/PUT Handler: Request with drain name
POST/PUT Handler->>Pre-check SELECT: SELECT WHERE name = ? (fast path)
alt Name already exists (common case)
Pre-check SELECT-->>POST/PUT Handler: row found
POST/PUT Handler-->>Client: 409 Conflict
else Name is free
Pre-check SELECT-->>POST/PUT Handler: no row
POST/PUT Handler->>DB INSERT/UPDATE: Execute write
DB INSERT/UPDATE->>Postgres: SQL
alt Concurrent insert won the race (23505)
Postgres-->>DB INSERT/UPDATE: unique_violation error
DB INSERT/UPDATE-->>POST/PUT Handler: throw error
POST/PUT Handler-->>Client: 409 Conflict
else Write succeeds
Postgres-->>DB INSERT/UPDATE: returning row
DB INSERT/UPDATE-->>POST/PUT Handler: inserted/updated row
POST/PUT Handler-->>Client: 201/200 with drain
end
end
Reviews (2): Last reviewed commit: "fix(data-drains): convert unique-name vi..." | Re-trigger Greptile |
4f02445 to
4e3cfa1
Compare
Catch Postgres 23505 on insert/update so concurrent name conflicts return a clean 409 instead of a 500. The data_drains_org_name_unique index already prevents duplicate rows; this just improves the UX.
4e3cfa1 to
331a52f
Compare
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 331a52f. Configure here.
…4471) Catch Postgres 23505 on insert/update so concurrent name conflicts return a clean 409 instead of a 500. The data_drains_org_name_unique index already prevents duplicate rows; this just improves the UX.
Summary
23505on data-drain INSERT/UPDATE so concurrent name conflicts return a clean 409 instead of a 500data_drains_org_name_uniqueindex already prevents duplicate rows — this is a UX/error-shape fix, not a data-integrity fixType of Change
Testing
Tested manually
Checklist