Database Schema Sync Loop
Automatically detects and resolves schema drift between your database and ORM models by iteratively applying necessary migrations and verifying alignment.
Goal
Align schema and models
How to Run
Run this loop in your coding agent to automatically synchronize your database schema with ORM models through iterative detection and correction.
- 01
Step 1: Initialize Loop
Copy and paste the kickoff prompt into your coding agent (Cursor, Claude Code, Codex, etc.) to start the schema synchronization process.
- 02
Step 2: Agent Execution
The agent will run up to 10 iterations, each time checking for schema differences and applying corrections until no drift is detected.
- 03
Step 3: Review Results
After exit, verify the final state of your schema and models to ensure they are properly aligned.
Workflow Steps
- 01
Detect Schema Drift
Run schema diff to identify discrepancies between current database schema and ORM model definitions
- 02
Analyze Differences
Examine detected differences to determine which changes need to be applied to resolve inconsistencies
- 03
Apply Changes
Generate and execute appropriate migration scripts or model updates to align schema with ORM
- 04
Verify Alignment
Re-run schema diff to confirm that applied changes have resolved all discrepancies
- 05
Iterate or Exit
If drift persists and iterations remain, return to Step 1. Otherwise, exit successfully when no drift is detected.
Kickoff Prompt
Start the "Database Schema Sync Loop" loop. Goal: Align schema and models Max iterations: 10 Between iterations run: schema diff Exit when: No schema drift Start the database schema sync loop. Check for schema drift using 'schema diff', analyze any differences between the database and ORM models, apply necessary migrations or model updates to resolve inconsistencies, and repeat this process for up to 10 iterations until the schema diff shows no drift. Ensure each change is validated before proceeding. Self-pace this loop. After each iteration, run `schema diff` and evaluate the output, and only continue if the exit condition is not met (No schema drift). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.
Guardrails
hardcoded- ·Always backup your database before applying schema changes
- ·Do not modify production databases directly - use staging environments
- ·Validate each migration by running tests before committing changes
- ·Ensure ORM compatibility before applying structural changes
- ·Log all changes for audit and rollback purposes
- ·Respect existing data integrity constraints during schema updates
Flow Diagram
Related loops — Database
Database
Backup Verification
Automates the verification of database backup restorability by repeatedly testing restore operations until successful or maximum iterations reached.
Database
Foreign Key Repair Loop
This loop identifies and repairs broken foreign key relationships in a relational database. It systematically detects constraint violations, proposes corrective actions, and validates fixes until all foreign key checks pass.
Database
Query Performance Fixer
An automated workflow to identify, analyze, and optimize slow-running database queries through iterative benchmarking and targeted improvements.