Skip to content

feat(scanner): country-scoped pending submission uniqueness (#930)#943

Merged
ericsocrat merged 1 commit intomainfrom
feat/930-country-scoped-submission-uniqueness
Mar 17, 2026
Merged

feat(scanner): country-scoped pending submission uniqueness (#930)#943
ericsocrat merged 1 commit intomainfrom
feat/930-country-scoped-submission-uniqueness

Conversation

@ericsocrat
Copy link
Owner

Summary

Replaces global idx_ps_ean_pending with country-scoped idx_ps_ean_country_pending on (ean, suggested_country) WHERE status = 'pending'. Updates api_submit_product and api_record_scan to use country-scoped duplicate/pending checks with global fallback for NULL country.

Closes #930

Changes

  • Migration 20260321000500: Drop old index, create country-scoped unique index, recreate both functions with country-aware pending checks
  • pgTAP tests: 9 new tests (plan 92 -> 101) — index uniqueness (4), api_record_scan country-scoped has_pending_submission (3), index existence (2)
  • QA check feat: Sonar + coverage + CI hardening (PR-A) #4: Updated index name reference

Verification

Design

  • NULL country: Excluded from unique index (PostgreSQL NULL != NULL), global fallback in both functions
  • Backward compatible: All API parameters have defaults, no response shape changes
  • Trigger-safe tests: Disable trg_submission_quality_triage + trg_trust_score_adjustment for direct INSERT tests; use EAN not in products table

- Replace global idx_ps_ean_pending with idx_ps_ean_country_pending
  on (ean, suggested_country) WHERE status = 'pending'
- Update api_submit_product: country-scoped duplicate check with
  global fallback for NULL country
- Update api_record_scan: country-scoped has_pending_submission
- Add 9 pgTAP tests (plan 92 -> 101)
- Update QA check #4 for new index name
Copilot AI review requested due to automatic review settings March 17, 2026 16:56
@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.

@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 4:58pm

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

Implements country-scoped uniqueness for pending product_submissions to allow the same EAN to be pending in multiple countries concurrently, and updates scanner RPC logic/tests to align with the new constraint.

Changes:

  • Replace the global partial unique index on pending submissions with a country-scoped partial unique index on (ean, suggested_country).
  • Update api_submit_product and api_record_scan to perform country-scoped pending-submission checks, with a global fallback when country is NULL.
  • Add pgTAP coverage for the new index behavior and country-scoped has_pending_submission, and update QA check #4 to reference the new index.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
supabase/migrations/20260321000500_country_scoped_submission_uniqueness.sql Drops old pending-uniqueness index, creates new country-scoped index, updates scanner RPCs for country-aware pending checks.
supabase/tests/scanner_functions.test.sql Adds pgTAP assertions for new index behavior and country-scoped has_pending_submission; updates test plan.
db/qa/QA__scanner_submissions.sql Updates QA check to look for the new index name.

p.brand, p.category, p.country, p.unhealthiness_score, p.nutri_score_label
INTO v_product
FROM public.products p
WHERE p.ean = TRIM(p_ean)
'unhealthiness_score', v_product.unhealthiness_score,
'nutri_score', v_product.nutri_score_label,
'scan_country', v_scan_country,
'product_country', v_product.country
@ericsocrat ericsocrat merged commit 0d8c0be into main Mar 17, 2026
18 of 19 checks passed
@ericsocrat ericsocrat deleted the feat/930-country-scoped-submission-uniqueness branch March 17, 2026 17:01
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): country-scoped pending submission uniqueness

2 participants