Document spatial infrastructure setup and RLS policies
epic-geographic-peer-mentor-map-data-infrastructure-task-014 — Write developer documentation covering: how to run the PostGIS migrations locally, how the bounding-box RPC works and its parameters, the RLS policy structure and how to test it, the LocationPrivacyConfig fields and how to configure per organisation, and the MapProviderIntegration abstraction layer usage guide including how to swap providers. Place documentation in the project wiki or a docs/ folder.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 7 - 84 tasks
Can start after Tier 6 completes
Implementation Notes
Structure the document with these sections: Prerequisites, Local Setup, Database Schema & Migrations, Bounding-Box RPC Reference, RLS Policy Reference & Testing, LocationPrivacyConfig Reference, MapProviderIntegration Usage Guide, Swapping Map Providers, Troubleshooting. Use fenced code blocks for all SQL and Dart examples. For the RLS testing section, provide exact psql commands using set role and set request.jwt.claims. Keep the document under 600 lines — link to source files for full implementation detail rather than duplicating code.
Ensure GDPR notes are included in the LocationPrivacyConfig section (location data = personal data under Norwegian GDPR implementation, precision reduction to municipality level is a privacy requirement).
Testing Requirements
Documentation review only — no automated tests. Peer review checklist: (1) a developer unfamiliar with the spatial system can follow the local setup guide and successfully run the PostGIS migration; (2) all code snippets are syntactically valid Dart/SQL; (3) RLS test instructions produce the expected access-denied result when tested; (4) all LocationPrivacyConfig fields match the implemented class. Optionally, add a CI step that validates code snippets using dart analyze on extracted Dart blocks.
Supabase's hosted PostGIS extension behaviour may differ from the local emulator for spatial RPC functions, causing bounding-box queries to return incorrect results or fail in production while passing locally.
Mitigation & Contingency
Mitigation: Write integration tests against the Supabase emulator from the start and run the same test suite against a staging Supabase project before merging. Use ST_DWithin and ST_MakeEnvelope in plain SQL first, validate with psql, then wrap as RPC.
Contingency: If PostGIS RPC proves unreliable, fall back to client-side bounding box filtering on a full fetch of consented mentor locations (acceptable for up to ~200 mentors per chapter) until the spatial query is stabilised.
OpenStreetMap tile usage may require attribution handling and rate limiting. Switching to Google Maps Flutter plugin mid-implementation would require significant rework of the map-provider-integration abstraction.
Mitigation & Contingency
Mitigation: Define the map-provider-integration abstraction interface before selecting the SDK so that the concrete implementation is swappable. Implement OSM first with correct attribution. Document Google Maps as the alternate with its API key setup steps.
Contingency: If OSM tiles are rejected by stakeholders or tile server limits are hit, activate the Google Maps Flutter plugin implementation behind the same interface without touching any UI or service code.
Incorrect RLS configuration could allow a coordinator to query mentor locations from a different organisation, constituting a GDPR data breach.
Mitigation & Contingency
Mitigation: Write dedicated RLS integration tests with two isolated test organisations and assert that cross-organisation queries return zero rows. Include these tests in CI. Have a second developer review all RLS policy SQL before migration is applied.
Contingency: If a cross-organisation data leak is discovered post-deployment, immediately disable the map feature via the organisation feature flag, revoke the affected Supabase RLS policy, and notify the data protection officer per the organisation's GDPR incident response procedure.