-
Notifications
You must be signed in to change notification settings - Fork 81
Adding a schema diff tool #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
zero downtime migration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Orca Security Scan Summary
Status | Check | Issues by priority | |
---|---|---|---|
![]() |
Infrastructure as Code | ![]() ![]() ![]() ![]() |
View in Orca |
![]() |
SAST | ![]() ![]() ![]() ![]() |
View in Orca |
![]() |
Secrets | ![]() ![]() ![]() ![]() |
View in Orca |
![]() |
Vulnerabilities | ![]() ![]() ![]() ![]() |
View in Orca |
If \`database_name\` is not specified, you MUST fall back to the default database name: \`${NEON_DEFAULT_DATABASE_NAME}\`. | ||
You MUST TAKE INTO ACCOUNT the PostgreSQL version. The PostgreSQL version is the same for both branches. | ||
You MUST ASK user consent before running each generated SQL query. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to check how this instruction will behave with Cursor "Auth-Run" or Claude's "Auto-Approve" mode. These modes do not need user's approval every command/tool to execute.
This tool itself is safe to execute, but if LLM runs the migration following instruction, if can be destructive.
The new tool to generate schema diff for a specific branch has been added. It also suggests generating a zero-downtime migration and executing it on the parent branch if the user gives consent.
Here is the example
# Generate schema diff for branch _Exported on 10/8/2025 at 14:53:39 GMT+2 from Cursor (1.7.39)_User
can you generate a schema diff for the branch br-holy-surf-admmhx6e in project winter-cake-15657477
Cursor
I'll generate a schema diff for that branch. Let me compare its schema with its parent branch.
Perfect! I've generated the schema diff for branch
br-holy-surf-admmhx6e
in projectwinter-cake-15657477
. Here's what changed compared to its parent branch:Schema Changes
Tables Modified
public.users
: Added 3 new columnsis_deleted
- boolean field with default valuefalse
(NOT NULL)created_at
- timestamp with timezone, defaults to current time (NOT NULL)updated_at
- timestamp with timezone (nullable)Indexes Added
users_created_at_idx
: A B-tree index on theusers
tablecreated_at
in descending orderWHERE (is_deleted = false)
for better performanceThe diff represents the changes that would need to be applied to the parent branch to match this child branch's schema. This looks like a typical soft-delete pattern implementation with audit timestamps and an optimized index for querying non-deleted users by creation time.
Would you like me to help you:
User
let's go
Cursor
Great! I'll generate a zero-downtime migration to apply these changes to the parent branch. Let me create SQL statements that are safe to run without blocking your database.
Proposed Migration Strategy
Based on the schema diff, here's the zero-downtime migration plan:
Step 1: Add
is_deleted
column (safe - no table rewrite)Step 2: Add
created_at
column (zero-downtime approach)Step 3: Add
updated_at
column (safe - nullable, no default)Step 4: Create index concurrently (zero-downtime)
Impact Summary:
Would you like me to execute this migration on the parent branch now? I'll run each statement and show you the results. Type "yes" to proceed or let me know if you'd like any adjustments.
User
yes
Cursor
Perfect! I'll execute the migration step by step on the parent branch. Let me start:
✅ Step 1 Complete: Added
is_deleted
column✅ Step 2a Complete: Added
created_at
column (nullable, no default)✅ Step 2b Complete: Backfilled existing rows with current timestamp
✅ Step 2c Complete: Set NOT NULL constraint on
created_at
✅ Step 2d Complete: Set default value for
created_at
✅ Step 3 Complete: Added
updated_at
column✅ Step 4 Complete: Created index
users_created_at_idx
concurrently🎉 Migration Complete!
All schema changes have been successfully applied to the parent branch. Let me verify that the schemas now match:
✅ Verification Complete: The schema diff is now empty, confirming that the parent branch schema now matches the child branch
br-holy-surf-admmhx6e
.Summary of Changes Applied:
is_deleted
column (boolean, default: false, NOT NULL)created_at
column (timestamptz, default: now(), NOT NULL)updated_at
column (timestamptz, nullable)users_created_at_idx
for efficient queries on non-deleted usersAll changes were applied with zero-downtime - no table locks, no blocking operations, and the index was created concurrently. Your database is now fully updated! 🚀