Repository navigation
feat: storage for partner-lab imports on both backends (2.1.0) - #11
Merged
Merged
Conversation
Five new repositories, on PostgreSQL and MongoDB, for the api's report-reader imports: - externalReports (external_reports): one row per partner PDF, sourceSha256 unique per organisation, the ExtractedReport JSON as is, status, warnings - externalReportFiles (external_report_files): the PDF bytes, apart so lists never load them - externalSignatories (external_signatories): the partner signature registry; listForOrg is cached per organisation through the cache layer and cleared on every write - externalSignatures (external_signatures): the PNG per (organisation, PDF, signature) - reportProvenance (report_provenance): one per report, where its results came from Bytes go in as Uint8Array and come out as Buffer on both drivers. New tables and collections only; sync() creates them. Contract tests on both backends; TEST_BACKENDS=pg runs PostgreSQL only. docs/EXTERNAL-REPORTS.md describes the storage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018jBohmYiwjQLWmN2duiZcA
BackStacked
added a commit
that referenced
this pull request
Nov 9, 2026
## What and why In 2.1.0, `external_report_files.id` was a foreign key to `external_reports`. The api stores the partner PDF **first** and creates the external report with the file's id only after extraction. Extraction runs inline, or in a worker job whose payload carries just the file id. On PostgreSQL, every import therefore fails with `external_report_files_id_fkey`. This shows up on api#23's CI. Two separate pushes made 2.1.0 miss the fix: the fix (b30ee5e) landed on the branch after #11 had already merged. - `src/pg/models.ts`: `id` is now a plain UUID primary key with no foreign key. Mongo never had one. - `src/core/types.ts` and `docs/EXTERNAL-REPORTS.md`: document that the file is stored before its report. - `scripts/test.ts`: a new contract check stores a PDF before its report exists, on both backends. This check would have caught the bug. - Version 2.1.1. `TEST_BACKENDS=pg npm test`: 100 passed, 0 failed. Mongo is not run locally; CI runs it. A database that already ran `sync()` on 2.1.0 keeps the constraint, so drop it by hand: `ALTER TABLE external_report_files DROP CONSTRAINT external_report_files_id_fkey;`. None should exist yet, because the api has not been deployed with 2.1.0. Release: after merge, tag `v2.1.1`. --- _Generated by [Claude Code](https://claude.ai/code/session_018jBohmYiwjQLWmN2duiZcA)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Himanshu · project thread
What and why
The api is getting partner-lab PDF imports (
@mgpl-diagnostics/report-reader). This PR adds their storage, on PostgreSQL and MongoDB, behind the same repository interface:externalReportsexternal_reportssourceSha256is unique per org.extractedholds theExtractedReportunchanged, plusstatusandwarningsexternalReportFilesexternal_report_filesexternalSignatoriesexternal_signatorieslistForOrg(orgId, lab?)is cached per org (Redis cache layer) and cleared on create, update and deleteexternalSignaturesexternal_signaturessourceSha256,sha), uniquereportProvenancereport_provenancereportId): performed by, medical signatories, NABL text, the partner's test name, and the results as importedDifferences from the brief:
external_reports, every list query would load the PDFs.reports.sync()creates new tables but never alters existing ones, so nothing needs a migration script. The new tables are created byrepos.sync()/npm run db:sync.Bytes go in as
Uint8Arrayand come out asBufferon both drivers. Sequelize had been stringifying a bareUint8Array, and Mongo's lean reads had been returning BSONBinary.Details are in
docs/EXTERNAL-REPORTS.md. AGENTS.md has a new rule 11 (this data is private).Type
Checklist
npm run typecheckpassesTEST_BACKENDS=pg npm test: 99 passed, 0 failed). This session can't download MongoDB binaries (403), so CI's MongoDB run is the first real check of the Mongo side.TEST_BACKENDSis new and defaults to both.Release: after merge, tag
v2.1.0on the merge commit so the api can depend on^2.1.0.Generated by Claude Code