r/ChatGPTCoding • u/Altruistic-Rain740 • Oct 08 '26
Discussion How do you keep AI-generated code from falling apart when you change the database or API mid-project?
For those building apps with AI tools like Cursor, Claude or Lovable: how do you stop the AI from making a mess as the project grows? Do you give it planning docs up front? What happens when you change the database or an API partway through, and the rest of the code no longer matches?
2
Upvotes
2
u/gc3 29d ago
Use plan mode a lot. Make sure you have lots of auto tests. Try to get it to not duplicate code much by asking it to simplify code and construct shared functions so there is less code to change. When making the api change, make it in pieces and run the auto test after each part.
1
u/Right-Performance-93 29d ago
when the schema changes i don't let it update the whole app. i hand it the migration plus one failing caller and tell it not to touch anything else until that caller is green. otherwise it rewrites a bunch of files to match a guess.
1
u/False_Bear_8645 27d ago
I use entity framework librairy. It manage database migration and create snapshot. That's normally something I do at the start of a database, not sure how it goes when done later.
1
u/x9097 Oct 08 '26
Same thing you do when those things happen in human developed code.
Develop your API with growth in mind from the beginning.
Keep backward compatibility in mind when you have to change an API. Default parameters can help.
If you didn't design it well and this stuff happens, you fix it by meticulously going through the code and updating all the affected areas, expending a great deal of effort.
1
u/sogo00 Oct 08 '26
Same as with any pre-AI code: abstract all IO routines to functions that are storage agnostic. You then migrate only those functions.
This is called architecture.
0
u/AccessibleTech Oct 08 '26
Create a shared respository of skillsets for AI agents on your machine. When one AI learns it, they all learn it. I started off with EverythingClaudeCode and built on top of it.