core PK: id 9 required 2 unique

Description

Extended profile entity for users who serve as peer mentors, capturing operational attributes including current status, area, assignment count, and certification summary. Peer mentors are the primary service-delivery resource and their data drives all coordinator management workflows.

15
Attributes
7
Indexes
8
Validation Rules
48
CRUD Operations

Data Structure

Name Type Description Constraints
id uuid Unique identifier for the peer mentor profile record
PKrequiredunique
user_id uuid Foreign key to users table. One-to-one relationship: each peer mentor has exactly one user account. UNIQUE constraint enforced at database level.
requiredunique
organization_id uuid Foreign key to the primary organization this peer mentor belongs to. Determines RLS scope, Bufdir reporting attribution, and coordinator assignment.
required
local_association_id uuid Foreign key to the local association (lokallag) within the org hierarchy. Used for activity attribution and coordinator scoping in NHF's 1400-lokallag structure.
-
status enum Current operational availability status. Drives assignment pool inclusion, map visibility, and coordinator notifications. 'paused' is set mentor-initiated or auto-triggered on certificate expiry (HLF policy). 'inactive' is a terminal state requiring coordinator reactivation.
required
area string Human-readable label for the geographic or service area where this peer mentor primarily operates. Used in contact list display, coordinator search/filter, and map view labelling. Organization-specific terminology applies via the Labels system (e.g., 'fylke', 'region', 'distrikt').
-
assignment_count integer Denormalized running total of assignments completed by this peer mentor. Maintained exclusively by a database trigger on the assignments table (increment on insert, decrement on cancellation/delete). Never written directly by application code. Used by Blindeforbundet's honorarium threshold logic: 3rd assignment triggers base honorarium, 15th triggers elevated rate.
required
honorarium_rate decimal Current applicable honorarium rate in NOK per assignment, determined by assignment_count threshold tier. Blindeforbundet-specific: rate changes at threshold crossings (0→3 and 3→15 assignments). Recalculated by Honorarium Calculation Service on threshold events. Null before first threshold is crossed.
-
is_driver boolean Whether this peer mentor has registered as a volunteer driver. When true, triggers NDA signing requirements and unlocks driver honorarium eligibility at Blindeforbundet.
required
location_consent_granted boolean GDPR opt-in flag for home area centroid storage in peer_mentor_locations. Must be explicitly set to true via Privacy Consent Service before any location data is stored. Required for Blindeforbundet geographic matching feature.
required
certification_summary json Cached JSON snapshot of active certifications for fast list rendering without join queries. Schema: {has_valid_cert: boolean, expiring_soon: boolean, expired_count: integer, next_expiry_date: string|null}. Invalidated and refreshed by Certificate Service on any certification lifecycle event.
-
profile_notes text Coordinator-visible operational notes about this peer mentor. Not surfaced to the mentor themselves. RLS restricts read/write to coordinator and admin roles only.
-
last_activity_date datetime Timestamp of the most recently registered activity. Denormalized for fast inactivity detection in coordinator dashboards without aggregating the activities table. Updated on successful activity submission.
-
created_at datetime Timestamp when the peer mentor profile was first created. Set automatically on insert by Supabase default.
required
updated_at datetime Timestamp of the most recent write to any field in this row. Maintained by a database trigger (moddatetime extension) to support cache invalidation and audit trail.
required

Database Indexes

idx_peer_mentors_user_id
btree unique

Columns: user_id

idx_peer_mentors_organization_id
btree

Columns: organization_id

idx_peer_mentors_org_status
btree

Columns: organization_id, status

idx_peer_mentors_local_association_id
btree

Columns: local_association_id

idx_peer_mentors_status
btree

Columns: status

idx_peer_mentors_assignment_count
btree

Columns: assignment_count

idx_peer_mentors_last_activity_date
btree

Columns: last_activity_date

Validation Rules

user_id_references_valid_user error

Validation failed

organization_id_references_valid_organization error

Validation failed

assignment_count_non_negative error

Validation failed

honorarium_rate_non_negative error

Validation failed

status_transition_validity error

Validation failed

area_max_length error

Validation failed

certification_summary_json_schema warning

Validation failed

unique_user_peer_mentor_mapping error

Validation failed

Business Rules

one_peer_mentor_profile_per_user
on_create

Each user account can have at most one peer mentor profile. Enforced by UNIQUE constraint on user_id at the database level. Attempts to create a second profile for the same user are rejected.

auto_pause_on_certificate_expiry
on_update

For HLF, when all active certifications expire, status is automatically set to 'paused' and the mentor is removed from active assignment pools. Certificate Expiry Scheduler runs daily checks; Certificate Service handles real-time expiry events. The mentor also disappears from HLF's public-facing local association listings.

