Repository navigation
feat(epcis): document receipts and live EPCIS failure metric #3576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
PetrefiedThunder
merged 15 commits into
claude/supplier-data-quality
from
claude/epcis-document-receipts
Oct 25, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
11eb280
feat(suppliers): agreed sending hours per facility and live late CTE …
PetrefiedThunder b64bf33
feat(epcis): record a receipt for every EPCIS document and live failu…
PetrefiedThunder b6908a0
test(epcis): size receipt batches from MIN_RECORDS and check partial …
PetrefiedThunder 8cc9a3b
test(security): count the agreed sending hours PUT as a dual session …
PetrefiedThunder 8eaf374
Merge claude/supplier-data-quality (main a9cb1f05) into claude/suppli…
PetrefiedThunder 39d7c2e
Merge claude/supplier-data-quality (main a9cb1f05) into claude/epcis-…
PetrefiedThunder 627cd9d
fix(copy): real-data follow-up to #3471 (v3) (#3544)
PetrefiedThunder 0b8ddf3
fix(ci): Engine Review Pass picks up real PASS markers (#3577)
PetrefiedThunder f973979
feat(copy): SEL-452 copy gate with capabilities registry and baseline…
PetrefiedThunder 16f29dc
Merge main into claude/supplier-agreed-sending-hours
PetrefiedThunder 0aafb55
chore(schema): snapshot supplier_facilities.agreed_sending_hours (v136)
PetrefiedThunder 730ba95
Merge claude/supplier-agreed-sending-hours into claude/epcis-document…
PetrefiedThunder c77c400
fix(copy): label EPCIS as Preview in supplier quality and ingest, dro…
PetrefiedThunder f9debff
Merge claude/supplier-agreed-sending-hours into claude/epcis-document…
PetrefiedThunder a9e7bb2
Merge claude/supplier-data-quality into claude/epcis-document-receipts
PetrefiedThunder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
alembic/versions/20261024_a3f7ce361b0e_v137_epcis_document_receipts.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| """EPCIS document receipts: fsma.epcis_document_receipts. | ||
|
|
||
| Mirrors supabase/migrations/20261024090000_epcis_document_receipts.sql exactly: | ||
| same table, columns, constraints, index, RLS policy and grants. One row per | ||
| EPCIS document the ingest routes receive, accepted or rejected, keyed by the | ||
| SHA-256 of the raw request body. error_summary is a short sanitized summary, | ||
| never payload content. | ||
|
|
||
| Additive and idempotent (IF NOT EXISTS, drop-if-exists-then-create policy, | ||
| role-guarded grants), so the plain SQL file can run ahead of it. Downgrade | ||
| drops only what this revision created. | ||
|
|
||
| Revision ID: a3f7ce361b0e | ||
| Revises: b005ddbf1dba | ||
| Create Date: 2026-10-24 | ||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
|
|
||
| revision: str = "a3f7ce361b0e" # pragma: allowlist secret | ||
| down_revision: Union[str, Sequence[str], None] = "b005ddbf1dba" # pragma: allowlist secret | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
| _UPGRADE_STATEMENTS: tuple[str, ...] = ( | ||
| """ | ||
| CREATE TABLE IF NOT EXISTS fsma.epcis_document_receipts ( | ||
| id uuid primary key default gen_random_uuid(), | ||
| tenant_id uuid not null, | ||
| document_sha256 text not null, | ||
| received_at timestamptz not null default now(), | ||
| status text not null, | ||
| error_summary text, | ||
| constraint epcis_document_receipts_status_check | ||
| check (status in ('accepted', 'rejected')), | ||
| constraint epcis_document_receipts_sha256_check | ||
| check (document_sha256 ~ '^[0-9a-f]{64}$'), | ||
| constraint epcis_document_receipts_error_summary_length_check | ||
| check (error_summary is null or char_length(error_summary) <= 200) | ||
| ); | ||
| """, | ||
| """ | ||
| -- Read path: rejected share per tenant over a rolling window. | ||
| create index if not exists idx_epcis_document_receipts_tenant_received | ||
| on fsma.epcis_document_receipts (tenant_id, received_at); | ||
| """, | ||
| """ | ||
| ALTER TABLE fsma.epcis_document_receipts ENABLE ROW LEVEL SECURITY; | ||
| """, | ||
| """ | ||
| ALTER TABLE fsma.epcis_document_receipts FORCE ROW LEVEL SECURITY; | ||
| """, | ||
| """ | ||
| -- CASE form, not OR: public.get_tenant_context() raises when app.tenant_id is | ||
| -- unset and Postgres does not order OR operands, so the sysadmin arm is tested | ||
| -- first (same predicate shape as alembic v096, v134 and v135). | ||
| drop policy if exists tenant_isolation_epcis_document_receipts on fsma.epcis_document_receipts; | ||
| """, | ||
| """ | ||
| create policy tenant_isolation_epcis_document_receipts on fsma.epcis_document_receipts | ||
| for all | ||
| using ( | ||
| case | ||
| when (select current_setting('regengine.is_sysadmin', true)) = 'true' | ||
| and current_user = 'regengine_sysadmin' then true | ||
| else tenant_id = (select public.get_tenant_context()) | ||
| end | ||
| ) | ||
| with check ( | ||
| case | ||
| when (select current_setting('regengine.is_sysadmin', true)) = 'true' | ||
| and current_user = 'regengine_sysadmin' then true | ||
| else tenant_id = (select public.get_tenant_context()) | ||
| end | ||
| ); | ||
| """, | ||
| """ | ||
| -- Runtime role allowlist (alembic v111): new tables are inaccessible to the | ||
| -- app role until a migration names them. Insert and select only: a receipt is | ||
| -- evidence and is never updated or deleted by the app. | ||
| do $$ | ||
| begin | ||
| if exists (select 1 from pg_roles where rolname = 'anon') then | ||
| revoke all on fsma.epcis_document_receipts from anon; | ||
| end if; | ||
| if exists (select 1 from pg_roles where rolname = 'authenticated') then | ||
| revoke all on fsma.epcis_document_receipts from authenticated; | ||
| end if; | ||
| if exists (select 1 from pg_roles where rolname = 'regengine') then | ||
| grant select, insert on fsma.epcis_document_receipts to regengine; | ||
| end if; | ||
| if exists (select 1 from pg_roles where rolname = 'regengine_sysadmin') then | ||
| grant select on fsma.epcis_document_receipts to regengine_sysadmin; | ||
| end if; | ||
| end $$; | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| for statement in _UPGRADE_STATEMENTS: | ||
| op.execute(statement) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.execute("DROP POLICY IF EXISTS tenant_isolation_epcis_document_receipts ON fsma.epcis_document_receipts") | ||
| op.execute("DROP INDEX IF EXISTS fsma.idx_epcis_document_receipts_tenant_received") | ||
| op.execute("DROP TABLE IF EXISTS fsma.epcis_document_receipts") | ||
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.