Create Supabase schema for recurring activity templates
epic-coordinator-proxy-registration-foundation-task-001 — Write and apply Supabase migration to create the recurring_activity_templates table with columns for template name, activity type, duration defaults, recurrence pattern, coordinator_id, org_id, and timestamps. Include Row Level Security policies scoped to coordinator's organization.
Acceptance Criteria
Technical Requirements
Implementation Notes
Use Supabase CLI migrations workflow (supabase migration new). Define recurrence_pattern as TEXT with a CHECK constraint rather than a custom ENUM to avoid painful ALTER TYPE migrations later if new patterns are added. The duration_minutes column should default to 30 to align with the workshop requirement that 30 minutes is the standard default for HLF (380 registrations/year use case). Store recurrence_pattern as a free-form JSON string in a notes column if structured recurrence (e.g., 'every Monday at 10:00') is needed in future — keep the initial column simple.
Ensure the FK to organizations uses ON DELETE CASCADE so template orphans are avoided if an org is removed.
Testing Requirements
Write SQL-level tests (using pgTAP or Supabase's built-in test runner) verifying: (1) a coordinator can insert a template for their own org, (2) a coordinator cannot insert a template for a different org, (3) a coordinator can read their org's templates but not another org's, (4) a coordinator can delete their own template but not another coordinator's template within the same org, (5) updated_at is automatically set on update. Run migration against a local Supabase instance and confirm all tests pass before merging.
Supabase RLS policies for org-scoped proxy access may be difficult to express correctly, especially for coordinators with multi-chapter access. An overly permissive policy could allow cross-org proxy registrations, corrupting Bufdir reporting; an overly restrictive policy could block legitimate coordinators from registering.
Mitigation & Contingency
Mitigation: Write integration tests covering all access boundary cases (same org, cross-org, multi-chapter coordinator) before merging any RLS migration. Use parameterised RLS test helpers already established by the auth feature.
Contingency: If RLS proves insufficient, add a server-side Edge Function validation layer that re-checks org membership before persisting any proxy record, providing defence in depth.
Adding new tables and foreign key constraints to an existing production Supabase database risks migration failures or locking issues if the database already contains active sessions during deployment.
Mitigation & Contingency
Mitigation: Use additive-only migrations (no DROP or ALTER on existing tables). Test full migration sequence in a staging Supabase project before production deployment. Schedule during low-traffic window.
Contingency: Maintain a rollback migration script. If the migration fails, the feature remains unreachable behind a feature flag while the schema issue is resolved.
Audit log entries must be immutable for compliance, but Supabase RLS by default allows row owners to update their own rows. If audit records are accidentally mutable, dispute resolution and accountability guarantees are invalidated.
Mitigation & Contingency
Mitigation: Configure the proxy_audit_log table with an RLS policy that allows INSERT for coordinators but denies UPDATE and DELETE for all roles including service_role, enforced at the database level.
Contingency: If RLS cannot fully prevent updates, create a database trigger that reverts any UPDATE to the audit table and logs the attempt as a security event.