From a93a3561c3754790989a00c3888834198f71dd6a Mon Sep 17 00:00:00 2001 From: Martin Carlsson Date: Wed, 28 Oct 2020 15:13:52 +0100 Subject: [PATCH] P5-6075 create product categories view for esales export --- migrations/000.253.sql | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 migrations/000.253.sql diff --git a/migrations/000.253.sql b/migrations/000.253.sql new file mode 100644 index 0000000..67b7255 --- /dev/null +++ b/migrations/000.253.sql @@ -0,0 +1,25 @@ +--P5-6075: create view that displays *all* categories for a product + +drop materialized view if exists v_esales_product_categories; + +create materialized view v_esales_product_categories as +select distinct + tree.id, + tree.locale_id, + getSafeXmlPath(tree.path, 2) AS path, + category_texts.name as name, + product_category.product_id +from + product_category + join categories on product_category.category_id = categories.id + join categories hidden_category on hidden_category.name = 'hidden' + join v_esales_categorytree_i18n tree on + ((tree.lft < categories.lft and tree.rgt > categories.rgt) OR categories.id = tree.id) + and tree.id <> 1 and (tree.lft not between hidden_category.lft and hidden_category.rgt) + join category_texts on tree.id = category_texts.category_id and tree.locale_id = category_texts.locale_id; + + +create index product_locale_idx on v_esales_product_categories(product_id,locale_id); + + +alter materialized view v_esales_product_categories owner to photowall;