diff --git a/changelog/63_UNRELEASED_xxxx.xx.xx.md b/changelog/63_UNRELEASED_xxxx.xx.xx.md index c81eb25a..109367fd 100644 --- a/changelog/63_UNRELEASED_xxxx.xx.xx.md +++ b/changelog/63_UNRELEASED_xxxx.xx.xx.md @@ -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 diff --git a/migrations/0130.sql b/migrations/0130.sql index 51db2d3f..c47003f5 100644 --- a/migrations/0130.sql +++ b/migrations/0130.sql @@ -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; \ No newline at end of file +SET allow_label_per_unit = 0;