chore: harden reliability checks #2

Merged
nalalangan merged 67 commits from main-new into main 2026-05-25 14:28:32 -09:00
Showing only changes of commit 5693570f33 - Show all commits

View File

@ -0,0 +1,23 @@
BEGIN;
WITH ranked_classifications AS (
SELECT
id,
ROW_NUMBER() OVER (
PARTITION BY household_id, store_id, household_store_item_id
ORDER BY updated_at DESC NULLS LAST, id DESC
) AS row_rank
FROM household_item_classifications
WHERE household_store_item_id IS NOT NULL
)
DELETE FROM household_item_classifications hic
USING ranked_classifications ranked
WHERE hic.id = ranked.id
AND ranked.row_rank > 1;
DROP INDEX IF EXISTS idx_household_item_classifications_household_store_item;
CREATE UNIQUE INDEX idx_household_item_classifications_household_store_item
ON household_item_classifications(household_id, store_id, household_store_item_id);
COMMIT;