Skip to content

feat(scanner): GS1 prefix to country hint utility function (#928)#940

Merged
ericsocrat merged 1 commit intomainfrom
feat/928-gs1-country-hint
Mar 17, 2026
Merged

feat(scanner): GS1 prefix to country hint utility function (#928)#940
ericsocrat merged 1 commit intomainfrom
feat/928-gs1-country-hint

Conversation

@ericsocrat
Copy link
Owner

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 sql
  • Covers GS1 prefixes: PL (590), DE (400–440), FR (300–379), GB (50), IE (539), IT (800–839), ES (840–849)
  • Store-internal detection: 020–029 and 200–299 ranges
  • UNKNOWN fallback with prefix field for debugging
  • NULL return for NULL/short input (STRICT)

Response shape

{"code": "PL", "name": "Poland", "confidence": "high"}
{"code": "STORE", "name": "Store-internal", "confidence": "low"}
{"code": "UNKNOWN", "name": "Unknown origin", "confidence": "none", "prefix": "999"}

Tests

  • 12 pgTAP tests in scanner_functions.test.sql (plan 80 → 92)
    • PL, DE (×2 for range), FR, GB, IE, IT, ES prefixes
    • Store-internal (020 + 200 ranges)
    • Unknown prefix with prefix field assertion
  • 1 schema contract in schema_contracts.test.sql (plan 302 → 303)

Verification

3 files changed, +165 / -2 lines
  • supabase/migrations/20260321000300_gs1_country_hint.sql — new migration
  • supabase/tests/scanner_functions.test.sql — 12 new pgTAP tests
  • supabase/tests/schema_contracts.test.sql — 1 new contract test

Checklist

  • Migration is idempotent (CREATE OR REPLACE)
  • pgTAP tests cover all GS1 prefixes + edge cases
  • Schema contract updated
  • No API contract changes (internal utility only)
  • No frontend changes required

Copilot AI review requested due to automatic review settings March 17, 2026 15:40
@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tryvit Ready Ready Preview, Comment Mar 17, 2026 3:42pm

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.sql and 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'
@ericsocrat ericsocrat merged commit 1b66d1c into main Mar 17, 2026
18 of 19 checks passed
@ericsocrat ericsocrat deleted the feat/928-gs1-country-hint branch March 17, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(scanner): GS1 prefix to country hint utility function

2 participants