[Story-1078] Add forum human-readable numbers

Story 1078Epic None17 files · +496/−19

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

Why this matters

Forums you can't quote are forums that get lost.

Why a human-readable forum number matters.

Two firms. Two F-001s. One confused counsel.

The fix — One firm-scoped slip, allocated once, formatted once, never reissued.

How it flows

sequenceDiagram
  autonumber
  participant client as Client
  participant service as Forum Service
  participant alloc as Reference Allocator
  participant db as Reference Counter (DB)
  participant fmt as Formatter
  client->>service: create forum
  service->>alloc: allocate_reference(firm, 'forum')
  alloc->>db: increment counter atomically
  db->>alloc: next integer
  alloc->>service: return integer
  service->>service: persist Forum with forum_number
  service->>fmt: format_forum_ref(n)
  fmt->>service: F-001
  service->>client: ForumView

4c8e9f1a2b70_0079_forum_human_readable_number.py · +172 — new methods

Methodin → outwhat it does
_create_support_reference_counter_policies() → None
_drop_support_reference_counter_policies() → None
_replace_reference_kind_constraint(include_forum) → None

What changed, file by file

Extends the counter kind check to admit 'forum', adds RLS policies, seeds per-firm counters via deterministic backfill. Maps to counter-reuse + migration claim.

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

Adds the integer forum_number field on the Forum entity, allocated for new forums and backfilled for existing ones by the migration.

New fields: forum_number : int

New formatter turning a forum number integer into the human-readable F-zero-zero-one string. Maps to format claim.

new methodsignature
format_forum_ref(forum_number) → str

Exposes forum_number and forum_number_formatted on the ForumView DTO. Maps to format claim.

New fields: forum_number : intforum_number_formatted : str

Reference counter model that allocate_reference reads and increments atomically per firm and kind. Maps to counter-reuse claim.

new classsignature
ReferenceCounter(type)

Files changed (17)

File±
alembic/versions/4c8e9f1a2b70_0079_forum_human_readable_number.py ★+172
docs/walkthroughs/story-1078-walkthrough.html+106
openapi/app-api.json+12
src/domains/forum/AGENTS.md ★+19 −7
src/domains/forum/dtos/forum.py+8
src/domains/forum/entity.py ★+22 −1
src/domains/forum/service.py+14
src/domains/reference_counter/__init__.py+3 −2
src/domains/reference_counter/entity.py+5 −4
src/shared/constants/firm_status.py+2 −1
src/shared/formatters/forum_ref.py+14
tests/contract/test_app_forums_openapi.py+4
tests/integration/test_app_forums.py+26 −2
tests/integration/test_app_matters.py+9 −2
tests/integration/test_updated_at_triggers.py+4
tests/shared/formatters/test_forum_ref.py+25
tests/unit/test_forum_number_migration.py+51