Database migration review
Send the migration script with the table size and the code that still writes to the table, and have GPT-6 Astra say whether it can run on a live database and in what order to split it. Rehearse it on a copy of production data first.
Example: Can this migration run on the live table?
Material
- migration.sql
- ALTER TABLE orders ADD COLUMN region text NOT NULL;
- Table size
- orders has about 40 million rows and receives writes all day.
- orders.ts
- INSERT INTO orders (id, user_id, total) VALUES ($1, $2, $3)
PromptUsing the migration, the table size and the current code, say whether this can run as is on the production database. If not, split it into steps that can, in order.
Sample answer · written by hand to show the reasoning
Not as is. Existing rows have no region, so adding a NOT NULL column without a default fails, and the current insert would fail too because it doesn’t set region. Add region as a nullable column, deploy code that writes it, backfill old rows in batches, and only then add the NOT NULL constraint.