configuration PK: id 9 required 1 unique

Description

Defines a Bufdir reporting period (start and end date) for an organization, typically aligned to grant cycles. Organizations may configure preset periods (quarterly, annual) and custom ranges. Report periods scope activity aggregation queries and ensure all generated Bufdir export files reference the correct grant cycle for regulatory compliance.

16
Attributes
5
Indexes
8
Validation Rules
16
CRUD Operations

Data Structure

Name Type Description Constraints
id uuid Immutable primary key generated on creation (UUID v4).
PKrequiredunique
organization_id uuid Foreign key referencing the organization that owns this reporting period. All data access is scoped through this key via Supabase RLS.
required
name string Human-readable display name for this reporting period (e.g., 'Q1 2025', 'Annual 2024', 'Custom Jan–Mar 2025'). Shown in period pickers and report history.
required
start_date datetime Inclusive start boundary of the reporting period, stored as UTC timestamp (time portion 00:00:00). Used in all activity aggregation range queries.
required
end_date datetime Inclusive end boundary of the reporting period, stored as UTC timestamp (time portion 23:59:59). Must be strictly after start_date.
required
is_preset boolean True when this period was created from a preconfigured organization preset (quarterly, annual). False for custom date ranges entered by the user. Presets are managed via period-preset-service.
required
preset_type enum Identifies which preset template this period was created from. NULL when is_preset is false. Used to group and label periods in the UI.
-
submitted_at datetime UTC timestamp of when a Bufdir export was successfully submitted for this period. NULL means the period has not yet been submitted. Populated by bufdir-export-audit-service on export completion.
-
submitted_by uuid User ID of the coordinator or org admin who triggered the final Bufdir submission for this period. NULL if not yet submitted.
-
is_active boolean Marks whether this is the currently active reporting period for the organization. Only one period per organization should be active at a time. The active period is pre-selected in the period picker.
required
grant_cycle_reference string Optional free-text reference linking this period to a specific Bufdir grant cycle identifier (e.g., 'Bufdir 2025 tilskudd'). Supports external traceability and audit.
-
activity_count_snapshot integer Cached count of activity records within this period at last aggregation run. Used by record-count-banner to avoid redundant queries. NULL means no snapshot has been computed yet.
-
snapshot_computed_at datetime UTC timestamp of when activity_count_snapshot was last computed. Used by period-record-count-service to determine snapshot staleness.
-
created_at datetime UTC timestamp of record creation. Set automatically on insert.
required
updated_at datetime UTC timestamp of last record modification. Maintained by a trigger on UPDATE.
required
created_by uuid User ID of the admin or coordinator who created this period record. Supports audit trail.
-

Database Indexes

idx_report_period_org_id
btree

Columns: organization_id

idx_report_period_org_dates
btree

Columns: organization_id, start_date, end_date

idx_report_period_org_active
btree

Columns: organization_id, is_active

idx_report_period_submitted_at
btree

Columns: organization_id, submitted_at

idx_report_period_preset_type
btree

Columns: organization_id, preset_type

Validation Rules

start_before_end error

Validation failed

minimum_range_duration error

Validation failed

name_not_blank error

Validation failed

organization_id_exists error

Validation failed

future_period_warning warning

Validation failed

no_overlap_with_previously_submitted error

Validation failed

grant_cycle_reference_length error

Validation failed

snapshot_non_negative error

Validation failed

Business Rules

no_overlap_per_organization
on_create

A new report period for an organization must not overlap date ranges with any existing period for the same organization. Prevents double-counting of activities in Bufdir exports across grant cycles.

submitted_period_immutable
on_update

Once submitted_at is set (non-NULL), the start_date, end_date, and organization_id fields become read-only. This preserves the integrity of submitted Bufdir reports for regulatory audit.

no_delete_with_generated_reports
on_delete

A report period that has associated generated_report or bufdir_export_audit_log records must not be deleted. This enforces referential integrity for grant funding accountability.

single_active_period_per_org
on_create

At most one report period per organization may have is_active = true at any time. When a new active period is set, the previous active period must be deactivated atomically.

preset_type_required_when_is_preset
on_create

When is_preset is true, preset_type must be one of the defined enum values. When is_preset is false, preset_type should be NULL or 'custom'.

org_scoped_access_only
always

All reads and writes to report_period records are restricted to the organization_id matching the authenticated user's session context via Supabase RLS. Cross-organization access is prohibited.

end_date_not_far_future_warning
on_create

If end_date is more than 13 months in the future from created_at, a warning is raised to prompt the admin to confirm they have entered the correct date. Does not block creation.

Storage Configuration

Storage Type
primary_table
Location
main_db
Partitioning
No Partitioning
Retention
Permanent Storage

Entity Relationships

bufdir_export_audit_log
incoming references

A Bufdir export audit record references the target reporting period for traceability of which grant cycle was submitted

required
generated_report
incoming many_to_one

Each Bufdir export file references the reporting period it covers, ensuring traceability between reports and grant cycles

required
organization
incoming one_to_many

An organization defines its own Bufdir reporting periods aligned to its grant cycle calendar

optional