Here's a migration that would sail through most code reviews:
ALTER TABLE users ADD COLUMN plan text NOT NULL ; ALTER TABLE users ADD COLUMN api_token uuid DEFAULT gen_random_uuid ( ) ; CREATE INDEX users_plan_idx ON users ( plan ) ; ALTER TABLE orders ADD CONSTRAINT orders_total_positive CHECK ( total > 0 ) ;
Enter fullscreen mode
Exit fullscreen mode
On an empty dev database it runs in milliseconds. On a table with real data:
Line 1 fails outright. Every existing row would get NULL in a NOT NULL column, so Postgres rejects it ("column contains null values"). Your deploy stops halfway.
Line 2 rewrites the whole table under the strongest lock, because gen_random_uuid() needs a different value in every row. On a 2M-row table I measured 9.2 s with reads and writes blocked. The same column with DEFAULT now() took 1.3 ms.
Line 3 blocks every write to users until the index is built. On 2M rows, a single INSERT waited 2.26 s .…