Menu

This 4-line migration looks routine and breaks production. A free GitHub Action catches it (looking for 5 teams to try it)
📰

This 4-line migration looks routine and breaks production. A free GitHub Action catches it (looking for 5 teams to try it)

DEV Community: github·Muhammad Adnan·19 minutes ago
#dUWZ3B3z
#devtogithub#technology#devto#dev#migration
Reading 0:00
15s threshold

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 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.