From 93ec5db1a3757be2e5c646270f50889247cbc8d5 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 28 Sep 2023 09:19:43 +0200 Subject: [PATCH] refs #4515 simpleUpdate --- db/changes/234001/00-updateWeight.sql | 42 ++------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/db/changes/234001/00-updateWeight.sql b/db/changes/234001/00-updateWeight.sql index 6f224667d..29c3ef8ae 100644 --- a/db/changes/234001/00-updateWeight.sql +++ b/db/changes/234001/00-updateWeight.sql @@ -1,49 +1,11 @@ --- algunas medias se quedan muy fuera de lugar -UPDATE `vn`.`item` i - JOIN( - SELECT typeFk, AVG(`size`) `size` - FROM vn.item - WHERE `size` > 0 - AND `size` IS NOT NULL - GROUP BY typeFk - ) sub ON sub.typeFk = i.typeFk - SET i.`size` = sub.`size` - WHERE i.`size` IS NULL; - -ALTER TABLE `vn`.`item` MODIFY COLUMN `size` int(10) NOT NULL; - -UPDATE `vn`.`item` i - JOIN( - SELECT typeFk, AVG(weightByPiece / `size`) grams - FROM vn.item - WHERE weightByPiece IS NOT NULL - AND weightByPiece > 0 - AND `size` > 0 - AND `size` IS NOT NULL - GROUP BY typeFk - ) sub ON sub.typeFk = i.typeFk - SET i.weightByPiece = sub.grams * `size` - WHERE weightByPiece IS NULL - OR weightByPiece = 0; +ALTER TABLE `vn`.`item` MODIFY COLUMN `size` int(10) NOT NULL DEFAULT ; ALTER TABLE `vn`.`item` MODIFY COLUMN weightByPiece int(10) NOT NULL - COMMENT 'peso por defecto para un articulo por tallo/unidad'; - --- revisar algunos se quedan fuera - -UPDATE `vn`.`buy` b - SET b.packing = IFNULL(b.grouping, 0) * 2 - WHERE b.packing IS NULL; + COMMENT 'peso por defecto para un articulo por tallo/unidad' DEFAULT ; ALTER TABLE `vn`.`buy` MODIFY COLUMN packing int(11) DEFAULT 0 NOT NULL; -UPDATE `vn`.`buy` b - JOIN `vn`.`item` i ON i.id = b.itemFk - SET b.weight = (i.weightByPiece * b.packing) / 1000 - WHERE weight IS NULL - OR weight = 0; - ALTER TABLE `vn`.`buy` MODIFY COLUMN `weight` decimal(10,2) NOT NULL; \ No newline at end of file