refs #4515 simpleUpdate
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Pablo Natek 2023-09-28 09:19:43 +02:00
parent 098892c34c
commit 93ec5db1a3
1 changed files with 2 additions and 40 deletions

View File

@ -1,49 +1,11 @@
-- algunas medias se quedan muy fuera de lugar ALTER TABLE `vn`.`item` MODIFY COLUMN `size` int(10) NOT NULL DEFAULT ;
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` ALTER TABLE `vn`.`item`
MODIFY COLUMN weightByPiece int(10) NOT NULL MODIFY COLUMN weightByPiece int(10) NOT NULL
COMMENT 'peso por defecto para un articulo por tallo/unidad'; COMMENT 'peso por defecto para un articulo por tallo/unidad' DEFAULT ;
-- revisar algunos se quedan fuera
UPDATE `vn`.`buy` b
SET b.packing = IFNULL(b.grouping, 0) * 2
WHERE b.packing IS NULL;
ALTER TABLE `vn`.`buy` ALTER TABLE `vn`.`buy`
MODIFY COLUMN packing int(11) MODIFY COLUMN packing int(11)
DEFAULT 0 NOT NULL; 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; ALTER TABLE `vn`.`buy` MODIFY COLUMN `weight` decimal(10,2) NOT NULL;