Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions supabase/migrations/20260320000100_scan_history_country.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Migration: Add scan_country to scan_history
-- Purpose: Captures user's catalog region at scan time (from user_preferences.country).
-- Enables country-scoped scan analytics and downstream country-aware features.
-- Nullable: Existing rows have no country context; old API callers still work.
-- Rollback: ALTER TABLE public.scan_history DROP COLUMN IF EXISTS scan_country;
-- Issue: #921 | Epic: #920

ALTER TABLE public.scan_history
ADD COLUMN IF NOT EXISTS scan_country text
REFERENCES public.country_ref(country_code);

-- Partial index for country-scoped analytics queries
CREATE INDEX IF NOT EXISTS idx_sh_country
ON public.scan_history (scan_country)
WHERE scan_country IS NOT NULL;

COMMENT ON COLUMN public.scan_history.scan_country IS
'User catalog region at scan time (from user_preferences.country). NULL for legacy rows.';
9 changes: 8 additions & 1 deletion supabase/tests/schema_contracts.test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- ─────────────────────────────────────────────────────────────────────────────

BEGIN;
SELECT plan(288);
SELECT plan(297);

-- ═══════════════════════════════════════════════════════════════════════════
-- 1. Core data tables exist
Expand Down Expand Up @@ -421,5 +421,12 @@ SELECT has_function('public', 'api_unwatch_product', 'fu
SELECT has_function('public', 'api_get_watchlist', 'function api_get_watchlist exists');
SELECT has_trigger('products', 'trg_record_score_change', 'trigger trg_record_score_change exists on products');

-- ─── scan_history.scan_country (#921, epic #920) ─────────────────────────────
SELECT has_column('public', 'scan_history', 'scan_country', 'scan_history has scan_country column');
SELECT col_is_null('public', 'scan_history', 'scan_country', 'scan_history.scan_country is nullable');
SELECT fk_ok('public', 'scan_history', 'scan_country',
'public', 'country_ref', 'country_code',
'scan_history.scan_country references country_ref(country_code)');
Comment on lines +424 to +429

SELECT * FROM finish();
ROLLBACK;
Loading