Files
HealthLog/prisma/migrations/0356_document_source_connections/migration.sql
T
Marc-André Bombeck fdc60f69c2 feat(documents): search and import from Paperless-ngx and Papra on request
A person stores one connection per system (base address, Papra
organization id, API token encrypted at rest) and can search it by
document name with tag and date filters, then import picked documents
one per request through the same ingest path as an upload: source-key
answer before any download, content dedup, deleted stays deleted, quota,
provenance, and the person's own AI reading setting. An import can link
the document to the visit, condition or vaccination it was picked for.

The operator lists the instances in DOCUMENT_SOURCE_ORIGINS; unset, the
feature is off. Only listed origins are contacted, through safeFetch with
the origin pinned, redirects refused, timeouts and byte caps. The routes
are cookie-only and owner-only. The token is registered for rotation,
removed by Delete all data, and not carried in backups.
2026-09-26 13:02:36 +02:00

23 lines
985 B
SQL

-- Document picker (#1038). One connection per person per system (Paperless-ngx
-- or Papra) with the API token encrypted at rest. The picker searches the
-- source and imports picked documents on request only; nothing polls.
CREATE TABLE "document_source_connections" (
"id" TEXT NOT NULL,
"user_id" TEXT NOT NULL,
"system" VARCHAR(16) NOT NULL,
"base_url" VARCHAR(2048) NOT NULL,
"organization_id" VARCHAR(128),
"token_encrypted" TEXT NOT NULL,
"last_verified_at" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "document_source_connections_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX "document_source_connections_user_id_system_key"
ON "document_source_connections" ("user_id", "system");
ALTER TABLE "document_source_connections"
ADD CONSTRAINT "document_source_connections_user_id_fkey"
FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;