# Trash

> Soft delete through each subject's deletedAt column: trash with children in one batch, restore with unique checks, a list per organization, and purge after a retention period, skipped for subjects under a legal hold.

- Category: Database primitives
- Module: `trash`
- Modes: `managed`, `custom`
- Docs: https://bettersupabase.com/docs/blocks/trash
- Page: https://bettersupabase.com/blocks/trash

## Install

```bash
npx better-supabase add trash
```

The command also installs `updated-at`, `memberships`, `permissions`, `housekeeping`.

## Configure

Add the block to `better-supabase.config.ts`:

```ts
import { defineConfig } from "better-supabase/config";

export default defineConfig({
  blocks: {
    // Required by trash; add installs them too.
    "updated-at": {},
    memberships: {},
    permissions: {},
    housekeeping: {},
    // Modes: "managed", "custom". The default is "managed".
    trash: { mode: "managed" },
  },
});
```

## Client

The block has no React entry yet. Its server-side TypeScript is in `better-supabase/blocks/trash`.

## Events

- `subject.purged`
- `subject.restored`
- `subject.trashed`

## Related blocks

Requires: [memberships](https://bettersupabase.com/blocks/memberships.md), [permissions](https://bettersupabase.com/blocks/permissions.md), [housekeeping](https://bettersupabase.com/blocks/housekeeping.md)

Works with: [outbox](https://bettersupabase.com/blocks/outbox.md), [audit](https://bettersupabase.com/blocks/audit.md), [data-lifecycle](https://bettersupabase.com/blocks/data-lifecycle.md), [housekeeping](https://bettersupabase.com/blocks/housekeeping.md), [bulk-actions](https://bettersupabase.com/blocks/bulk-actions.md)

## Recipes

- [Undo toast](https://bettersupabase.com/recipes/undo-toast.md): A toast after a delete with a button that restores the record from the trash.
- [Trash bin](https://bettersupabase.com/recipes/trash-bin.md): Deleted records with buttons to restore them or delete them for good.
