Cursor + Neon: Writing Database Migrations Without Breaking Production
Cursor can write migration scripts and run them — on a Neon branch. The whole point is it never touches main until you say so. Here's the setup that makes that guarantee real.
Database migrations are one of the highest-risk things a developer does — and one of the highest-value things an AI can assist with. Cursor can write the migration, reason about the schema change, and even suggest the rollback. The part you need to control is where it runs. Neon branches make that possible. Stow makes it enforced.
The Branch-First Migration Pattern
Neon's copy-on-write branching lets you spin up a full Postgres clone in seconds with zero data copying cost. The right pattern for AI-assisted migrations is:
Cursor creates a Neon branch from your main database via Stow
Cursor writes the migration SQL based on your instructions
You run the migration against the branch connection URI — not main
You verify the schema and data look correct on the branch
You promote the branch or manually apply the migration to production
What Happens If You Skip the Branch
Real scenario
Cursor writes a migration that renames a column. You say "looks good, run it." Without a branch, it runs on your production database. The column rename breaks three API endpoints you forgot were using the old name. No rollback script. Outage at 2pm on a Tuesday.
Neon branches eliminate this scenario. The migration runs on an isolated copy. If something breaks, you delete the branch and try again.
Step 1: Connect Neon in Stow
- Navigate to Connected Services → Add New Service → Neon
- Generate a Neon API Key in your Neon account settings
- Paste the key into Stow and click Save
Step 2: Configure Neon Permissions
Recommended Configuration for Migrations
Step 3: Connect Cursor to Stow
- In Stow, go to AI Agents → + Add Agent, name it "Cursor", generate a Client Secret
- In Cursor Settings (
Cmd/Ctrl+Shift+J), go to Tools & MCP → + New MCP Server - Add the Stow SSE config with your Agent ID and Secret
The Migration Workflow in Practice
Cursor retrieves the branch connection URI through Stow (the URI is masked in logs — never stored in plain text) and you use it to run the migration directly. Cursor can also write the psql command or Drizzle/Prisma migration file for you to execute.
What Cursor Can and Can't Do Here
Cursor can
- Create the Neon branch
- Write the migration SQL
- Write the rollback SQL
- Retrieve connection details
- List branches and verify state
Cursor can't (with this config)
- Execute SQL directly on Neon (no direct DB connection tool)
- Touch your production/main branch without approval
- Delete branches without your approval
- Modify project settings
What Gets Logged
Stow Security Team
April 19, 2026