- Private CRM: an AI CRM where Claude does the data entry and you make the calls · part 3 of 12
- Laravel
- Rust
- CRM
Archive instead of delete: why my CRM never removes a row
Private CRM has no delete routes. Records are archived with who and when, and an activity log keeps every change for ever. Here is how it works and what broke.
5 min read
Private CRM has no delete button. Not on contacts, not on deals, not on API tokens. Every delete route was removed in one commit, and the only way a row leaves a list is by being archived, with a timestamp and a name on it.
Here's why, how one route handles every kind of record, and the permission bug that generic route introduced within the hour.
Why nothing gets deleted
A CRM is a memory. The deal you lost in March tells you something in September. The contact a colleague removed by mistake is a client someone has to call back. Deleted rows also break things quietly: an order pointing at a product that no longer exists, an activity log line about a record you can't open.
So the rule became: nothing is ever deleted. Contacts and companies got archived_at and archived_by first, when they were split out of "customers" (part 2). One commit later deals, orders, products, tasks, plus API tokens, got the same two columns, and every delete route went away.
Archived rows drop out of every list, every total, the search box, the MCP tools and token sign-in. An archived API token stops working on the next request.
One route for every kind
Instead of a destroy handler per resource, there is one route:
// Nothing is deleted: records are archived and restored here, and stay in the database for ever.
route.get("/archives", archives::index);
route.post("/archives/{kind}/{id}", archives::store);
route.delete("/archives/{kind}/{id}", archives::destroy);
store archives, destroy restores. The handler first loads the record and checks the user may see it, using the same policy as the record's own page. Then a small macro stamps the row:
macro_rules! stamp {
($model:ident, $id:expr, $at:expr, $by:expr) => {
$model::query()
.filter($model::id.eq($id))
.update()
.archived_at($at)
.archived_by($by)
.await?
};
}
The Archive page lists everything archived with who did it and when, and restores any of it. Only roles with "archive and restore" see the buttons and the page.
The regression a generic route caused
Merging seven destroy handlers into one looked like a clean win. It also dropped a check.
The old delete handlers for products and orders checked "manage products" and "manage orders". The generic archive handler only checked "archive and restore" plus visibility. So someone allowed to archive, but not to manage products, could suddenly archive a product.
The fix put the checks back inside the match arm for each kind:
"product" => {
user.authorize(PermissionPolicy::allows, &Permission::ManageProducts).await?;
Product::find_or_fail(id).await?.name
}
Same for orders, plus a check that the reader can see the order's contact. Archiving, restoring and the Archive list all check it now.
A second fix went the other way. Revoking an API token is an archive, so it needed the archive permission. That's wrong: if your token leaks, you should be able to kill it right away without asking an admin. Now revoking your own token needs no extra permission, and the handler still checks that the token is yours.
Lesson learned: when you merge handlers, list every check each old handler made before you delete it.
An activity log kept for ever
Archiving answers "where did it go". The next commit answered "who changed it": an audit_logs table that is never edited or emptied. It records:
- every page a signed-in person opens
- every create and update, with each changed field's old and new value (a deal moved from Won back to Negotiation, a contact's phone before and after)
- notes and calls logged on deals
- archives and restores
- sign-ins, sign-outs and failed sign-ins
Model events write the change lines. A web middleware puts the acting user into the request context and logs page views, skipping Inertia partial reloads and prefetches, so a page that polls every 30 seconds doesn't flood the log. Changes made over MCP carry the token that made them, so you can tell a person's edit from an agent's. Passwords and tokens are never logged.
The Activity log page filters by person, action, record type and date, gated on a "read the activity log" permission. As covered in part 2, it is also scoped: a reader who can't see everyone's records gets their own lines and their team's, nothing else. A log of old and new values is a copy of the data, so it needs the same access rules as the data.
Later: links that survive
The "never delete" rule got a database-level backstop during the code review (part 12). Tasks can link to a deal or a contact, and a migration added foreign keys that set the link to null if the record is ever deleted. Dangling links were cleared before the constraint went on. Nothing in the app deletes, but the database shouldn't rely on that.
And when AI agents got write access over MCP, a test made sure none of them could archive anything either:
for word in ["delete", "remove", "archive", "destroy"] {
assert!(!name.contains(word), "{name} must not be an MCP tool");
}
If someone adds a delete_contact tool later, the suite fails before any agent can call it.
Try it in your own app
Add archived_at and archived_by to your tables, filter archived rows out at the query layer, and give your app one archive route instead of one per resource. Then go back and copy every permission check from the handlers you removed. If you self-host, the self-hosted security checklist pairs well with an audit log like this.
Part 4 is about money: why Private CRM stores amounts in thousandths, not cents.
Last updated 4 Dec 2026 · filed under Laravel, rust, crm