pediatric-ai-scribe-v3/migrations/1780300000000_user-resources.js
Daniel a0d81789ff
Some checks failed
Forgejo Android APK / Root app tests (push) Successful in 49s
Forgejo Docker Build / Root app tests (push) Successful in 47s
Forgejo Android APK / Build signed APK (push) Successful in 2m2s
Forgejo Docker Build / Build Docker image (push) Successful in 9s
Forgejo Docker Build / Deploy to the host (push) Failing after 2s
feat: My Resources — anyone can generate teaching material, privately
Learning is moderator-owned: content published into categories that everyone
sees, behind router.use(moderatorMiddleware). That is right for institutional
material and wrong as the only way in — an ordinary user could not generate
anything at all.

So this is a separate pathway rather than a loosening of that one. Learning is
untouched; the moderator gate stays exactly where it was. A signed-in user can
generate a deck or an article for their own use, keep it, refine it and export
it, and nobody else ever sees it.

Private by construction. Every statement filters on the owner and there is no
route that returns another person's work, which a test asserts statement by
statement rather than trusting. The foreign key cascades, so deleting an account
takes its drafts with it. There is no category, no publish state and no sharing:
adding sharing later should be a deliberate feature, not something that leaks
out of a forgotten WHERE clause.

Markdown is the artifact. Every format is rendered from it on demand — pptx and
docx by pandoc, both carrying the house reference deck, and PDF by Gotenberg,
whose LibreOffice preserves a deck's layout in a way rendering from markdown
would not. That is what makes "add a slide on when to admit" a text edit rather
than a binary patch.

Gotenberg was published on the host but on a network of its own, so reaching it
from a container went out and back through the host gateway. It now joins
danvics_convert, owned by danvics-net like the others. PDF is the one export
allowed to fail: if that service is down, the deck and the document still
download and the error says which.

Verified end to end as a plain user: the moderator route still refuses with 403,
generation returned a deck grounded on 12 corpus excerpts, the library lists
only their own, pptx/docx/pdf all downloaded valid, "add a slide on when to
admit" put the slide in the right place and left References last, and an
unauthenticated request gets 401 while someone else's id gets 404.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dv6sqaY6Vq3ChZHMem3cnU
2026-09-11 14:50:54 +02:00

39 lines
1.7 KiB
JavaScript

// Resources a user generated for themselves.
//
// Learning content is moderator-owned and published into categories for
// everyone. This is the other thing people wanted: somewhere to generate a deck
// for tomorrow's teaching session without it becoming institutional content,
// and without needing to be a moderator to do it at all.
//
// Private by construction. Every query filters on user_id, and the foreign key
// cascades, so deleting an account takes its drafts with it. There is no
// category, no publish state and no sharing: this table is one person's
// workspace, and adding sharing later should be a deliberate decision rather
// than something that leaks out of a missing WHERE clause.
exports.up = pgm => {
pgm.sql(`
CREATE TABLE IF NOT EXISTS user_resources (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
title TEXT NOT NULL DEFAULT 'Untitled',
-- presentation | article. Decides which prompt writes it and which
-- formats it exports to.
kind TEXT NOT NULL DEFAULT 'presentation',
-- Markdown is the artifact. Every export is rendered from it on demand,
-- so refining means editing text rather than patching a binary.
markdown TEXT NOT NULL DEFAULT '',
topic TEXT NOT NULL DEFAULT '',
-- How many corpus excerpts it was written from; 0 means the model alone.
grounded_count INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_user_resources_owner
ON user_resources(user_id, created_at DESC);
`);
};
exports.down = pgm => {
pgm.sql('DROP TABLE IF EXISTS user_resources;');
};