Test a destructive Postgres migration on a copy-on-write branch
Когда использовать: You have a migration (DROP COLUMN, big UPDATE, index rebuild) and you want to run it on prod-shaped data without risking prod.
Предварительные требования
- Neon API key — console.neon.tech → Account → API keys
Поток
-
Create a branch from mainIn Neon project <id>, create a branch named 'test-drop-legacy' from the main branch. Return the connection string for the new branch.✓ Скопировано→ Branch created in <2 seconds, conn string returned
-
Apply the migration on the branchConnect to the new branch and run: <paste migration SQL>. Report row counts and any errors.✓ Скопировано→ Migration completes; counts make sense
-
Verify, then clean upRun sanity queries on the changed tables. If results look correct, tell me and I'll apply to main. Then delete the branch either way.✓ Скопировано→ Verification + branch deleted to avoid storage charges
Итог: Confidence that your migration works on real data, with zero risk to prod.
Подводные камни
- Branch consumes storage proportional to how much you write on it — Delete branches promptly after testing — abandoned branches with heavy writes drive up bill
- Branch is a snapshot — doesn't see writes that happen on main after branch creation — Branch close to apply time; or use Neon time-travel to branch from a specific timestamp