note
hosted, paid — --remote
Sequence restarted — duplicate key collisions ahead
Note — this works and blocks nothing, but a performance regression is likely.
What it catches
RESTART rewinds a sequence regardless of what values are already in use. If any existing row holds an id at or above the restart point, inserts start failing with duplicate-key errors at some unpredictable later moment.
Fires on
ALTER SEQUENCE orders_id_seq RESTART WITH 1;Do this instead
Derive the sequence position from the data instead of restarting at an absolute value: setval to the current max leaves no room for collisions. If the goal was reclaiming ids, don't — gaps are normal and harmless.
-- Position the sequence relative to real data:
SELECT setval('orders_id_seq', (SELECT max(id) FROM orders));Catch this before it ships
This rule runs in the hosted service on Startup and above — add --remote with a team token, or use the GitHub Action: npx bolvrk check migration.sql