Files
tenant-registry/migrations/0021_company_profiles.up.sql
T
sharangandClaude Opus 5.5 174a2f1e01
ci / shared (push) Successful in 14s
ci / test (push) Successful in 25m47s
ci / image (push) Successful in 37s
feat(company-profile): Unternehmensprofil per tenant, registry as the authority (#85)
Migration 0021 (company_profiles + company_profile_revisions), GET/PUT /v1/tenants/{id}/company-profile, POST …/submit with optimistic revisions (409 + current revision; unchanged saves are no new revision), staff import via /v1/admin/tenants/{id}/company-profile (named staff member only), outline validation of the form document, audit without answers, OpenAPI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 10:30:09 +00:00

32 lines
1.7 KiB
SQL

-- Unternehmensprofil (portal onboarding, decided 2026-10-20): a tenant's
-- company profile and compliance scope as the portal form saves them. The
-- registry is the authority; the portal owns the form's schema, so the
-- answers are kept as the form's document (JSONB), every answer, option and
-- "Vorschlag" mark unchanged. One profile per tenant (the tenant is the
-- company); advisors' client profiles come later as separate records.
CREATE TABLE company_profiles (
tenant_id UUID PRIMARY KEY REFERENCES tenants(id) ON DELETE CASCADE,
data JSONB NOT NULL CHECK (jsonb_typeof(data) = 'object'),
schema_version TEXT NOT NULL CHECK (char_length(schema_version) BETWEEN 1 AND 40),
revision INTEGER NOT NULL CHECK (revision >= 1),
status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'submitted')),
updated_by TEXT NOT NULL DEFAULT '',
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
submitted_by TEXT NOT NULL DEFAULT '',
submitted_at TIMESTAMPTZ
);
-- Every saved state, never changed afterwards: who changed what when, and
-- whether it came from the form, a submission or a staff import.
CREATE TABLE company_profile_revisions (
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
revision INTEGER NOT NULL CHECK (revision >= 1),
data JSONB NOT NULL,
schema_version TEXT NOT NULL,
status TEXT NOT NULL CHECK (status IN ('draft', 'submitted')),
source TEXT NOT NULL CHECK (source IN ('portal', 'submit', 'import')),
changed_by TEXT NOT NULL DEFAULT '',
changed_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (tenant_id, revision)
);