Migration Until Clean
This loop automatically detects and fixes database migration issues by iteratively running migrations, analyzing errors, and applying corrective code changes until the migration process completes successfully.
Goal
Fix migration issues
How to Run
Run this loop in a supported agent environment to automatically resolve database migration failures through iterative debugging and code fixes.
- 01
Initialize Loop
Provide the kickoff prompt to your coding agent in an environment like Cursor, Claude Code, or Gemini CLI.
- 02
Agent Execution
The agent will run the migration check, analyze failures, modify code, and repeat until success or max iterations reached.
Workflow Steps
- 01
Run Migration Check
Execute 'npm run migrate' to identify current migration status and errors
- 02
Inspect Results
Analyze the output for specific error messages, failed migrations, or schema conflicts
- 03
Diagnose Issue
Determine root cause: syntax errors, constraint violations, missing dependencies, or version conflicts
- 04
Apply Fix
Modify migration files, update dependencies, or adjust schema definitions to resolve identified issues
- 05
Iterate Process
Return to step 1 and repeat until migration succeeds or maximum attempts reached
Kickoff Prompt
Start the "Migration Until Clean" loop. Goal: Fix migration issues Max iterations: 10 Between iterations run: npm run migrate Exit when: Migration succeeds Start the Migration Until Clean loop. Run 'npm run migrate' to check current status, analyze any errors or failed migrations, identify the root cause of the issue, and apply appropriate fixes to migration files, schema definitions, or dependencies. Continue this process iteratively until the migration completes successfully or 10 iterations have been reached, whichever comes first. After each attempt, inspect the results carefully before making changes. Self-pace this loop. After each iteration, run `npm run migrate` and evaluate the output, and only continue if the exit condition is not met (Migration succeeds). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.
Guardrails
hardcoded- ·Never execute destructive commands without user confirmation
- ·Always backup the database before attempting fixes
- ·Ensure rollback strategies exist for each migration change
- ·Avoid modifying production data directly
- ·Check for conflicting migration versions before applying changes
- ·Validate schema integrity after each fix attempt
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
Database Schema Sync Loop
Automatically detects and resolves schema drift between your database and ORM models by iteratively applying necessary migrations and verifying alignment.
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.