Files
tenant-registry/migrations/0010_projects.up.sql
sharangandClaude Opus 5.5 f3450f84c7
ci / shared (push) Successful in 13s
ci / test (push) Successful in 23m41s
ci / image (push) Successful in 35s
feat(projects): Projekte for documents and product objects (#46)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
2026-09-29 12:49:36 +00: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;