r/ClaudeCode • • 7h ago

Built with Claude A backup restore is not an undo

Claude Code runs a bad migration at 2pm. Users keep signing up. You notice at 5pm.

A backup restore takes the whole database back to 1:59pm. Three hours of sign-ups are gone.

What you want is "undo that one change, keep everything else". So we built that into Backenly, an open-source Autonomous backend for applications made with coding agents.

What we built

- Undo works on one change, not the whole database

- Data written after the change is kept. If the undo would touch any of it, you see what before approving

- The undo is tested in a rolled-back transaction first

- Not everything can be undone yet (emptying a whole table, for example)

How Claude Code uses it

- It connects over MCP (npx u/backenly/mcp-server init)

- Schema changes it makes are recorded, each with its own ID

- If something breaks, it can ask to undo that change. Only you can approve it

- We also build Backenly with Claude Code

What we learned

- To a database, "rollback" means going back in time. After a bad agent change, people want "undo that one thing"

- An undo is a change too, so a person should approve it

How do you handle a bad migration today?

3 Upvotes

6 comments sorted by

•

u/AutoModerator 7h ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/Warm_Cauliflower_207 6h ago

had a similar issue with a migration last year, our rollback wiped out 4 hours of user data. we ended up rebuilding the missing state from logs, but it was messy. wonder if backenly handles that kind of recovery too?

1

u/Adarsh_c_j 6h ago

ohh,rebuilding from logs sounds really painful. And yes, that's exactly the case we built it for.

Backenly undoes only that one migration, not the whole database. So the 4 hours of user data written after it stays. If the undo would touch any of that newer data, it shows you exactly what before you approve.

One honest limit: it only works for changes made through Backenly, because it needs the record of what each change did.

Curious, what kind of migration was it? A column change, or something that rewrote data?

1

u/Tisoc-Groscruz 10m ago

rebuilding state from logs is pure nightmare fuel, especially when youre trying to move fast

2

u/aaronsuns 5h ago

For the sign-ups lost after the bad change, a full restore doesn't have to be the only option. Restore point-in-time recovery (WAL in Postgres, binlog in MySQL) to a separate instance at the moment just before the migration, then copy back only the rows created or changed after that point. Wrap migrations in a transaction where the database supports transactional DDL, like Postgres, so a failed step rolls back cleanly. Keep the migration SQL in version control so you can check exactly which objects it touched.

1

u/Adarsh_c_j 4h ago

Yes, that's the right way to do it by hand, and it's pretty much what we wanted to automate.

The hard part is the "copy back only the rows created or changed after" step. You have to find which rows those are, and some of them were changed by the migration itself. At 5pm with users waiting, that's easy to get wrong.

Good point on transactional DDL too. It saves you when a step fails, but not when the migration works fine and is just wrong, which is the case I meant here.

Have you had to do the separate instance restore for real? How long did it take?