Report History Repository
Component Detail
Description
Data access layer for persisting and querying Bufdir report history records in the organization-scoped Supabase table. Handles all CRUD operations and ensures row-level security filters are respected.
report-history-repository
Summaries
The Report History Repository is the foundational data persistence layer that makes the entire report history feature reliable and auditable. It ensures every Bufdir submission is permanently recorded with full metadata — period, generating user, timestamp, and file reference — providing an immutable audit trail that satisfies regulatory and grant-compliance requirements. By enforcing organisation-scoped row-level security, it guarantees that one organisation can never access another's records, a critical data isolation requirement for a multi-tenant platform. The repository's pagination support means the system remains performant as organisations accumulate years of report history.
Low-complexity data layer component with no external service dependencies, making it an ideal early-sprint deliverable that unblocks both the Report History Service and the Report Re-export Coordinator. The primary planning consideration is schema alignment: the bufdir-report-record table structure must be finalised and migrated in Supabase before any repository method can be tested end-to-end. Row-level security policies must be reviewed and approved by the infrastructure team before UAT. Testing scope includes insert, query, update, delete, pagination boundary conditions, and RLS policy enforcement with both matching and non-matching org IDs.
Performance testing with large history sets should be scheduled before production launch.
Report History Repository is the Supabase-backed data access layer for the bufdir_report_history table, executing exclusively in the backend context. insertReportRecord(record) performs a typed insert returning the created row's ID for downstream reference. getHistoryByOrg(orgId, {limit, offset}) applies an eq filter on org_id plus range-based pagination — ensure the query includes an order_by generated_at DESC clause for consistent results. updateFileRef(reportId, fileRef) is used by the Re-export Coordinator after re-generation.
deleteRecord(reportId) should be guarded by a soft-delete flag if audit retention is required. Row-level security in Supabase handles org isolation at the database level, but the repository should still pass the authenticated user's JWT context to Supabase client calls to ensure RLS policies are correctly evaluated.
Responsibilities
- Insert new report history records after successful export
- Query report history with organization scoping
- Update file reference after re-export
- Support pagination for large history sets
Interfaces
insertReportRecord(record)
getHistoryByOrg(orgId, {limit, offset})
getRecordById(reportId)
updateFileRef(reportId, fileRef)
deleteRecord(reportId)
countByOrg(orgId)
Relationships
Dependents (2)
Components that depend on this component
Related Data Entities (3)
Data entities managed by this component