configuration PK: id 11 required 1 unique

Description

Represents the parent-child relationships between organizations in a multi-tenant hierarchy, enabling NHF-style structures with national, regional, and local levels. Each record captures one edge in the hierarchy tree.

12
Attributes
5
Indexes
5
Validation Rules
16
CRUD Operations

Data Structure

Name Type Description Constraints
id uuid Primary key
PKrequiredunique
parent_organization_id uuid FK to organizations.id — the ancestor organization in this hierarchy edge
required
child_organization_id uuid FK to organizations.id — the subordinate organization in this hierarchy edge
required
hierarchy_level enum Semantic level of the child in the org tree (e.g. national, regional, local)
required
depth integer Numeric depth from root (0 = top-level/national). Used for efficient subtree queries without recursive CTE on every request.
required
path text Materialized path string (e.g. 'nhf/nhf-oslo/nhf-oslo-vest') for efficient ancestor/descendant lookups without recursion
required
is_active boolean Whether this hierarchy link is currently active. Inactive links are hidden from navigation but preserved for audit.
required
activity_distribution_enabled boolean Whether activities logged by child org members can roll up into parent org reports. Supports NHF requirement for activity distribution between org levels.
required
max_child_memberships integer Maximum number of local associations a user can belong to under this parent (NHF: up to 5). NULL means unlimited.
-
created_by uuid FK to users.id — Global Admin or Org Admin who created this hierarchy link
required
created_at datetime Timestamp of record creation
required
updated_at datetime Timestamp of last update
required

Database Indexes

idx_org_hierarchies_parent
btree

Columns: parent_organization_id

idx_org_hierarchies_child
btree

Columns: child_organization_id

idx_org_hierarchies_unique_edge
btree unique

Columns: parent_organization_id, child_organization_id

idx_org_hierarchies_path
btree

Columns: path

idx_org_hierarchies_depth
btree

Columns: depth

Validation Rules

child_differs_from_parent error

Validation failed

unique_parent_child_pair error

Validation failed

valid_hierarchy_level error

Validation failed

depth_consistent_with_parent error

Validation failed

both_orgs_must_exist error

Validation failed

Business Rules

no_circular_hierarchy
on_create

A child organization cannot also be an ancestor of its parent in the same hierarchy tree. Circular references must be rejected.

Enforced by: OrgHierarchyService
max_membership_cap
always

When max_child_memberships is set on a hierarchy node, users may not be members of more child organizations under this parent than the cap allows. NHF cap is 5.

activity_rollup_requires_flag
always

Activity data from child organizations only rolls up into parent org reports when activity_distribution_enabled is true on the hierarchy edge.

global_admin_only_create_top_level
on_create

Only Global Admins may create or modify hierarchy edges at depth 0 (national level). Org Admins may only manage hierarchy below their own organization.

Enforced by: OrgHierarchyService
deactivate_cascades_to_reports
on_update

When a hierarchy edge is set inactive, parent org reports no longer include child data, and Bufdir exports exclude the child org's activities.

path_auto_maintained
on_create

The materialized path field is automatically computed and updated whenever a hierarchy edge is created or its parent changes. Application layer must never accept a client-supplied path value.

Enforced by: OrgHierarchyService

Storage Configuration

Storage Type
primary_table
Location
main_db
Partitioning
No Partitioning
Retention
Permanent Storage