Stow.Cursor + Neon: Writing Database Migrations Without Breaking Production
AI AgentsApril 19, 20265 min read

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.

Cursor
Neon

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:

1

Cursor creates a Neon branch from your main database via Stow

2

Cursor writes the migration SQL based on your instructions

3

You run the migration against the branch connection URI — not main

4

You verify the schema and data look correct on the branch

5

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

List projects and branchesAllowed
Get project detailsAllowed
List databases and rolesAllowed
Create branchAllowed
Delete branchApproval Required
Create projectApproval Required
Delete projectOff

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

"Create a new Neon branch called migration-add-user-roles from the main branch"
"List all branches in my project so I can see what's currently active"
"Write a migration to add a roles column to the users table with a default of 'viewer'"
"Get the connection URI for the migration-add-user-roles branch"

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

Action Taken
Timestamp
Status
Risk Score

Migrate on a Branch. Ship When It's Right.

AI-written migrations on isolated Neon branches. Production stays untouched until you decide.

S

Stow Security Team

April 19, 2026