Test a destructive Postgres migration on a copy-on-write branch
When to use: You have a migration (DROP COLUMN, big UPDATE, index rebuild) and you want to run it on prod-shaped data without risking prod.
Prerequisites
- Neon API key — console.neon.tech → Account → API keys
Flow
-
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.✓ Copied→ 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.✓ Copied→ 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.✓ Copied→ Verification + branch deleted to avoid storage charges
Outcome: Confidence that your migration works on real data, with zero risk to prod.
Pitfalls
- 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