From b25305aa003a2ba09e8823c64522228174ac2b3b Mon Sep 17 00:00:00 2001 From: Rikard Bartholf Date: Thu, 6 Jul 2023 14:38:41 +0200 Subject: [PATCH] Add procedure stockproduct_create (#340) * Add procedure stockproduct_create * Replace tabs with spaces * Set visible end browsable default = 0 --- migrations/000.999.sql | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 migrations/000.999.sql diff --git a/migrations/000.999.sql b/migrations/000.999.sql new file mode 100644 index 0000000..281a733 --- /dev/null +++ b/migrations/000.999.sql @@ -0,0 +1,30 @@ +-- PROCEDURE: public.stockproduct_create(text, text, text, integer, integer, integer, integer) + +DROP PROCEDURE IF EXISTS public.stockproduct_create; + +CREATE OR REPLACE PROCEDURE public.stockproduct_create( + _article_number text, + _name text, + _path text, + _visible integer DEFAULT 0, + _browsable integer DEFAULT 0, + INOUT _product_id integer DEFAULT NULL::integer, + INOUT _stock_id integer DEFAULT NULL::integer) +LANGUAGE 'plpgsql' +AS $BODY$ + +BEGIN + INSERT INTO "product-products" (path, visible, browsable) + VALUES (_path, _visible, _browsable) + RETURNING productid INTO _product_id; + + INSERT INTO "product-products_fields" (productid, fieldid, value) + VALUES + (_product_id, 1, _article_number), + (_product_id, 2, _name); + + INSERT INTO stockproducts (product_id, name, in_stock) + VALUES (_product_id, _name, true) + RETURNING id INTO _stock_id; +END; +$BODY$;