5
The day my for loop broke my database table - a Tuesday to remember
I was working on a simple inventory tracker for my small shop here in Portland. I had this for loop that was supposed to update stock levels for 50 items, but I forgot to add a try-except block. After 20 minutes of watching my SQL queries run, I realized the loop was inserting duplicate rows instead of updating existing ones. Ended up with 1,200 extra rows in my database table before I killed the process. Had to restore from a backup from 3 days earlier and lost a bunch of order data. Has anyone else accidentally flooded their database like that?
1 comments
Log in to join the discussion
Log In1 Comment
hall.charles1mo ago
Honest question, is restoring from backup really that big of a deal here? You had a backup from 3 days ago, you lost a few orders, that sucks but it's not the end of the world. Most small shops can re-enter a couple days of orders manually if they had to. And 1,200 duplicate rows in a modern database is barely a blip on performance. I've seen people accidentally insert 50,000 duplicates and just delete them with a query. Feels like you're overthinking a Tuesday problem.
4