honorarium_threshold_triggers_rate_update
on_update

For Blindeforbundet, when assignment_count crosses the 3rd or 15th threshold, honorarium_rate is recalculated by Honorarium Calculation Service and coordinator is notified via Threshold Notification Trigger. Application code must not manually increment assignment_count.

paused_or_inactive_excluded_from_pools
always

Mentors with status != 'active' must be excluded from assignment target lists, geographic matching results, bulk registration selection, and active mentor card lists. All consumer queries must filter status = 'active' explicitly.

coordinator_notification_on_status_change
on_update

When status transitions to 'paused' or 'inactive', the coordinator assigned to that mentor receives a push notification containing the mentor's name and optional pause reason. Ensures coordinators maintain real-time awareness of their active pool size.

driver_requires_valid_nda
always

A mentor with is_driver = true must have a signed, non-expired NDA on file before receiving driver honorariums or transport assignments at Blindeforbundet. NDA Validation Service gates all driver-specific operations.

location_data_requires_consent
always

A peer_mentor_locations record may only be created or updated for a mentor where location_consent_granted = true. Privacy Consent Service must record explicit opt-in before Location Repository stores any centroid data. Revoking consent must delete existing location records.

assignment_count_owned_by_trigger
on_update

The assignment_count field is a denormalized value managed exclusively by the database-level assignment-count-trigger. No application service or repository may write directly to this field. This is the single source of truth for threshold and dashboard calculations.

Storage Configuration

Storage Type
primary_table
Location
main_db
Partitioning
No Partitioning
Retention
Permanent Storage

Entity Relationships

assignments
incoming many_to_one

Each assignment targets a specific peer mentor as the encrypted payload recipient

required
mentor_pairings
incoming many_to_one

Each pairing references the experienced peer mentor acting as the guide in the mentorship scheme

required
mentor_pairings
incoming many_to_one

Each pairing references the newer peer mentor receiving guidance as the mentee

required
certifications
outgoing one_to_many

A peer mentor may hold multiple certifications for different courses, with HLF policy gating availability on active certificates

optional
organizations
outgoing many_to_one

Each peer mentor profile is associated with a primary organization for scoping and reporting

required
peer_mentor_availability
outgoing one_to_many

A peer mentor has a history of availability status changes tracked for audit and coordinator alerts

optional cascade delete
peer_mentor_locations
outgoing one_to_many

A peer mentor may have location records with GDPR consent flags for geographic matching at Blindeforbundet

optional cascade delete
users
incoming one_to_one

Each peer mentor has exactly one extended peer mentor profile linked to their user account

optional cascade delete

Components Managing This Entity

data Event Repository ["mobile","backend"] ui Event Participants Widget ["mobile"] service Activity Delegation Service ["mobile","backend"] service Bulk Registration Service ["mobile","backend"] ui Peer Mentor Selection Widget ["mobile"] data Contact Repository ["mobile"] service Contact Search Service ["mobile"] ui Contact Card Widget ["mobile"] ui Contacts List Screen ["mobile"] data Peer Mentor Repository ["mobile","backend"] service Peer Mentor Profile Service ["mobile"] ui Peer Mentor Card Widget ["mobile"] ui Peer Mentor Detail Screen ["mobile"] data Availability Repository ["backend","mobile"] infrastructure Certificate Expiry Scheduler ["backend"] service Coordinator Notification Service ["backend"] service Pause Management Service ["backend","mobile"] data Task Assignment Repository ["mobile","backend"] ui Task Assignment Screen ["mobile"] data Location Repository ["backend"] service Geographic Matching Service ["mobile","backend"] service Privacy Consent Service ["mobile","backend"] ui Location Pin Widget ["mobile"] ui Map View Screen ["mobile"] ui Mentor Map Bottom Sheet ["mobile"] infrastructure Document Signing Infrastructure ["backend"] service Honorarium Service ["backend","mobile"] service NDA Validation Service ["backend","mobile"] data Coordinator Stats Repository ["backend"] service Coordinator Report Service ["backend"] data Assignment Count Repository ["backend"] infrastructure Assignment Count Database Trigger ["backend"] service Honorarium Calculation Service ["backend"] service Threshold Notification Trigger ["backend"] service Certificate Service ["backend"] data Mentor Program Repository ["backend","mobile"] service Mentor Program Service ["backend","mobile"] ui Mentor Match Widget ["mobile","frontend"] data Admin Repository ["backend"] service Admin Management Service ["backend"] data Member Overview Repository ["mobile"] service Coordinator Overview Service ["mobile"] ui Active Peer Mentor List Widget ["mobile"] data Database Schema ["backend"]