Skip to content

Commit

Permalink
fix: cleanup sample functions (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp-Borchert-ISH authored Oct 6, 2022
1 parent 4db18b8 commit b052d4f
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ BEGIN
CREATE TABLE oms."CustomConfigurationDO"
(
id bigint,
"shop2SupplierRef" bigint,
"shop2SupplierRef" bigint NOT NULL,
"configType" character varying(255) NOT NULL,
CONSTRAINT "CustomConfigurationDO_pkey" PRIMARY KEY (id),
CONSTRAINT "Shop2SupplierDO_fkey" FOREIGN KEY ("shop2SupplierRef") REFERENCES oms."Shop2SupplierDO" (id) ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
;
CONSTRAINT "CustomConfigurationDO_pk" PRIMARY KEY (id),
CONSTRAINT "Shop2SupplierDO_fk" FOREIGN KEY ("shop2SupplierRef")
REFERENCES oms."Shop2SupplierDO" (id)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "CustomConfigurationDO_uk" UNIQUE ("shop2SupplierRef","configType")
);
CREATE SEQUENCE oms."CustomConfigurationDO_id_seq";
PERFORM admin.set_table_comment ('oms', 'CustomConfigurationDO','Contains custom property types for the Shop2SuppliersDO relations');
END IF;


IF false = admin.is_table('oms', 'CustomConfigurationDO_AV') THEN
CREATE TABLE oms."CustomConfigurationDO_AV"
(
Expand All @@ -26,14 +26,12 @@ BEGIN
value text NOT NULL,
CONSTRAINT pk_ref_key PRIMARY KEY ("customConfigurationRef", key),
CONSTRAINT "fk_customConfigurationRef" FOREIGN KEY ("customConfigurationRef")
REFERENCES oms."CustomConfigurationDO" (id) MATCH SIMPLE
REFERENCES oms."CustomConfigurationDO" (id)
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
END IF;
PERFORM admin.set_table_comment ('oms', 'CustomConfigurationDO_AV','Contains custom property values for the Shop2SuppliersDO relations');

END IF;

END;
$Do$;
$Do$;
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
DO $$


-- DROP FUNCTION oms.add_config_parameter(bigint, character varying, character varying, character varying);
CREATE OR REPLACE FUNCTION oms.add_s2s_config_parameter(
p_shop2supplierref bigint,
p_configtype varchar,
p_key varchar,
p_value varchar)
RETURNS void AS
$$

BEGIN

-- DROP FUNCTION oms.add_config_parameter(bigint, character varying, character varying, character varying);
CREATE OR REPLACE FUNCTION oms.add_config_parameter(
p_shop2supplierref bigint,
p_configtype character varying,
p_key character varying,
p_value character varying)
RETURNS void AS
$BODY$BEGIN
IF NOT EXISTS (SELECT 1 FROM oms."CustomConfigurationDO" where "shop2SupplierRef" = p_shop2supplierref and "configType" = p_configtype) THEN
INSERT INTO oms."CustomConfigurationDO" ("id", "shop2SupplierRef", "configType")
SELECT nextval('oms."CustomConfigurationDO_id_seq"'), p_shop2supplierref, p_configtype;
END IF;
IF p_key IS NOT NULL THEN
insert into oms."CustomConfigurationDO_AV" ("customConfigurationRef", key, value)
select (select id from oms."CustomConfigurationDO" where "shop2SupplierRef" = p_shop2supplierref and "configType" = p_configtype), p_key, p_value
ON CONFLICT ("customConfigurationRef", key) DO UPDATE SET value = p_value;
END IF;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
INSERT INTO oms."CustomConfigurationDO" ("id", "shop2SupplierRef", "configType")
SELECT nextval('oms."CustomConfigurationDO_id_seq"'), p_shop2supplierref, p_configtype
WHERE NOT EXISTS (select 1 FROM oms."CustomConfigurationDO"
where "shop2SupplierRef" = p_shop2supplierref and "configType" = p_configtype);

IF p_key IS NOT NULL THEN
INSERT INTO oms."CustomConfigurationDO_AV" ("customConfigurationRef", key, value)
SELECT (select id from oms."CustomConfigurationDO" where "shop2SupplierRef" = p_shop2supplierref and "configType" = p_configtype), p_key, p_value
ON CONFLICT ("customConfigurationRef", key) DO UPDATE SET value = p_value;
END IF;

END;
$$;

$$
LANGUAGE plpgsql VOLATILE;

comment on function oms.add_s2s_config_parameter(
p_shop2supplierref bigint,
p_configtype varchar,
p_key varchar,
p_value varchar) is 'add config values for a given Shop2SupplierDO / configType';

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Example functions
In case you are missing the "old" PSQL helper functions please have a look at the blueprint project.

See: [Github Repo iom-blueprint-project](https://github.com/intershop/iom-blueprint-project/tree/main/src/sql-config/dbmigrate)

0 comments on commit b052d4f

Please sign in to comment.