From f4f3ed1d246c73b514c90004ea790f3c2bc2d56c Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Wed, 25 Sep 2024 15:51:20 +0200 Subject: [PATCH] partial implementation --- .../community-schema-patch-subcommunities.sql | 13 +++++++ .../main/resources/sql/community-schema.sql | 35 ++++++++++--------- 2 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 apps/dnet-exporter-api/src/main/resources/sql/community-schema-patch-subcommunities.sql diff --git a/apps/dnet-exporter-api/src/main/resources/sql/community-schema-patch-subcommunities.sql b/apps/dnet-exporter-api/src/main/resources/sql/community-schema-patch-subcommunities.sql new file mode 100644 index 00000000..92f114c2 --- /dev/null +++ b/apps/dnet-exporter-api/src/main/resources/sql/community-schema-patch-subcommunities.sql @@ -0,0 +1,13 @@ +-- ADD FIELDS +-- parent text REFERENCES communities(id) ON DELETE CASCADE, -- NULL for the main community +-- claimable boolean NOT NULL DEFAULT false, -- spcefici for sub-communities +-- ... + + +-- MISSING CASCADE +community_projects +community_datasources +community_support_orgs +community_orgs + +CREATE INDEX community_parent ON communities(parent); diff --git a/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql b/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql index 2d1d8b8e..8a16b10a 100644 --- a/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql +++ b/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql @@ -7,6 +7,10 @@ DROP TABLE IF EXISTS communities; CREATE TABLE communities ( id text PRIMARY KEY, + + parent text REFERENCES communities(id) ON DELETE CASCADE, -- NULL for the main community + claimable boolean NOT NULL DEFAULT false, -- spceficic for sub-communities + name text NOT NULL, shortname text NOT NULL, -- in the profile is label displayname text, @@ -31,7 +35,7 @@ CREATE TABLE communities ( ); CREATE TABLE community_projects ( - community text NOT NULL REFERENCES communities(id), + community text NOT NULL REFERENCES communities(id) ON DELETE CASCADE, project_id text NOT NULL, project_code text NOT NULL, project_name text NOT NULL, @@ -42,7 +46,7 @@ CREATE TABLE community_projects ( ); CREATE TABLE community_datasources ( - community text NOT NULL REFERENCES communities(id), + community text NOT NULL REFERENCES communities(id) ON DELETE CASCADE, ds_id text NOT NULL, ds_name text NOT NULL, ds_officialname text NOT NULL, @@ -54,7 +58,7 @@ CREATE TABLE community_datasources ( ); CREATE TABLE community_support_orgs ( - community text NOT NULL REFERENCES communities(id), + community text NOT NULL REFERENCES communities(id) ON DELETE CASCADE, org_name text NOT NULL, org_url text NOT NULL, org_logourl text NOT NULL, @@ -62,26 +66,25 @@ CREATE TABLE community_support_orgs ( ); CREATE TABLE community_orgs ( - community text NOT NULL REFERENCES communities(id), + community text NOT NULL REFERENCES communities(id) ON DELETE CASCADE, org_id text NOT NULL, PRIMARY KEY (community, org_id) ); -CREATE TABLE community_subs ( - sub_id text NOT NULL PRIMARY KEY, - community text NOT NULL REFERENCES communities(id), - label text NOT NULL, - category text NOT NULL, - claim boolean NOT NULL DEFAULT false, - browsable boolean NOT NULL DEFAULT false, - params jsonb, - parent text REFERENCES community_subs(sub_id) -- NULL for the first level -); +--CREATE TABLE community_subs ( +-- sub_id text NOT NULL PRIMARY KEY, +-- community text NOT NULL REFERENCES communities(id), +-- label text NOT NULL, +-- category text NOT NULL, +-- claim boolean NOT NULL DEFAULT false, +-- browsable boolean NOT NULL DEFAULT false, +-- params jsonb, +-- parent text REFERENCES community_subs(sub_id) -- NULL for the first level +--); CREATE INDEX community_projects_community ON community_projects(community); CREATE INDEX community_datasources_community ON community_datasources(community); CREATE INDEX community_support_orgs_community ON community_support_orgs(community); CREATE INDEX community_orgs_community ON community_orgs(community); -CREATE INDEX community_subs_community ON community_subs(community); -CREATE INDEX community_subs_parent ON community_subs(parent); +CREATE INDEX community_parent ON communities(parent);