DEV Community

Cover image for Stop Letting AI Write Your Database Migrations

Stop Letting AI Write Your Database Migrations

Syed Ahmer Shah on May 06, 2026

The era of “just ask the LLM” has made us remarkably productive, but it has also made us dangerously comfortable. We are currently witnessing a shi...
Collapse
 
faique_26 profile image
Faique

The comparison to open-heart surgery is spot on. AI is great at syntax, but it doesn't have the "fear" or the context of a live production environment. I've seen too many junior devs trust LLM output blindly only to realize later that they’ve locked a mission-critical table during peak hours.

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

The "fear" is a great point. That gut feeling that tells a human dev, "Wait, this table is huge, let me double-check the execution plan," is exactly what AI lacks. It’s that healthy paranoia that keeps production environments stable.

Collapse
 
farzeenai profile image
Aley

Adding a non-nullable column with a default value is the classic "silent killer" of production databases. It’s the perfect example of where AI gives you the "correct" SQL but the "wrong" engineering approach. Thanks for highlighting the multi-step human-engineered alternative; that's a pattern every dev should memorize.

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

It really is the "silent killer." Because it passes every local test and every CI pipeline with flying colors, it’s the ultimate trap for a developer in a hurry. Once you’ve lived through one production outage caused by a table lock, that multi-step pattern becomes second nature.

Collapse
 
syedfarzeenshahofficial profile image
Vinod Oad

This is a great breakdown of why local testing can be so deceptive. A migration that takes 10ms on a dev machine can easily become a nightmare on a production table with millions of rows. Using AI for the initial scaffolding is fine, but there's no substitute for understanding your database's locking behavior.

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

Local vs. Production is the biggest lie in web development! Testing on 50 rows is a completely different world than testing on 5 million. Understanding locking behavior isn't just a "senior" skill anymore; in the age of AI, it’s a survival skill for every dev.

Collapse
 
mnemehq profile image
Theo Valmis

The migration angle is the perfect case study because the cost of getting it wrong is asymmetric. AI is great at generating syntactically valid SQL, but the riskiest part of a migration is the unwritten context: which tables have hot indexes, which deploys have to pair with a feature flag, why the obvious column rename was rejected last quarter. Without that, every generated migration is a coin flip in prod.

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

The asymmetry of risk is exactly why we can't automate this. Context like hot indexes is invisible to an LLM.

Collapse
 
mnemehq profile image
Theo Valmis

Exactly. The difficult part is that a lot of critical engineering context is implicit, operational, and accumulated over time rather than explicitly present in code.

LLMs can generate migrations syntactically. The harder problem is preserving the architectural and operational reasoning around those migrations before they become production risk.

Collapse
 
farzeendev profile image
Sagar Kumar

Excellent point about the context gap. An LLM doesn't know your replication lag or your deployment strategy. It treats a database like a static file rather than a living, breathing system. Using AI as a drafter rather than an architect is the best advice I've heard regarding this transition.

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

"Treats a database like a static file"—that is the perfect way to put it. AI understands the syntax of the language but not the physics of the environment. Keeping the "Architect" role for ourselves is the only way to ensure the system stays upright.

Collapse
 
musabsheikh profile image
Faraz

Well said. AI helps with speed, but schema changes need engineering judgment, not blind trust.

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

Precisely. AI can give you speed, but only a human can provide the judgment. It’s all about using the tool to save time on the typing, not the thinking.

Collapse
 
farzeenshahofficial profile image
Zohaib

It is interesting 🤔

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

It’s a fascinating time to be a dev—we have more power than ever, but that just means we have to be even more careful with how we use it.

Collapse
 
syedasharshah profile image
Vicky Jaish

Thanks for sharing 😊

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

You're very welcome. It’s a lesson usually learned the hard way, so I’m happy to share the perspective!

Collapse
 
youtube_marketing_b23ba8a profile image
Youtube Marketing

What about hallucination, over confidence levels, leaks that AI does to projects ?

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

Great points. Hallucination and data leaks add a massive layer of risk that simple syntax checking can't catch.

Collapse
 
sahilkumar profile image
Sahil Kumar

It was worth reading 😁

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

Glad you enjoyed the read! Hopefully, it saves a few databases from some unintentional downtime.

Collapse
 
yune120 profile image
Yunetzi

LLMs are great copilots, not chauffeurs. Migrations deserve human review—production crashes are expensive, napkin math won't cut it.

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

"Copilots, not chauffeurs" is the perfect mantra for 2026. If you let the AI drive the migration, you’re eventually going to end up in a ditch. Human review is the only insurance policy we have.

Collapse
 
syedfarzeen profile image
Ganjkar Bhai

I strongly agree, we should handle critical things without ai

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

Totally agree. Some things are just too high-stakes to leave to a probabilistic model. The database is definitely at the top of that list.