Skip to content

Commit

Permalink
Merge pull request #1352 from research-software-directory/1350-catego…
Browse files Browse the repository at this point in the history
…ry-overview-database

1350 category overview database
  • Loading branch information
ewan-escience authored Nov 22, 2024
2 parents 2317c36 + f338f42 commit 20db918
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend-postgrest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#
# SPDX-License-Identifier: Apache-2.0

FROM postgrest/postgrest:v12.2.2
FROM postgrest/postgrest:v12.2.3
29 changes: 29 additions & 0 deletions database/014-create-keyword-and-category.sql
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ $$;
-- includes organisation, community and general categories
-- Note! to filter specific categories of an community or organisation use join with community table

-- if you ever change this table, then software_of_category() needs to be changed as well
CREATE TABLE category_for_software (
software_id UUID REFERENCES software (id),
category_id UUID REFERENCES category (id),
Expand Down Expand Up @@ -260,6 +261,8 @@ $$;

-- TABLE FOR project categories
-- currently used only for organisation categories

-- if you ever change this table, then projects_of_category() needs to be changed as well
CREATE TABLE category_for_project (
project_id UUID REFERENCES project (id),
category_id UUID REFERENCES category (id),
Expand Down Expand Up @@ -298,3 +301,29 @@ $$
ELSE '[]'::json
END AS result
$$;


CREATE FUNCTION software_of_category()
RETURNS SETOF category_for_software
LANGUAGE SQL STABLE AS
$$
SELECT DISTINCT software.id, category_path.id
FROM software
INNER JOIN category_for_software
ON software.id = category_for_software.software_id
INNER JOIN category_path(category_for_software.category_id)
ON TRUE;
$$;


CREATE FUNCTION projects_of_category()
RETURNS SETOF category_for_project
LANGUAGE SQL STABLE AS
$$
SELECT DISTINCT project.id, category_path.id
FROM project
INNER JOIN category_for_project
ON project.id = category_for_project.project_id
INNER JOIN category_path(category_for_project.category_id)
ON TRUE;
$$;
2 changes: 1 addition & 1 deletion database/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: Apache-2.0

FROM postgres:15.7
FROM postgres:15.9
RUN chmod a+rwx /docker-entrypoint-initdb.d
COPY --chown=postgres:postgres *.sh /docker-entrypoint-initdb.d/
COPY --chown=postgres:postgres *.sql /docker-entrypoint-initdb.d/
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ version: "3.0"
services:
database:
build: ./database
image: rsd/database:2.5.0
image: rsd/database:2.6.0
ports:
# enable connection from outside (development mode)
- "5432:5432"
Expand Down

0 comments on commit 20db918

Please sign in to comment.