-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.6.0-to-1.7.0.sql
62 lines (51 loc) · 1.78 KB
/
1.6.0-to-1.7.0.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---------- CREATED BY MIGRA ----------
create table "public"."orcid_whitelist" (
"orcid" character varying(19) not null
);
alter table "public"."orcid_whitelist" enable row level security;
alter table "public"."contributor" add column "position" integer;
alter table "public"."team_member" add column "position" integer;
CREATE UNIQUE INDEX orcid_whitelist_pkey ON public.orcid_whitelist USING btree (orcid);
alter table "public"."orcid_whitelist" add constraint "orcid_whitelist_pkey" PRIMARY KEY using index "orcid_whitelist_pkey";
alter table "public"."orcid_whitelist" add constraint "orcid_whitelist_orcid_check" CHECK (((orcid)::text ~ '^\d{4}-\d{4}-\d{4}-\d{3}[0-9X]$'::text));
set check_function_bodies = off;
CREATE OR REPLACE FUNCTION public.project_count_by_organisation(public boolean DEFAULT true)
RETURNS TABLE(organisation uuid, project_cnt bigint)
LANGUAGE plpgsql
STABLE
AS $function$
BEGIN
IF (public) THEN
RETURN QUERY
SELECT
list_parent_organisations.organisation_id,
COUNT(DISTINCT project_for_organisation.project) AS project_cnt
FROM
project_for_organisation
CROSS JOIN list_parent_organisations(project_for_organisation.organisation)
WHERE
status = 'approved' AND
project IN (
SELECT id FROM project WHERE is_published=TRUE
)
GROUP BY list_parent_organisations.organisation_id;
ELSE
RETURN QUERY
SELECT
list_parent_organisations.organisation_id,
COUNT(DISTINCT project_for_organisation.project) AS project_cnt
FROM
project_for_organisation
CROSS JOIN list_parent_organisations(project_for_organisation.organisation)
GROUP BY list_parent_organisations.organisation_id;
END IF;
END
$function$
;
create policy "admin_all_rights"
on "public"."orcid_whitelist"
as permissive
for all
to rsd_admin
using (true)
with check (true);