feat(scanner): GS1 prefix to country hint utility function (#928)#940
Merged
ericsocrat merged 1 commit intomainfrom Mar 17, 2026
Merged
feat(scanner): GS1 prefix to country hint utility function (#928)#940ericsocrat merged 1 commit intomainfrom
ericsocrat merged 1 commit intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
Adds a small Postgres utility (public.gs1_country_hint(p_ean text) -> jsonb) to derive a GS1 “country of registration” hint from an EAN prefix, intended as a building block for upcoming admin mismatch detection.
Changes:
- Introduces
public.gs1_country_hint(p_ean text)as an IMMUTABLE STRICT SQL function returning a JSONB hint object (or NULL for short input). - Extends pgTAP coverage in
scanner_functions.test.sqland updates schema contract checks to assert the function exists. - Updates pgTAP test plan counts to reflect the added assertions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| supabase/migrations/20260321000300_gs1_country_hint.sql | Adds the gs1_country_hint SQL function and its comment. |
| supabase/tests/scanner_functions.test.sql | Adds pgTAP assertions for known GS1 prefixes and unknown/store-internal handling. |
| supabase/tests/schema_contracts.test.sql | Adds a schema contract assertion for the new function and bumps the plan. |
| SET search_path = public | ||
| AS $$ | ||
| SELECT CASE | ||
| -- NULL / too-short handled by STRICT (returns NULL automatically) |
Comment on lines
+661
to
+666
| -- 1. PL prefix (590) → Poland | ||
| SELECT is( | ||
| (public.gs1_country_hint('5901234123457'))->>'code', | ||
| 'PL', | ||
| 'gs1_country_hint: 590 prefix returns PL (#928)' | ||
| ); |
Comment on lines
+737
to
+742
| SELECT ok( | ||
| (public.gs1_country_hint('9990000000000')) ? 'prefix', | ||
| 'gs1_country_hint: unknown result includes prefix field (#928)' | ||
| ); | ||
|
|
||
|
|
| THEN '{"code":"PL","name":"Poland","confidence":"high"}'::jsonb | ||
|
|
||
| -- Germany (400–440) | ||
| WHEN substring(p_ean, 1, 2) BETWEEN '40' AND '44' |
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.
Summary
Adds
gs1_country_hint(p_ean text)— an IMMUTABLE SQL function that extracts the GS1 country-of-registration hint from an EAN-13 barcode prefix. This is a building block for issue #929 (admin mismatch detection).Closes #928
Changes
Migration (
20260321000300_gs1_country_hint.sql)gs1_country_hint(p_ean text) → jsonb— IMMUTABLE STRICT, LANGUAGE sqlprefixfield for debuggingResponse shape
{"code": "PL", "name": "Poland", "confidence": "high"} {"code": "STORE", "name": "Store-internal", "confidence": "low"} {"code": "UNKNOWN", "name": "Unknown origin", "confidence": "none", "prefix": "999"}Tests
scanner_functions.test.sql(plan 80 → 92)prefixfield assertionschema_contracts.test.sql(plan 302 → 303)Verification
supabase/migrations/20260321000300_gs1_country_hint.sql— new migrationsupabase/tests/scanner_functions.test.sql— 12 new pgTAP testssupabase/tests/schema_contracts.test.sql— 1 new contract testChecklist
CREATE OR REPLACE)