Files
tenant-registry/migrations/0010_projects.up.sql
T
Sharang ParnerkarandClaude Opus 5.5 e25320297a
ci / shared (pull_request) Successful in 13s
ci / test (pull_request) Successful in 24m19s
ci / image (pull_request) Skipped
feat(projects): Projekte for documents and product objects
A tenant groups its documents and product objects by one of its own
products (kind product) or a topic such as the CRA (kind topic). Purely
organisational.

- migration 0010: projects (unique name per tenant, ignoring case),
  document_projects, documents.own_document
- GET/POST /v1/tenants/{id}/projects, PATCH/DELETE .../{pid}: the portal
  writes for staff and tenant admins; products read with tenants.read
- GET /v1/tenants/{id}/projects/{pid}/targets: the project's Prüfwerk
  objects from Prüfwerk's platform API (service token), with dashboard links;
  empty and available=false when Prüfwerk cannot answer
- documents: upload with project_ids and own_document, PATCH
  /v1/admin/documents/{doc} to reassign; own documents are published
  without a notification mail
- audit: project.created/updated/deleted, document.updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
2026-09-29 14:24:12 +02:00

30 lines
1.6 KiB
SQL

-- Projekte (v0.1.1): a tenant groups its documents and product objects (for
-- example Prüfwerk targets) by what they are about, either one of the
-- customer's own products or machines (kind 'product') or a topic such as
-- the CRA or the Data Act (kind 'topic'). Purely organisational: nothing that
-- gets checked depends on it. Staff and tenant admins create them.
-- (tenant_projects from 0001 is an unused placeholder and stays untouched.)
CREATE TABLE projects (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
name TEXT NOT NULL CHECK (char_length(name) BETWEEN 1 AND 120),
kind TEXT NOT NULL CHECK (kind IN ('product', 'topic')),
description TEXT NOT NULL DEFAULT '' CHECK (char_length(description) <= 1000),
created_by TEXT NOT NULL DEFAULT '',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE UNIQUE INDEX projects_tenant_name ON projects (tenant_id, lower(name));
-- A document belongs to any number of the tenant's projects.
CREATE TABLE document_projects (
document_id UUID NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
PRIMARY KEY (document_id, project_id)
);
CREATE INDEX document_projects_project ON document_projects (project_id);
-- The tenant's own documents, kept here for them: shown like any other,
-- but publishing one sends no notification mail.
ALTER TABLE documents ADD COLUMN own_document BOOLEAN NOT NULL DEFAULT false;