SQL · correctness
insert-requires-on-conflict
sql:insert-requires-on-conflict INSERT without ON CONFLICT — migration data writes must be idempotent upserts.
- Code
- SARJ105
- Default
- error
- Fix
- none
- Languages
- sql
Why
A retried seed migration can duplicate rows or fail on a uniqueness constraint when an insert has no replay behavior.
Fix
Add ON CONFLICT with an explicit DO NOTHING or DO UPDATE action.
Before / after
Executed by this rule’s unit tests.
Before
Seed insert without conflict handling
INSERT INTO plan (name) VALUES ('free');
After
Seed insert with conflict handling
INSERT INTO plan (name) VALUES ('free') ON CONFLICT (name) DO NOTHING;
Limits
- Only PostgreSQL migration paths and explicitly marked PostgreSQL migrations are checked.