docs(catalogs): DELETE /api/catalogs/{catalogId} contract + cascade semantics (chat#1942)

Merged
SW
4mo ago
+111-1

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:

TableFK on catalogs(id)Result
catalog_songsON DELETE CASCADE (migration)removed
account_catalogsON DELETE CASCADE (migration)removed
catalog_valuationsON DELETE CASCADE (database#52)removed
playcount_snapshotsON 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 — delete operation + 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 delete to /api/catalogs/{catalogId}; defines DeleteCatalogResponse (required: status, catalog_id, released_snapshot_ids); errors reuse CatalogsErrorResponse; 404, not 403; changes are additive in releases.json.
    • Cascade/retention: deletes catalog_songs, account_catalogs, catalog_valuations; keeps playcount_snapshots via ON DELETE SET NULL; recovery via POST /api/catalogs with { snapshot, name }.
    • Docs: adds api-reference/songs/catalog-delete.mdx and nav entry; removes frontmatter descriptions on delete and rename pages so the full OpenAPI description renders.

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.