[Bug-1085] Decouple filing types from matter types

Story 1085Epic None22 files · +343/−1067

PR #276 · pramaan-io/pramaan-functions · merged 2026-06-08

Why this matters

Filing type delete was blocked by a ghost reference

A stale matter-type link kept real filing types undeletable

The association was a ghost — the real retention lives in the matter snapshot, not the dropdown.

The fix — Delete guard now checks the only thing that retains a filing type — the matter snapshot.

How it flows

sequenceDiagram
  autonumber
  participant ui as Admin UI
  participant api as Filing type API
  participant db as Database
  ui->>api: DELETE filing type
  api->>api: Check real retained references only
  api->>db: Query matter_snapshot_filing_types
  api->>api: Zero rows → safe to delete
  api-->>db: Drop the row

alembic/versions/3d7c9e2f1a84_0084_drop_matter_type_filing_types.py

Methodin → outwhat it does
upgrade() → NoneDrops the matter_type_filing_types table along with its RLS policies and grants so the stale coupling cannot reappear.
downgrade() → NoneRestores the association table and its RLS policies and grants if a rollback is ever needed.

What changed, file by file

Alembic migration that drops the matter_type_filing_types table and its RLS policies and grants, executing the core decoupling claimed in the PR summary.

new methodsignature
upgrade() → None
downgrade() → None
New fields: revision : strdown_revision : str | Sequence[str] | Nonebranch_labels : str | Sequence[str] | Nonedepends_on : str | Sequence[str] | None

Files changed (22)

File±
alembic/env.py+1 −1
alembic/versions/3d7c9e2f1a84_0084_drop_matter_type_filing_types.py ★+183
openapi/app-api.json+3 −416
src/app_api/router_filing_types.py+0 −41
src/domains/filing_type/AGENTS.md+0 −1
src/domains/filing_type/__init__.py+2 −2
src/domains/filing_type/dtos/__init__.py+0 −4
src/domains/filing_type/dtos/filing_type.py+1 −22
src/domains/filing_type/entity.py+0 −68
src/domains/filing_type/repository.py ★+5 −110
src/domains/filing_type/service.py ★+4 −151
src/domains/matter/redesign_service.py+0 −38
src/domains/matter_type/dtos/__init__.py+0 −4
src/domains/matter_type/dtos/matter_type.py+1 −20
src/domains/matter_type/repository.py+1 −49
src/domains/matter_type/service.py+1 −17
src/shared/db/entities.py+1 −2
tests/contract/test_app_filing_types_openapi.py+1 −1
tests/integration/test_app_filing_types.py+136 −85
tests/integration/test_app_matter_redesign.py+1 −31
tests/integration/test_app_matter_types.py+2 −3
tests/integration/test_rls_isolation.py+0 −1