-- Align legacy ancestor view with v2 behavior by excluding root category id = 1.
CREATE OR REPLACE VIEW v_category_with_ancestors AS
SELECT c.id,
      parent.id AS ancestor_id,
      parent.name
FROM categories c
LEFT JOIN categories parent
      ON parent.lft <= c.lft
      AND parent.rgt >= c.rgt
      AND parent.id <> 1
WHERE c.id <> 1;
