9432 - backfill categories with any new categories_v2_lft_rgt categories (#559)

This commit is contained in:
Anders Gustafsson
2026-05-13 11:00:10 +02:00
committed by GitHub
parent 52ec67eb5e
commit c7705ded34
+14
View File
@@ -0,0 +1,14 @@
-- Backfill any category that exists in categories_v2_lft_rgt but is missing
-- from the canonical `categories` table. The canonical table is what
-- product_category references via FK, so every v2 category must have a
-- corresponding row there (with is_v2 = true).
--
-- This covers categories 1824 and 1825 (created before insertNode was fixed)
-- and any other gaps that may exist. ON CONFLICT makes it safe to re-run.
INSERT INTO categories (id, name, is_v2)
SELECT v2.id, v2.name, true
FROM categories_v2_lft_rgt v2
WHERE NOT EXISTS (
SELECT 1 FROM categories c WHERE c.id = v2.id
)
ON CONFLICT (id) DO NOTHING;