PR #272 · pramaan-io/pramaan-functions · merged 2026-06-08
When a filing type disappears, its history disappears with it.
No archive, no soft delete, no audit — and references dangling.
Row gone. References orphan. Audit trail lost.
The fix — Archive, never shred; reference once, track forever.
sequenceDiagram autonumber participant card as filing_type (catalog card) participant lib as lifecycle (librarian) participant bor as snapshot / template (borrower) card->>card: FT-002 issued, live card->>lib: request: archive this card lib->>bor: who has this card on loan? bor->>lib: 8 snapshots + 4 templates lib-->>card: flip availability row retained card->>card: FT-002 permanent, never reissued
| Method | in → out | what it does |
|---|---|---|
_in_use_references | (filing_type_id, firm_id) → tuple[InUseReference, ...] | lists snapshots and templates borrowing this filing type, blocking blind delete |
_usage_count | (db, filing_type_id, firm_id) → int | counts active borrowers so the UI shows how busy this card is |
archive_filing_type | (db, filing_type_id) → FilingTypeDetailView | moves the card to the back room — flag flips, row retained |
unarchive_filing_type | (db, filing_type_id) → FilingTypeDetailView | brings the card back to the live shelf if the firm needs it again |
Alembic migration adds the availability lifecycle, archive/delete audit columns, and per-firm filing_type_number to business.filing_types, and rewrites the reference-kind constraint to allow filing_type as a valid kind.
| new method | signature |
|---|---|
_replace_reference_kind_constraint | (include_filing_type) → None |
upgrade | () → None |
downgrade | () → None |
revision : strdown_revision : str | Sequence[str] | Nonebranch_labels : str | Sequence[str] | Nonedepends_on : str | Sequence[str] | NoneFiling type service gains archive/unarchive actions plus in-use reference and usage-count checks, killing the naive hard-delete path that would orphan matter snapshots and matter-type templates.
| new method | signature |
|---|---|
_list_item | (row, usage_count) → FilingTypeListItem |
_in_use_references | (filing_type_id, firm_id) → tuple[InUseReference, ...] |
_usage_count | (db, filing_type_id, firm_id) → int |
archive_filing_type | (db, filing_type_id) → FilingTypeDetailView |
unarchive_filing_type | (db, filing_type_id) → FilingTypeDetailView |
Filing type entity gains availability, filing_type_number, and audit columns (archived_at, archived_by_user_id, deleted_by_user_id, created_by_user_id) so every row carries its own provenance.
filing_type_number : intavailability : strcreated_by_user_id : UUID | Nonearchived_at : datetime | Nonearchived_by_user_id : UUID | Nonedeleted_by_user_id : UUID | NoneFiling type DTOs surface availability, formatted filing_type_number, archive timestamps, usage count, and is_in_use / can_delete flags for the API and management UI.
| new class | signature |
|---|---|
FilingTypeAvailability | (class) |
_trim_name | (value) → str | None |
_trim_description | (value) → str | None |
availability : FilingTypeAvailabilityinclude_archived : boolfiling_type_number : intfiling_type_number_formatted : strarchived_at : datetime | Nonearchived_by_user_id : UUID | Noneusage_count : intis_in_use : boolcan_delete : boolcreated_by_user_id : UUID | NoneFiling type repository helpers (current_user_id, find_live_by_name, create) carry the actor and the new filing_type_number allocation into inserts.
| new method | signature |
|---|---|
current_user_id | (db) → UUID |
find_live_by_name | (db, name, excluding_filing_type_id) → FilingType | None |
create | (db, data, filing_type_number, created_by_user_id) → FilingType |
HTTP router exposes archive and unarchive endpoints and the management-only include_archived listing flag, bringing filing types to forum parity.
| new method | signature |
|---|---|
archive_filing_type | (filing_type_id, db, _) → FilingTypeDetailView |
unarchive_filing_type | (filing_type_id, db, _) → FilingTypeDetailView |
include_archived : Annotated[Shared formatter format_filing_type_ref renders the per-firm filing type number as the human-readable FT-001 string used across the platform.
| new method | signature |
|---|---|
format_filing_type_ref | (filing_type_number) → str |