Data Layer medium complexity backend
0
Dependencies
1
Dependents
1
Entities
0
Integrations

Description

Persists and retrieves per-organisation Bufdir column schema configurations in Supabase. Allows Norse Digital Products to update column mappings without a code deployment as Bufdir's template evolves.

Feature: Bufdir Reporting & Export

bufdir-schema-config-repository

Summaries

The Bufdir Column Schema Config Repository eliminates the need for a software deployment every time Bufdir updates its reporting template — a change that has historically blocked organisations from submitting on time and forced emergency engineering work. By storing column mappings in a configurable, versioned database layer managed by Norse Digital Products, the platform can respond to Bufdir template changes in minutes rather than days, keeping all client organisations compliant without service interruption. The versioning capability also provides a safety net: if a schema update introduces errors, administrators can roll back instantly. This operational resilience directly protects the grant funding of every organisation using the platform and reduces support burden for the product team.

This is a medium-complexity backend data component stored in Supabase. Development effort is primarily in the versioning mechanism — `listSchemaVersions` and `revertToVersion` add meaningful complexity beyond basic CRUD and should be scoped carefully. A key dependency question is who will have access to update schema configurations in production: if this is an admin-only operation through the back office, ensure the appropriate role-based access controls are in place before go-live. Testing must cover default schema fallback (when no org-specific config exists), version rollback correctness, and Supabase RLS policies to prevent one organisation from reading another's schema.

The main project risk is schema drift: if Bufdir updates their template and the config is not updated promptly, exports will fail. Plan for an admin notification or monitoring alert to flag schema version mismatches.

This backend data component provides persistent storage for per-organisation Bufdir column schema configurations in Supabase. The `getSchema` method should implement a fallback chain: org-specific schema → default schema, so new organisations inherit a working baseline without manual setup. `saveSchema` should auto-increment the version number and timestamp the record rather than overwriting in-place, enabling `listSchemaVersions` to return the full history and `revertToVersion` to restore a prior state by copying the versioned record as the new current. The schema itself (BufdirColumnSchema) should be stored as a JSONB column in Supabase for flexibility as Bufdir's template evolves.

Apply row-level security so each organisation's config is isolated. Consider caching the default schema in-process since it is read on every export and changes infrequently — invalidate on `saveSchema` calls against the default org. The bufdir_column_schema data model drives the table definition.

Responsibilities

  • Store and retrieve per-organisation Bufdir column schema configurations
  • Support versioning of schema configurations
  • Provide default schema when no org-specific config exists

Interfaces

getSchema(String orgId)
saveSchema(String orgId, BufdirColumnSchema schema)
getDefaultSchema()
listSchemaVersions(String orgId)
revertToVersion(String orgId, int version)

Relationships

Dependents (1)

Components that depend on this component

Related Data Entities (1)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/bufdir-schema-versions 6 endpoints
GET /api/v1/bufdir-schema-versions List schema versions for an organisation
GET /api/v1/bufdir-schema-versions/:org_id/active Get the active schema for an organisation
GET /api/v1/bufdir-schema-versions/default Get the default Bufdir column schema
POST /api/v1/bufdir-schema-versions Save a new schema version for an organisation
PUT /api/v1/bufdir-schema-versions/:version_id Update an existing schema version
DELETE /api/v1/bufdir-schema-versions/:version_id Delete a schema version