Entry 05
The day my laptop deleted my work
Two PCs, one live app and no single source of truth. Then a missing load that was never missing, and a fight over who owns the next number. Three hard lessons and the rules that fixed them.
On 22 June I fixed one small rate on my work laptop, pressed deploy, and wiped out everything I had built that day.
How to lose a day in one click
I work on the app from two machines: a PC at home and a laptop at work. The code on the laptop was three days old. When I deployed my little rate fix from it, the live app became that three-day-old copy plus one fix. The whole day’s work from the home PC vanished from production. The same day we found that security fixes from earlier that week were missing from production too.
We got it back by switching the live site to the previous good version, downloading thirty-odd files from it, and putting the rate fix on top. The next day I did it again, this time from an old duplicate project folder on the laptop that I had forgotten existed. I deleted that folder.
It was not the first warning. In the middle of June I had rebuilt the whole project folder on the laptop from the version running live. Four files were missing outright; without one of them the login screen hung forever. Every other file had been through an encoding accident that turned punctuation into garbage. The bookings file alone had more than 1,880 broken dashes.
The fix was a set of rules, and a script to enforce them because I knew I would forget:
- GitHub holds the one true copy of the code.
- Both PCs pull the latest version before any work starts.
- A safe-deploy script refuses to publish from a copy that is behind GitHub.
- Every deploy is logged.
On 19 July the login broke anyway. The live site held a mix of old and new files, because a half-finished change had gone out before it was saved to GitHub. Since then the order is fixed: save to GitHub, then deploy. Never the other way round.
The load that was never missing
On 1 July I could not find load 0050 on the Trips page. I assumed something had deleted it.
Nothing had. The Trips page only showed how many loads each trip contained, and the trip logic had no rule for when a trip ends. It kept adding every new load to whatever trip happened to be open, forever. Load 0050 was sitting inside a trip that had started weeks earlier.
The correct rule (a new trip starts each time the truck leaves the home depot) already existed in the code. It lived inside the kilometre report and nowhere else. We applied it to the trips themselves and split fourteen wrongly grouped trips holding 44 loads.
Who owns the next number?
Load numbers hold everything together. They tie the booking to the diesel order, the trip sheet and the invoice, and the clerks quote them on the phone all day.
On 2 July Claude found that 883 of our 963 bookings had no load number. Two causes: a bulk import that went around the app, and the free-tier database answering more slowly than a clerk could click Save, so the request for a number lost the race. On 6 July we found the counter sitting at 29999.
On 7 July we moved numbering into the database itself. It hands out the number at the moment of saving and cannot hand out the same one twice. Bookings imported from the spreadsheet arrive as drafts with no number, and only get one when I confirm them. A cancelled load keeps its number, so the gap stays visible.
One more surprise followed. On 22 July someone typed a subcontractor’s own waybill number into our load-number field. It was higher than ours, and the database politely moved the counter up to follow it. Now only numbers in our own format can move the counter.
Build it yourself: three guard rails
1. One true copy of the code. Create a private GitHub repository on day one. Then give the AI this rule in your CLAUDE.md: pull before starting work; save (commit) and push before deploying; never deploy from a folder that is behind. Better still, ask it to write a small deploy script that checks those three things and refuses to continue if any fail. Use the script every time.
2. One home for each business rule. When you find a rule hiding inside a report or a screen (“a trip starts when the truck leaves the depot”), move it to one place and make everything else use it. Ask the AI: “where else in the code does this rule appear?” The answer is often alarming.
3. Let the database own anything that must be unique. Load numbers, order numbers, invoice numbers. In a Postgres database (Supabase uses Postgres) the idea looks like this:
-- the database, not the screen, hands out load numbers
create sequence load_no_seq;
alter table loads add column load_no integer unique;
create function assign_load_no() returns trigger as $$
begin
-- drafts wait for a number; confirmed loads get the next one
if new.status <> 'draft' and new.load_no is null then
new.load_no := nextval('load_no_seq');
end if;
return new;
end $$ language plpgsql;
create trigger loads_number before insert or update on loads
for each row execute function assign_load_no();
You do not need to write that yourself. You need to know to ask for it: “make the database assign the numbers, make duplicates impossible, and keep drafts unnumbered.” Then add the second guard: only numbers in your own format may ever move the counter.
What I learned
Have one true copy of the work and make a script guard it, because you will forget. Put each business rule in exactly one place. Let the database own anything that must be unique, and assume someone will type the wrong thing into it.
Next: turning Excel chores into skills the AI can follow, and the day it told me a truck was home when it was in South Africa.
Written from my build notes. I keep a running memory of every session with the AI, and each entry is drafted from those notes with Claude's help, then checked and edited by me.
Get the next entry by email
One short email when an entry goes live, Tuesday and Friday. Nothing else, and one click to stop.
Your address is used for these emails only. It is not shared or sold.