Fixed migration when having unsupported parent/child product nesting levels (fixes #1542)

This commit is contained in:
Bernd Bestel 2021-07-25 20:22:10 +02:00
parent cf382bb47f
commit 53e405c4f8
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 33 additions and 1 deletions

View File

@ -1,2 +1,4 @@
- Fixed that the upgrade failed when having "> 2 times duplicate" (means the same barcode was added more than 2 times) product barcodes
- Fixed that when having any "Track date only" chore on the calendar, the iCal export was broken
- Fixed that the upgrade failed when having unsupported parent/child product nesting levels
- More information on this: Only 1 level is currently supported; creating > 1 level nestings was _never_ possible via the UI/frontend, but not checked/enforced by the backend before `v3.0.0` - so it was potentially possible via the API (or any third party app/tool which utilizes it) to create such a nesting which then made this upgrade to fail

View File

@ -1,3 +1,33 @@
/*
Parent/child product relations are currently limited to 1 level.
This was enforced by the UI/frontend since ever, but on the backend/database only
since v3.0.0 (by the trigger enfore_product_nesting_level).
So via the API (or any third party app/tool which utilizes it), it was potentially possible
to create > 1 level nestings before v3.0.0.
The ALTER TABLE statement below does technically an update on all product rows (due to the column default value),
so > 1 level nestings would make this fail.
=> So clean up those unsupported nesting levels here.
*/
-- Clears parent_product_id for any > 1 level nesting (which is currently unsupported)
UPDATE products
SET parent_product_id = NULL
WHERE id IN (
SELECT
p_child.id
FROM products p_parent
JOIN products p_child
ON p_parent.parent_product_id = p_child.id
WHERE p_parent.parent_product_id IS NOT NULL
)
AND parent_product_id IS NOT NULL;
ALTER TABLE products
ADD default_print_stock_label INTEGER NOT NULL DEFAULT 0;
@ -8,4 +38,4 @@ ALTER TABLE products
ADD allow_label_per_unit INTEGER NOT NULL DEFAULT 0;
UPDATE products
SET allow_label_per_unit = 0;
SET allow_label_per_unit = 0;