From a2b2f26628d6c96a43fbf3870f440956ea1180e2 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 18 Oct 2020 15:52:52 +0200 Subject: [PATCH] Delete stock_log rows for not existing products in migration 0103 (fixes #1002) --- migrations/0103.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/migrations/0103.sql b/migrations/0103.sql index 862d01f5..d118733b 100644 --- a/migrations/0103.sql +++ b/migrations/0103.sql @@ -1,13 +1,17 @@ +-- Delete stock_log rows for not existing products as this would make the rest here fail +DELETE from stock_log +WHERE product_id NOT IN (SELECT id from products); + ALTER TABLE stock_log ADD qu_factor_purchase_to_stock REAL NOT NULL DEFAULT 1.0; ALTER TABLE stock ADD qu_factor_purchase_to_stock REAL NOT NULL DEFAULT 1.0; -UPDATE stock +UPDATE stock SET qu_factor_purchase_to_stock = (SELECT qu_factor_purchase_to_stock FROM products WHERE product_id = id); -UPDATE stock_log +UPDATE stock_log SET qu_factor_purchase_to_stock = (SELECT qu_factor_purchase_to_stock FROM products WHERE product_id = id); --Price is now going forward to be saved as 1 QU Stock