core PK: id 8 required 1 unique

Description

Stores the geographic position and location metadata for peer mentors, used for map visualization and assignment matching by geography.

13
Attributes
5
Indexes
5
Validation Rules
12
CRUD Operations

Data Structure

Name Type Description Constraints
id uuid Primary key
PKrequiredunique
user_id uuid Foreign key referencing the peer mentor user this location belongs to
required
latitude decimal WGS84 latitude coordinate of the peer mentor's location
required
longitude decimal WGS84 longitude coordinate of the peer mentor's location
required
accuracy_meters decimal Estimated accuracy radius of the location in meters
-
location_type enum Whether this is the peer mentor's home address, a service area centroid, or a last-known position
required
municipality string Norwegian municipality name (kommune) for administrative filtering and Bufdir reporting
-
county string Norwegian county (fylke) for regional filtering and assignment matching
-
postal_code string Norwegian postal code (postnummer)
-
is_visible_on_map boolean Whether the peer mentor consents to being shown on the coordinator map view
required
service_radius_km decimal The maximum distance in kilometers the peer mentor is willing to travel for assignments
-
updated_at datetime Timestamp of last location update
required
created_at datetime Timestamp when the location record was first created
required

Database Indexes

idx_geographic_locations_user_id
btree

Columns: user_id

idx_geographic_locations_lat_lng
btree

Columns: latitude, longitude

idx_geographic_locations_county
btree

Columns: county

idx_geographic_locations_municipality
btree

Columns: municipality

idx_geographic_locations_visible
btree

Columns: is_visible_on_map

Validation Rules

valid_wgs84_coordinates error

Validation failed

valid_location_type error

Validation failed

service_radius_non_negative error

Validation failed

postal_code_format warning

Validation failed

user_must_exist error

Validation failed

Business Rules

one_location_per_user_per_type
on_create

A user may have at most one record per location_type. Upsert logic replaces the existing record when the same type is submitted again.

map_visibility_requires_consent
always

is_visible_on_map must default to true but the peer mentor may opt out at any time via profile settings. Coordinators must never see a peer mentor on the map if is_visible_on_map is false.

location_data_org_scoped
always

Coordinators may only query geographic_locations for users belonging to their own organization. Cross-org location data is not accessible.

assignment_matching_uses_service_radius
always

When matching peer mentors to assignments by geography, only peer mentors whose service_radius_km encompasses the assignment location are eligible candidates.

inactive_peer_mentors_hidden
always

Peer mentors with an active pause status (peer_mentor_statuses.is_paused = true) must not appear on the map regardless of is_visible_on_map.

Storage Configuration

Storage Type
primary_table
Location
main_db
Partitioning
No Partitioning
Retention
Permanent Storage