From fb947fde6207409f99ccb6c55179e9af4865a922 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Mon, 24 Jun 2024 15:15:47 +0200 Subject: [PATCH] funders api: created dsm_service_funder table + updated view --- .../src/main/resources/sql/funders-schema.sql | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/dnet-exporter-api/src/main/resources/sql/funders-schema.sql b/apps/dnet-exporter-api/src/main/resources/sql/funders-schema.sql index 9e733f32..3edb232f 100644 --- a/apps/dnet-exporter-api/src/main/resources/sql/funders-schema.sql +++ b/apps/dnet-exporter-api/src/main/resources/sql/funders-schema.sql @@ -1,6 +1,15 @@ ALTER TABLE dsm_organizations ADD COLUMN registered_funder boolean; -CREATE VIEW funders_view AS SELECT + +CREATE TABLE dsm_service_funder ( + _dnet_resource_identifier_ varchar(2048) DEFAULT 'temp_'||md5(clock_timestamp()::text)||'_'||md5(random()::text), + service text NOT NULL REFERENCES dsm_services(id) ON DELETE CASCADE, + funder text NOT NULL REFERENCES dsm_organizations(id) ON DELETE CASCADE, + last_collection_date date, + PRIMARY KEY(funder, service) +); + +CREATE OR REPLACE VIEW funders_view AS SELECT o.id AS id, o.legalshortname AS legalshortname, o.legalname AS legalname, @@ -13,13 +22,13 @@ CREATE VIEW funders_view AS SELECT array_agg(DISTINCT pids.issuertype||' @=@ '||pids.pid) AS pids FROM dsm_organizations o - JOIN dsm_service_organization so ON (o.id = so.organization) - JOIN dsm_services s ON (so.service = s.id) - JOIN projects p ON (p.collectedfrom = s.id) + JOIN dsm_service_funder sf ON (o.id = sf.funder) + JOIN dsm_services s ON (sf.service = s.id) LEFT OUTER JOIN dsm_organizationpids opids ON (o.id = opids.organization) LEFT OUTER JOIN dsm_identities pids ON (opids.pid = pids.pid) GROUP BY o.id; +GRANT ALL ON dsm_service_funder TO dnetapi; GRANT ALL ON funders_view TO dnetapi;