Files
tenant-registry/migrations/0008_documents.up.sql
T
Sharang ParnerkarandClaude Opus 5.5 da6eef6d30
ci / shared (pull_request) Successful in 13s
ci / test (pull_request) Successful in 23m11s
ci / image (pull_request) Skipped
feat(documents): tenant documents in object storage
Staff upload a file for a tenant as a draft (streamed to an S3 bucket,
hashed on the way, never buffered whole), publish it, or delete it;
the tenant lists its published documents and gets a five-minute
presigned download link. Uploads, publications and downloads are
audited, a download under the person the portal names.

Migration 0008 adds the documents table; internal/storage wraps
minio-go (Hetzner Object Storage, the bucket is created in its
region when missing). Without DOCUMENTS_S3_* the routes answer 503
and the rest of the registry is unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
2026-09-23 19:35:05 +02:00

24 lines
1.2 KiB
SQL

-- F2 (go-live 2026-09): documents BreakPilot hands to a tenant (conformity
-- documents, reports) until breakpilot-compliance delivers them itself. Staff
-- upload a draft, publish it, and only then does the tenant see it. The file
-- lives in object storage under object_key; this row is its index.
CREATE TABLE documents (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
title TEXT NOT NULL CHECK (char_length(title) BETWEEN 1 AND 200),
description TEXT NOT NULL DEFAULT '' CHECK (char_length(description) <= 2000),
filename TEXT NOT NULL,
content_type TEXT NOT NULL,
size_bytes BIGINT NOT NULL CHECK (size_bytes >= 0),
sha256 TEXT NOT NULL,
object_key TEXT NOT NULL UNIQUE,
status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'published')),
uploaded_by TEXT NOT NULL DEFAULT '',
published_by TEXT,
published_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX documents_tenant_created ON documents (tenant_id, created_at DESC);