core PK: id 15 required 1 unique

Description

A logged interaction between a peer mentor and a contact or group, such as a home visit, phone call, meeting, or group event. The central operational record of the Meander platform, feeding personal statistics, coordinator oversight, Bufdir reporting, and expense reimbursement.

25
Attributes
10
Indexes
6
Validation Rules
48
CRUD Operations

Data Structure

Name Type Description Constraints
id uuid Primary key
PKrequiredunique
organization_id uuid Tenant isolation — which organization this activity belongs to
required
user_id uuid The peer mentor who performed the activity (owner). For proxy registrations this is the peer mentor being reported for, not the coordinator.
required
registered_by_user_id uuid The user who actually created the record. Equals user_id for self-registration; differs for proxy/bulk registration by a coordinator.
required
activity_date datetime Date and time the activity took place (not the registration time). Defaults to current date on the device.
required
duration_minutes integer Duration of the activity in minutes. Defaults to 30.
required
activity_type enum Categorizes the kind of activity for Bufdir reporting and statistics.
required
summary text Free-text summary written by the peer mentor. Supports speech-to-text input. Optional for quick-log, required for wizard-registered activities.
-
contact_id uuid The primary contact this activity relates to. Nullable for group activities with no single contact.
-
is_group_activity boolean True when the activity involves multiple participants rather than a single contact.
required
participant_count integer Number of participants for group activities. Null for single-contact activities.
-
is_proxy_registration boolean True when a coordinator registered this activity on behalf of the peer mentor.
required
is_bulk_registration boolean True when this record was created as part of a bulk registration operation.
required
status enum Approval/review status of the activity record.
required
reviewed_by_user_id uuid Coordinator or admin who approved/flagged/rejected the activity.
-
reviewed_at datetime Timestamp of the review action.
-
rejection_reason text Reason provided when status is rejected or flagged.
-
duplicate_of_activity_id uuid References the canonical activity if this record was identified as a duplicate.
-
calendar_event_uid string External calendar UID when the activity was imported via calendar sync.
-
has_home_visit_report boolean Denormalized flag — true when a home_visit_reports record exists for this activity.
required
bufdir_eligible boolean Whether this activity should be counted in Bufdir reports. False for test organizations or activities explicitly excluded by the org admin.
required
local_id string Offline-created temporary ID used by the mobile client before server sync. Stored to support idempotent upsert on sync.
-
created_at datetime Server-side creation timestamp.
required
updated_at datetime Server-side last-update timestamp.
required
deleted_at datetime Soft-delete timestamp. Null means active.
-

Database Indexes

idx_activities_user_id
btree

Columns: user_id

idx_activities_organization_id
btree

Columns: organization_id

idx_activities_activity_date
btree

Columns: activity_date

idx_activities_user_date
btree

Columns: user_id, activity_date

idx_activities_org_date
btree

Columns: organization_id, activity_date

idx_activities_status
btree

Columns: status

idx_activities_contact_id
btree

Columns: contact_id

idx_activities_registered_by
btree

Columns: registered_by_user_id

idx_activities_local_id
btree

Columns: local_id

idx_activities_deleted_at
btree

Columns: deleted_at

Validation Rules

duration_positive_integer error

Validation failed

group_activity_requires_participant_count error

Validation failed

summary_required_for_wizard_registration error

Validation failed

review_fields_consistent error

Validation failed

activity_type_valid_enum error

Validation failed

local_id_unique_per_org error

Validation failed

Business Rules

proxy_registration_requires_coordinator_role
on_create

Only users with the Coordinator role may set is_proxy_registration=true or registered_by_user_id different from user_id.

activity_date_not_in_future
on_create

An activity cannot be logged for a future date — it must record something that already happened.

test_org_excluded_from_bufdir
on_create

Activities belonging to the Norse Test Organization must have bufdir_eligible=false and must not appear in Bufdir report exports.

duplicate_detection_on_submit
on_create

When a new activity is submitted, the system checks for existing records by the same or different user with matching organization_id, activity_date (±1 day), and contact_id. Suspected duplicates trigger a warning banner; hard duplicates block submission.

soft_delete_only
on_delete

Activities are never hard-deleted. Deletion sets deleted_at. All queries filter deleted_at IS NULL by default.

tenant_isolation
always

Every query involving activities must include an organization_id filter matching the authenticated user's organization. Cross-tenant reads are forbidden.

offline_idempotent_sync
on_create

When syncing an offline-created activity, the server must check local_id to prevent duplicate inserts. If local_id already exists for the organization, return the existing record rather than creating a new one.

approved_activity_immutable
on_update

Once status=approved, the activity record may not be edited by the peer mentor. Only a coordinator or admin can change status back to under_review to unlock edits.

Storage Configuration

Storage Type
primary_table
Location
main_db
Partitioning
by_date
Retention
Permanent Storage