Document adapter API and migration instructions
epic-multi-chapter-membership-handling-foundation-task-007 — Write developer documentation covering the contact_chapters migration steps (how to apply and roll back), the ContactChapter domain model fields and constraints, the public API surface of SupabaseContactChapterAdapter including method signatures and expected error types, and RLS policy intent. Include a note on the NHF multi-chapter requirement (members in up to 5 local chapters) and how this adapter satisfies it without double-counting in Bufdir reports.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 5 - 253 tasks
Can start after Tier 4 completes
Implementation Notes
Structure the documentation in a single `CONTACT_CHAPTER_ADAPTER.md` file placed in `docs/adapters/`. Sections in order: (1) Overview & Business Context, (2) Database Migration, (3) Domain Model Reference, (4) Adapter API Reference, (5) RLS Policy Reference, (6) NHF Multi-Chapter Business Rules, (7) Quick Start. For the API reference, use a Dart doc comment block style inside the markdown for each method — this keeps it familiar for Dart developers. The NHF multi-chapter section should explicitly state: 'A contact may appear in up to 5 contact_chapters rows (enforced by application-level validation in the Cubit and by a CHECK constraint added in the migration).
The adapter never aggregates member counts across chapters; aggregation for Bufdir reporting is handled at the reporting layer to prevent double-counting.' Keep the document under 600 lines — prefer concise method tables over verbose prose.
Testing Requirements
Documentation review checklist: (1) All method signatures match the implemented code exactly — run a grep/search to verify. (2) Migration SQL commands are tested in a clean local environment before documenting. (3) All Dart code snippets compile without errors. (4) Peer review by at least one other developer who has not worked on this component to validate clarity.
No automated tests required for this task, but the documentation should enable a developer unfamiliar with the component to complete the Quick Start without asking questions.
Supabase RLS policies for a junction table that spans organisations are non-trivial. An incorrectly scoped policy could expose chapter affiliations from other organisations to coordinators, constituting a data breach.
Mitigation & Contingency
Mitigation: Draft RLS policies in a staging environment and run an explicit cross-organisation isolation test suite before merging. Use Supabase policy testing tools and peer review all policy definitions.
Contingency: If a policy error reaches review, roll back the migration and apply a corrective patch. Ensure no production data has been exposed by auditing Supabase logs for cross-organisation query results.
The contact_chapters table migration may conflict with existing foreign key structures or require a backfill for contacts already assigned to a single chapter, causing migration failures in production.
Mitigation & Contingency
Mitigation: Write the migration as an additive, non-destructive operation. Backfill existing single-chapter assignments by deriving them from the existing contact records. Test the full migration on a production-sized dataset clone before release.
Contingency: Provide a rollback migration script that removes the new table without touching existing contact records. Coordinate with operations for a maintenance window if a re-run is needed.