Optimized product_barcodes handling (references #1928)

This commit is contained in:
Bernd Bestel 2022-06-30 13:38:30 +02:00
parent bef261d869
commit a80e048c2d
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300

12
migrations/0195.sql Normal file
View File

@ -0,0 +1,12 @@
-- Delete once all barcodes without a valid product_id (those are not visible anywhere)
DELETE FROM product_barcodes
WHERE product_id NOT IN (SELECT id FROM products);
CREATE TRIGGER prevent_adding_barcodes_for_not_existing_products AFTER INSERT ON product_barcodes
BEGIN
SELECT CASE WHEN((
SELECT 1
FROM products p
WHERE id = NEW.product_id
) ISNULL) THEN RAISE(ABORT, "product_id doesn't reference a existing product") END;
END;