feat(scanner): country-scoped pending submission uniqueness (#930)#943
Merged
ericsocrat merged 1 commit intomainfrom Mar 17, 2026
Merged
Conversation
- 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
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
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_productandapi_record_scanto perform country-scoped pending-submission checks, with a global fallback when country isNULL. - 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 |
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
Replaces global
idx_ps_ean_pendingwith country-scopedidx_ps_ean_country_pendingon(ean, suggested_country) WHERE status = 'pending'. Updatesapi_submit_productandapi_record_scanto use country-scoped duplicate/pending checks with global fallback for NULL country.Closes #930
Changes
20260321000500: Drop old index, create country-scoped unique index, recreate both functions with country-aware pending checksVerification
supabase db reset --local— migration applies cleanlysupabase test db— all 9 new tests pass (12 pre-existing failures unchanged)Design
trg_submission_quality_triage+trg_trust_score_adjustmentfor direct INSERT tests; use EAN not in products table