Define ClaimApproval database schema and Dart models
epic-expense-approval-workflow-foundation-task-003 — Create the claim_approval_decisions table in Supabase with columns for decision_id, claim_id, coordinator_id, decision (approved/rejected/escalated), justification, threshold_at_decision, decided_at, and full coordinator metadata snapshot. Define Dart model classes. Apply RLS so coordinators can only insert decisions for claims in their chapter scope.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 1 - 540 tasks
Can start after Tier 0 completes
Implementation Notes
The coordinator_snapshot JSONB column is a deliberate denormalization for audit integrity — if a coordinator's role or chapter changes later, historical decisions must still reflect the context at time of decision. Populate this snapshot in the application layer (repository) by reading the current coordinator profile from the auth session and user profile before inserting. The threshold_at_decision column solves a similar problem for threshold values — the application must query the active approval threshold and include it in the insert payload, not rely on a database default. For the Dart model, use a const constructor and override == and hashCode for value equality — useful in BLoC state comparisons.
Use the same migration version sequencing as task-001 to ensure dependency order is clear.
Testing Requirements
Unit tests: ClaimApprovalDecision.fromJson() and toJson() round-trip for all three ApprovalDecision values, nested CoordinatorSnapshot serialization, null justification handling, decided_at UTC parsing. Integration tests against Supabase test instance: INSERT succeeds when coordinator owns the claim's chapter, INSERT fails with 42501 when coordinator does not own the claim's chapter, SELECT returns only decisions within coordinator's scope, UPDATE attempt returns 42501, verify coordinator_snapshot is stored as provided (not a live JOIN).
Optimistic locking in ExpenseClaimStatusRepository may produce excessive concurrency exceptions in high-volume coordinator sessions where multiple coordinators process the same queue simultaneously, causing confusing UI errors and coordinator frustration.
Mitigation & Contingency
Mitigation: Design the locking strategy with a short retry window (1-2 automatic retries with 200ms back-off) before surfacing the error to the UI. Document the concurrency model clearly so the UI layer can display a contextual 'claim was already actioned' message rather than a generic error.
Contingency: If contention remains high under load testing, switch to a last-writer-wins update with a conflict notification rather than a hard block, and log all concurrent edits for audit purposes.
FCM device tokens stored for peer mentors may be stale (app reinstalled, token rotated) causing push notifications for claim status changes to silently fail, leaving submitters unaware their claim was approved or rejected.
Mitigation & Contingency
Mitigation: Implement token refresh on every app launch and store updated tokens in Supabase. ApprovalNotificationService should fall back to in-app Realtime delivery when FCM returns an invalid-token error and should queue a token refresh request.
Contingency: If FCM delivery rates fall below acceptable thresholds in production monitoring, add a polling fallback in the peer mentor claim list screen that checks status on foreground resume.
Supabase Realtime has per-project channel and connection limits. If many coordinators and peer mentors are simultaneously subscribed across multiple screens, the project may hit quota limits causing subscription failures.
Mitigation & Contingency
Mitigation: Design RealtimeApprovalSubscription to use a single shared channel per user session rather than per-screen subscriptions. Implement subscription reference counting so channels are only opened once and reused across screens.
Contingency: Upgrade the Supabase plan tier if limits are reached, and implement graceful degradation to polling with a 30-second interval when Realtime is unavailable.