Databaseprompt onlyIntermediate

Database Schema Sync Loop

Automatically detects and resolves schema drift between your database and ORM models by iteratively applying necessary migrations and verifying alignment.

← all loops
databaseschemaormsyncmigrationloopautomated

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.

  1. 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.

  2. 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.

  3. 03

    Step 3: Review Results

    After exit, verify the final state of your schema and models to ensure they are properly aligned.

Workflow Steps

  1. 01

    Detect Schema Drift

    Run schema diff to identify discrepancies between current database schema and ORM model definitions

  2. 02

    Analyze Differences

    Examine detected differences to determine which changes need to be applied to resolve inconsistencies

  3. 03

    Apply Changes

    Generate and execute appropriate migration scripts or model updates to align schema with ORM

  4. 04

    Verify Alignment

    Re-run schema diff to confirm that applied changes have resolved all discrepancies

  5. 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

rendering…

Related loops — Database