soft-delete-strategy

Implement soft deletes with deleted_at filters, partial indexes, and scheduled hard purges.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/marquesfelip/agents-and-skills --skill soft-delete-strategy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: soft-delete-strategy
Source: https://github.com/marquesfelip/agents-and-skills/tree/main/skills/soft-delete-strategy
Command: npx skills add https://github.com/marquesfelip/agents-and-skills --skill soft-delete-strategy

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Reversible deletion patterns enable teams to delete SaaS records safely while preserving the ability to undo, archive for records, and purge data in a compliant, auditable manner.

Core Features & Use Cases

  • Soft delete via a deleted_at timestamp to keep historical context without exposing deleted rows in normal queries.
  • Restore/undelete workflows with transactional integrity and conflict checks when restoring (e.g., slug or unique constraints).
  • Hard purge scheduling with a retention window to meet data-minimization and compliance requirements, including cascading deletes across related entities.

Quick Start

Add a deleted_at column to your tables, set up a partial index for active records, and implement the soft delete, restore, and purge workflows.

Frequently Asked Questions about soft-delete-strategy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a soft delete strategy in PostgreSQL for SaaS records?

Implement a soft delete by adding a deleted_at timestamp to your tables to hide rows from normal queries. Use partial indexes to preserve unique constraints for active records and schedule a daily hard purge to maintain compliance.

What's the best way to restore soft deleted records without violating unique constraints?

Restoring soft deleted records requires transactional integrity and conflict checks to prevent violations of unique constraints like slugs. The restore workflow validates these constraints before undeleting the cascaded related entities.

How do cascading deletes work with a paranoid delete pattern across related entities?

Cascading soft deletes propagate the deleted_at timestamp across related entities, such as projects and documents, within a single transaction. This ensures that restoring or purging parent records automatically processes all dependent child rows.

When do I need a hard purge workflow for data retention and compliance?

A hard purge workflow is needed to meet data-minimization and compliance requirements after a defined retention window. It permanently removes soft deleted records and their related entities to enforce scheduled data expiration.

Does PostgreSQL partial indexing solve unique constraint issues with deleted_at rows?

Partial indexes solve unique constraint conflicts by indexing only rows where deleted_at is null. This allows identical slug or email values to exist across deleted records without breaking uniqueness rules for active data.

How do I automatically filter soft deleted rows out of normal database queries?

Query filtering applies a default condition to exclude rows where deleted_at is not null. This ensures normal application queries never expose soft deleted records while preserving them for audit trails and historical context.