soft-delete
Skill2 starsChanged 4 months agoMITView on GitHub
Convert hard deletes into recoverable soft deletes — mark rows deleted instead of removing them, filter them out of normal reads, and keep uniqueness and foreign keys correct — so data can be restored and history preserved. Use when the user says "add soft delete", "make deletes recoverable", "don't actually delete rows", "add a deleted_at column", "archive instead of delete", "add a trash/restore feature", or "we need to undo deletes".
In this repository68 other files it gives its agents.
- a11ySkill
- api-docsSkill
- audit-logSkill
- benchmarkSkill
- bisectSkill
- cacheSkill
- changelogSkill
- cherry-pickSkill
- ci-setupSkill
- codeownersSkill
- commit-messageSkill
- connection-poolSkill
- contributingSkill
- coverageSkill
- db-migrateSkill
- dead-codeSkill
- debugSkill
- depsSkill
- diagramSkill
- dockerizeSkill
- docstringSkill
- e2eSkill
- env-exampleSkill
- error-handlingSkill
- explainSkill
- feature-flagSkill
- flaky-testSkill
- gitignoreSkill
- graceful-shutdownSkill
- graphqlSkill
- healthcheckSkill
- i18nSkill
- idempotencySkill
- licenseSkill
- lint-fixSkill
- loggingSkill
- migrateSkill
- mockSkill
- onboardSkill
- optimizeSkill
- paginationSkill
- pr-descriptionSkill
- pre-commitSkill
- profileSkill
- prune-branchesSkill
- rate-limitSkill
- readmeSkill
- rebaseSkill
- refactorSkill
- regexSkill
- releaseSkill
- resolve-conflictsSkill
- retrySkill
- review-diffSkill
- scaffoldSkill
- secrets-scanSkill
- security-headersSkill
- seedSkill
- sqlSkill
- squashSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
Verify: Test that a delete hides the row from normal reads but keeps it in the table, that restore brings it back, that a soft-deleted …
- Distinctive: line 31
Keep a real hard-delete/purge path for compliance erasure and table growth — soft delete augments deletion, it doesn't replace the ability …
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
ORM, schema & delete-site signals
!grep -rilE "deleted_at|deletedAt|soft.?delete|paranoid|SoftDelete|prisma|sequelize|typeorm|sqlalchemy|django|knex|mongoose|DELETE FROM|\\.destroy\\(|\\.delete\\(" --include='*.*' package.json pyproject.toml go.mod Gemfile 2>/dev/null | grep -vE 'node_modules|\.git|dist|build' | head -8
Instructions
Make deletes on the model/table in $ARGUMENTS recoverable instead of destructive. The core is a nullable deleted_at timestamp, but the subtle parts are making every read exclude deleted rows and keeping constraints valid — get those wrong and you silently leak deleted data or block legitimate re-creates.
Method
- Add the marker column. A nullable
deleted_at TIMESTAMP(null = live) is preferred over a boolean — it records when, and often who alongside (deleted_by). Generate a migration with a safe up/down (see thedb-migrateskill) and indexdeleted_atif you'll query by it. - Change delete to an update. Replace hard
DELETE/.destroy()calls with settingdeleted_at = now(). Offer arestore(set it back to null) and keep a genuine hard-delete path available for GDPR/erasure and admin purge — soft delete is not a substitute for the right to be forgotten. - Filter deleted rows from all normal reads — this is the trap. Apply a default scope so every query excludes
deleted_at IS NOT NULL. Prefer the ORM's built-in mechanism (TypeORM/Sequelizeparanoid, Django manager, a Prisma extension/middleware, Railsdefault_scope) so no query site is forgotten. Audit existing queries, joins, aggregates, and raw SQL — a single unscopedSELECTorCOUNTleaks or miscounts deleted data. - Fix uniqueness. A plain
UNIQUE(email)will reject re-creating a record whose old row was soft-deleted. Switch to a partial/filtered unique index (UNIQUE(email) WHERE deleted_at IS NULL) or includedeleted_atin the key, so a live value is unique but deleted rows don't block reuse. - Handle relations and cascades. Decide what happens to children of a soft-deleted parent (cascade the soft delete, or block/orphan) — a real
ON DELETE CASCADEwon't fire since no row is removed. Make sure foreign-key lookups from live rows don't resolve to deleted parents. - Mind the trade-offs. Tables grow unbounded — plan periodic pur/archival of long-deleted rows. Consider pairing with an
audit-logentry on delete/restore. Note that unique-index and count changes can surprise other features. - Verify. Test that a delete hides the row from normal reads but keeps it in the table, that restore brings it back, that a soft-deleted unique value can be re-created, and that no relationship/aggregate query returns deleted rows.
Rules
- Deletes set
deleted_at; every normal read must exclude soft-deleted rows via a default scope — audit joins, aggregates, and raw SQL, since one unscoped query leaks deleted data. - Convert unique constraints to partial/conditional uniqueness on live rows, or soft-deleted rows will block re-creating the same value.
- Keep a real hard-delete/purge path for compliance erasure and table growth — soft delete augments deletion, it doesn't replace the ability to truly remove data.
- Address relations explicitly (cascade or block the soft delete of parents with children); don't rely on database
ON DELETE CASCADE, which won't fire. - Provide a restore path and end by summarizing the column added, how reads are scoped, the uniqueness fix, relation handling, and the purge/retention plan.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

