15 lines
644 B
SQL
15 lines
644 B
SQL
-- 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;
|