docs(catalogs): DELETE /api/catalogs/{catalogId} contract + cascade semantics (chat#1942)
Row 4 of chat#1942. Contract-first; the api implementation follows.
Stacked on docs#292 (branch docs/catalog-rename-contract), which introduces the /api/catalogs/{catalogId} path object this adds a delete operation to. Both target main; merge #292 first and this diff reduces to the DELETE alone.
The contract
DELETE /api/catalogs/{catalogId} → { "status": "success", "catalog_id", "released_snapshot_ids": [] }, plus 400 / 401 / 404 / 500 on the existing CatalogsErrorResponse. Same visibility rule as the rename: a catalog you cannot see is a 404, not a 403.
What it deletes, and what it must not
Measured against one real 86-song catalog (issue table) and confirmed against the migrations, since every one of these is enforced by an FK, not by application code:
| Table | FK on catalogs(id) | Result |
|---|---|---|
catalog_songs | ON DELETE CASCADE (migration) | removed |
account_catalogs | ON DELETE CASCADE (migration) | removed |
catalog_valuations | ON DELETE CASCADE (database#52) | removed |
playcount_snapshots | ON DELETE SET NULL (migration) | survives, reference cleared |
That last row is the whole point, and it resolves the open question the issue left on catalog_valuations ("keep as history, or cascade"): cascade. A valuation row is a derived band — recomputable from the surviving snapshot on the next read — whereas the snapshot is a metered capture that spent the customer's credits and cannot be re-taken for a past date. Cheap objects may cascade; the expensive one may not.
The database already encodes exactly this, so the contract documents the FK semantics rather than inventing application-level cascade logic.
Recovery is the reason for released_snapshot_ids
Clearing the reference re-opens the idempotent re-claim path in createCatalogHandler, so a deleted catalog can be rebuilt from the same measurement under a correct name. That is only usable if the caller can still find the snapshot — so the delete returns the ids it released, and the reference page spells out the POST /api/catalogs { snapshot, name } round trip.
Files
api-reference/openapi/releases.json—deleteoperation +DeleteCatalogResponse. Purely additive: 102 insertions, 0 deletions; re-parsed after the edit.api-reference/songs/catalog-delete.mdx— reference page, with a warning steering name fixes to rename instead.docs.json— nav entry under Catalogs.
🤖 Generated with Claude Code
Summary by cubic
Adds the DELETE operation at /api/catalogs/{catalogId} with clear cascade rules and snapshot retention, returning released_snapshot_ids for recovery. Applies the 404 visibility rule; addresses chat#1942.
- New Features
- OpenAPI: adds
deleteto/api/catalogs/{catalogId}; definesDeleteCatalogResponse(required:status,catalog_id,released_snapshot_ids); errors reuseCatalogsErrorResponse; 404, not 403; changes are additive inreleases.json. - Cascade/retention: deletes
catalog_songs,account_catalogs,catalog_valuations; keepsplaycount_snapshotsvia ON DELETE SET NULL; recovery via POST/api/catalogswith{ snapshot, name }. - Docs: adds
api-reference/songs/catalog-delete.mdxand nav entry; removes frontmatter descriptions on delete and rename pages so the full OpenAPI description renders.
- OpenAPI: adds
Summary by CodeRabbit
- Documentation
- Added API reference documentation for deleting a catalog.
- Documented authentication requirements, validation rules, response statuses, and error scenarios.
- Added details about the deleted catalog and released snapshot IDs returned by the endpoint.
- Added the new page to the Catalogs navigation.