Spec a required column for a busy Postgres table
Your task
Your payments table in Postgres has 300 million rows and takes writes all day. You need a new currency column that must never be null. Old rows get their currency from their merchant, in merchants.currency, and new rows get it from the app. An agent will write the migrations and the rollout, and nothing may cause downtime.
Write the spec you would hand the agent.
What you know:
- Postgres 15, and your migration tool wraps each migration file in a transaction
- deploys are rolling, so old and new app versions run side by side for about 10 minutes
- long analytics queries sometimes run on the primary
Then, in a few sentences: what does "add a NOT NULL column with a default" get wrong on a table like this?