-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.2.2-to-1.3.0.sql
198 lines (186 loc) · 6.01 KB
/
1.2.2-to-1.3.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
---------- CREATED BY MIGRA ----------
drop function if exists "public"."project_search"();
drop function if exists "public"."projects_by_maintainer"(maintainer_id uuid);
drop function if exists "public"."projects_by_organisation"(organisation_id uuid);
drop function if exists "public"."related_projects_for_project"(origin_id uuid);
drop function if exists "public"."related_projects_for_software"(software_id uuid);
alter table "public"."project" add column "image_contain" boolean not null default false;
set check_function_bodies = off;
CREATE OR REPLACE FUNCTION public.project_search()
RETURNS TABLE(id uuid, slug character varying, title character varying, subtitle character varying, current_state character varying, date_start date, updated_at timestamp with time zone, is_published boolean, image_contain boolean, image_id uuid, keywords citext[])
LANGUAGE plpgsql
STABLE
AS $function$
BEGIN
RETURN QUERY
SELECT
project.id,
project.slug,
project.title,
project.subtitle,
CASE
WHEN project.date_end IS NULL THEN 'Starting'::varchar
WHEN project.date_end < now() THEN 'Finished'::varchar
ELSE 'Running'::varchar
END AS current_state,
project.date_start,
project.updated_at,
project.is_published,
project.image_contain,
image_for_project.project AS image_id,
keyword_filter_for_project.keywords
FROM
project
LEFT JOIN
image_for_project ON project.id = image_for_project.project
LEFT JOIN
keyword_filter_for_project() ON project.id=keyword_filter_for_project.project
;
END
$function$
;
CREATE OR REPLACE FUNCTION public.projects_by_maintainer(maintainer_id uuid)
RETURNS TABLE(id uuid, slug character varying, title character varying, subtitle character varying, current_state character varying, date_start date, updated_at timestamp with time zone, is_published boolean, image_contain boolean, image_id uuid)
LANGUAGE plpgsql
STABLE
AS $function$
BEGIN
RETURN QUERY
SELECT
project.id,
project.slug,
project.title,
project.subtitle,
CASE
WHEN project.date_end IS NULL THEN 'Starting'::varchar
WHEN project.date_end < now() THEN 'Finished'::varchar
ELSE 'Running'::varchar
END AS current_state,
project.date_start,
project.updated_at,
project.is_published,
project.image_contain,
image_for_project.project AS image_id
FROM
project
LEFT JOIN
image_for_project ON project.id = image_for_project.project
INNER JOIN
maintainer_for_project ON project.id = maintainer_for_project.project
WHERE
maintainer_for_project.maintainer = maintainer_id;
END
$function$
;
CREATE OR REPLACE FUNCTION public.projects_by_organisation(organisation_id uuid)
RETURNS TABLE(id uuid, slug character varying, title character varying, subtitle character varying, current_state character varying, date_start date, updated_at timestamp with time zone, is_published boolean, image_contain boolean, is_featured boolean, image_id uuid, organisation uuid, status relation_status, keywords citext[])
LANGUAGE plpgsql
STABLE
AS $function$
BEGIN
RETURN QUERY
SELECT
project.id,
project.slug,
project.title,
project.subtitle,
CASE
WHEN project.date_end IS NULL THEN 'Starting'::varchar
WHEN project.date_end < now() THEN 'Finished'::varchar
ELSE 'Running'::varchar
END AS current_state,
project.date_start,
project.updated_at,
project.is_published,
project.image_contain,
project_for_organisation.is_featured,
image_for_project.project AS image_id,
project_for_organisation.organisation,
project_for_organisation.status,
keyword_filter_for_project.keywords
FROM
project
LEFT JOIN
image_for_project ON project.id = image_for_project.project
LEFT JOIN
project_for_organisation ON project.id = project_for_organisation.project
LEFT JOIN
keyword_filter_for_project() ON project.id=keyword_filter_for_project.project
WHERE
project_for_organisation.organisation=organisation_id
;
END
$function$
;
CREATE OR REPLACE FUNCTION public.related_projects_for_project(origin_id uuid)
RETURNS TABLE(origin uuid, id uuid, slug character varying, title character varying, subtitle character varying, current_state character varying, date_start date, updated_at timestamp with time zone, is_published boolean, image_contain boolean, status relation_status, image_id uuid)
LANGUAGE plpgsql
STABLE
AS $function$
BEGIN
RETURN QUERY
SELECT
project_for_project.origin,
project.id,
project.slug,
project.title,
project.subtitle,
CASE
WHEN project.date_end IS NULL THEN 'Starting'::varchar
WHEN project.date_end < now() THEN 'Finished'::varchar
ELSE 'Running'::varchar
END AS current_state,
project.date_start,
project.updated_at,
project.is_published,
project.image_contain,
project_for_project.status,
image_for_project.project AS image_id
FROM
project
LEFT JOIN
image_for_project ON image_for_project.project = project.id
INNER JOIN
project_for_project ON project.id = project_for_project.relation
WHERE
project_for_project.origin = origin_id
;
END
$function$
;
CREATE OR REPLACE FUNCTION public.related_projects_for_software(software_id uuid)
RETURNS TABLE(software uuid, id uuid, slug character varying, title character varying, subtitle character varying, current_state character varying, date_start date, updated_at timestamp with time zone, is_published boolean, image_contain boolean, status relation_status, image_id uuid)
LANGUAGE plpgsql
STABLE
AS $function$
BEGIN
RETURN QUERY
SELECT
software_for_project.software,
project.id,
project.slug,
project.title,
project.subtitle,
CASE
WHEN project.date_end IS NULL THEN 'Starting'::varchar
WHEN project.date_end < now() THEN 'Finished'::varchar
ELSE 'Running'::varchar
END AS current_state,
project.date_start,
project.updated_at,
project.is_published,
project.image_contain,
software_for_project.status,
image_for_project.project AS image_id
FROM
project
LEFT JOIN
image_for_project ON image_for_project.project = project.id
INNER JOIN
software_for_project ON project.id = software_for_project.project
WHERE
software_for_project.software = software_id
;
END
$function$
;