diff --git a/migrations/000.631.sql b/migrations/000.631.sql new file mode 100644 index 0000000..6c432a7 --- /dev/null +++ b/migrations/000.631.sql @@ -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;