-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoriginal.sql
More file actions
5391 lines (3836 loc) · 150 KB
/
Copy pathoriginal.sql
File metadata and controls
5391 lines (3836 loc) · 150 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.3.10
-- Dumped by pg_dump version 9.5.3
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: basic_auth; Type: SCHEMA; Schema: -; Owner: postgres
--
CREATE SCHEMA basic_auth;
ALTER SCHEMA basic_auth OWNER TO postgres;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
--
-- Name: json_build; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS json_build WITH SCHEMA public;
--
-- Name: EXTENSION json_build; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION json_build IS 'json_build extension';
--
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
--
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';
--
-- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;
--
-- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';
SET search_path = basic_auth, pg_catalog;
--
-- Name: jwt_claims; Type: TYPE; Schema: basic_auth; Owner: postgres
--
CREATE TYPE jwt_claims AS (
role text,
email text,
exp integer,
person_id integer
);
ALTER TYPE jwt_claims OWNER TO postgres;
SET search_path = public, pg_catalog;
--
-- Name: token_type_enum; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE token_type_enum AS ENUM (
'validation',
'reset'
);
ALTER TYPE token_type_enum OWNER TO postgres;
SET search_path = basic_auth, pg_catalog;
--
-- Name: check_role_exists(); Type: FUNCTION; Schema: basic_auth; Owner: postgres
--
CREATE FUNCTION check_role_exists() RETURNS trigger
LANGUAGE plpgsql
AS $$
begin
if not exists (select 1 from pg_roles as r where r.rolname = new.role) then
raise foreign_key_violation using message =
'unknown database role: ' || new.role;
return null;
end if;
return new;
end
$$;
ALTER FUNCTION basic_auth.check_role_exists() OWNER TO postgres;
--
-- Name: clearance_for_role(name); Type: FUNCTION; Schema: basic_auth; Owner: postgres
--
CREATE FUNCTION clearance_for_role(u name) RETURNS void
LANGUAGE plpgsql
AS $$
declare
ok boolean;
begin
select exists (
select rolname
from pg_authid
where pg_has_role(current_user, oid, 'member')
and rolname = u
) into ok;
if not ok then
raise invalid_password using message =
'current user not member of role ' || u;
end if;
end
$$;
ALTER FUNCTION basic_auth.clearance_for_role(u name) OWNER TO postgres;
--
-- Name: current_email(); Type: FUNCTION; Schema: basic_auth; Owner: postgres
--
CREATE FUNCTION current_email() RETURNS text
LANGUAGE plpgsql
AS $$
begin
return current_setting('postgrest.claims.email');
exception
-- handle unrecognized configuration parameter error
when undefined_object then return '';
end;
$$;
ALTER FUNCTION basic_auth.current_email() OWNER TO postgres;
--
-- Name: encrypt_pass(); Type: FUNCTION; Schema: basic_auth; Owner: postgres
--
CREATE FUNCTION encrypt_pass() RETURNS trigger
LANGUAGE plpgsql
AS $$
begin
if tg_op = 'INSERT' or new.pass <> old.pass then
new.pass = crypt(new.pass, gen_salt('bf'));
end if;
return new;
end
$$;
ALTER FUNCTION basic_auth.encrypt_pass() OWNER TO postgres;
--
-- Name: send_validation(); Type: FUNCTION; Schema: basic_auth; Owner: postgres
--
CREATE FUNCTION send_validation() RETURNS trigger
LANGUAGE plpgsql
AS $$
declare
tok uuid;
begin
select uuid_generate_v4() into tok;
insert into basic_auth.tokens (token, token_type, email)
values (tok, 'validation', new.email);
insert into public.email_notifications
(email_to, subject, body, token_email, token, token_type)
values (new.email,'New User Validation','Follow Link Below to Validate New Account:',true,tok,'validation');
--perform pg_notify('validate',
--json_build_object(
--'email', new.email,
--'token', tok,
--'token_type', 'validation'
--)::text
--);
return new;
end
$$;
ALTER FUNCTION basic_auth.send_validation() OWNER TO postgres;
--
-- Name: user_role(text, text); Type: FUNCTION; Schema: basic_auth; Owner: postgres
--
CREATE FUNCTION user_role(email text, pass text) RETURNS name
LANGUAGE plpgsql
AS $$
begin
return (
select role from basic_auth.users
where users.email = user_role.email
and users.pass = crypt(user_role.pass, users.pass)
and users.verified = true
and users.ldap_user = false
);
end;
$$;
ALTER FUNCTION basic_auth.user_role(email text, pass text) OWNER TO postgres;
SET search_path = public, pg_catalog;
--
-- Name: call_application_statuses_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE call_application_statuses_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE call_application_statuses_id_seq OWNER TO postgres;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: call_application_statuses; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE call_application_statuses (
id integer DEFAULT nextval('call_application_statuses_id_seq'::regclass) NOT NULL,
status character varying(255) NOT NULL,
description text NOT NULL
);
ALTER TABLE call_application_statuses OWNER TO postgres;
--
-- Name: TABLE call_application_statuses; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE call_application_statuses IS 'The status of a call application.';
--
-- Name: call_applications_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE call_applications_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE call_applications_id_seq OWNER TO postgres;
--
-- Name: call_applications; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE call_applications (
id integer DEFAULT nextval('call_applications_id_seq'::regclass) NOT NULL,
call integer,
amount numeric(20,2),
applicant integer,
place integer,
comments text,
application_status integer,
score integer,
title text,
pmu_advisory text
);
ALTER TABLE call_applications OWNER TO postgres;
--
-- Name: TABLE call_applications; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE call_applications IS 'A call application is a response to a call from an organisation.';
--
-- Name: rpc_alfresco_change_application_status; Type: VIEW; Schema: public; Owner: postgres
--
CREATE VIEW rpc_alfresco_change_application_status AS
SELECT call_applications.id AS "projectId",
call_applications.id AS "projectCode",
call_applications.title AS "projectTitle",
call_application_statuses.status AS "projectStatusCode"
FROM (call_applications
LEFT JOIN call_application_statuses ON ((call_applications.application_status = call_application_statuses.id)));
ALTER TABLE rpc_alfresco_change_application_status OWNER TO postgres;
--
-- Name: alfresco_change_application_status(text, text); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION alfresco_change_application_status("projectCode" text, "newStatusCode" text) RETURNS SETOF rpc_alfresco_change_application_status
LANGUAGE plpgsql COST 1
AS $$
--#variable_conflict use_variable
DECLARE project_code INTEGER;
BEGIN
SET ROLE postgres;
SELECT call_applications.id INTO project_code
FROM call_applications
WHERE call_applications.id = alfresco_change_application_status."projectCode"::int;
IF project_code IS NULL THEN
RAISE EXCEPTION 'Application does not Exist!';
END IF;
UPDATE call_applications SET (application_status) = (alfresco_change_application_status."newStatusCode"::int)
WHERE call_applications.id = project_code;
RETURN QUERY SELECT * FROM rpc_alfresco_change_application_status
WHERE rpc_alfresco_change_application_status."projectId" = project_code;
--EXCEPTION WHEN OTHERS THEN /*Catch all*/
--RAISE EXCEPTION 'Something went wrong';
END;$$;
ALTER FUNCTION public.alfresco_change_application_status("projectCode" text, "newStatusCode" text) OWNER TO postgres;
--
-- Name: rpc_alfresco_create_application_code; Type: VIEW; Schema: public; Owner: postgres
--
CREATE VIEW rpc_alfresco_create_application_code AS
SELECT call_applications.id AS "projectCode"
FROM call_applications;
ALTER TABLE rpc_alfresco_create_application_code OWNER TO postgres;
--
-- Name: alfresco_create_application_code(text); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION alfresco_create_application_code("callCode" text) RETURNS SETOF rpc_alfresco_create_application_code
LANGUAGE plpgsql COST 1
AS $$
DECLARE project_code INTEGER;
DECLARE call_id INTEGER;
BEGIN
SET ROLE postgres;
SELECT calls.id INTO call_id
FROM calls
WHERE calls.call_reference = "callCode";
IF call_id IS NULL THEN
RAISE EXCEPTION 'Call Code Invalid';
END IF;
INSERT INTO call_applications (call) VALUES (call_id)
RETURNING call_applications.id INTO project_code;
RETURN QUERY SELECT * FROM rpc_alfresco_create_application_code
WHERE rpc_alfresco_create_application_code."projectCode" = project_code;
--EXCEPTION WHEN OTHERS THEN /*Catch all*/
--RAISE EXCEPTION 'Something went wrong';
END;$$;
ALTER FUNCTION public.alfresco_create_application_code("callCode" text) OWNER TO postgres;
--
-- Name: organisations_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE organisations_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE organisations_id_seq OWNER TO postgres;
--
-- Name: organisations; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE organisations (
id integer DEFAULT nextval('organisations_id_seq'::regclass) NOT NULL,
code character varying(50),
name character varying(255) NOT NULL,
web_site character varying(255),
vat_no character varying(255),
npo_no character varying(255),
cell_phone character varying(255),
work_phone character varying(255),
email_address character varying(255),
fax_no character varying(255),
street_first_line character varying(255),
street_second_line character varying(255),
postal_first_line character varying(255),
postal_second_line character varying(255),
suburb integer,
place integer,
province integer,
referee integer,
auditor integer,
organisation_type integer,
organisation_status integer,
pts_assocode text,
contact_person character varying(50)
);
ALTER TABLE organisations OWNER TO postgres;
--
-- Name: TABLE organisations; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE organisations IS 'An organisation is an institution that operates in the sector.';
--
-- Name: suburbs_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE suburbs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE suburbs_id_seq OWNER TO postgres;
--
-- Name: suburbs; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE suburbs (
id integer DEFAULT nextval('suburbs_id_seq'::regclass) NOT NULL,
name character varying(255) NOT NULL,
po_box_code character varying(50),
street_code character varying(50),
latitude real,
longitude real,
province integer,
place integer
);
ALTER TABLE suburbs OWNER TO postgres;
--
-- Name: TABLE suburbs; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE suburbs IS 'A suburb is part of a place with a Street and PO Box code, as defined by SAPO.';
--
-- Name: rpc_alfresco_get_organisations; Type: VIEW; Schema: public; Owner: postgres
--
CREATE VIEW rpc_alfresco_get_organisations AS
SELECT organisations.id AS "organisationId",
organisations.code AS "organisationCode",
organisations.name AS "organisationName",
organisations.npo_no AS "organisationNPONumber",
organisations.contact_person AS "organisationContactFullName",
organisations.cell_phone AS "organisationContactCellphoneNumber",
organisations.email_address AS "organisationEmailAddress",
organisations.work_phone AS "organisationTelephoneNumber",
organisations.fax_no AS "organisationFaxNumber",
organisations.street_first_line AS "organisationPhysicalAddressLine1",
organisations.street_second_line AS "organisationPhysicalAddressLine2",
(organisations.suburb)::text AS "organisationPhysicalAddressSuburbCode",
(organisations.place)::text AS "organisationPhysicalAddressCityCode",
(organisations.province)::text AS "organisationPhysicalAddressProvinceCode",
organisations.postal_first_line AS "organisationPostalAddressLine1",
organisations.postal_second_line AS "organisationPostalAddressLine2"
FROM (organisations
LEFT JOIN suburbs ON ((organisations.suburb = suburbs.id)))
ORDER BY organisations.name;
ALTER TABLE rpc_alfresco_get_organisations OWNER TO postgres;
--
-- Name: alfresco_create_organisation(text, text, text, text, text, text, text, text, text, text, text, text, text, text); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION alfresco_create_organisation("organisationName" text, "organisationNPONumber" text DEFAULT NULL::text, "organisationContactFullName" text DEFAULT NULL::text, "organisationContactCellphoneNumber" text DEFAULT NULL::text, "organisationEmailAddress" text DEFAULT NULL::text, "organisationTelephoneNumber" text DEFAULT NULL::text, "organisationFaxNumber" text DEFAULT NULL::text, "organisationPhysicalAddressLine1" text DEFAULT NULL::text, "organisationPhysicalAddressLine2" text DEFAULT NULL::text, "organisationPhysicalAddressSuburbCode" text DEFAULT NULL::text, "organisationPhysicalAddressCityCode" text DEFAULT NULL::text, "organisationPhysicalAddressProvinceCode" text DEFAULT NULL::text, "organisationPostalAddressLine1" text DEFAULT NULL::text, "organisationPostalAddressLine2" text DEFAULT NULL::text) RETURNS SETOF rpc_alfresco_get_organisations
LANGUAGE plpgsql COST 1
AS $$
--#variable_conflict use_variable
DECLARE organisation_id INTEGER;
DECLARE province_id INTEGER;
BEGIN
SET ROLE postgres;
province_id := id from provinces where code = alfresco_create_organisation."organisationPhysicalAddressCityCode";
INSERT INTO organisations(
name,
npo_no,
contact_person,
cell_phone,
email_address,
work_phone,
fax_no,
street_first_line,
street_second_line,
suburb,
place,
province,
postal_first_line,
postal_second_line
) VALUES (
alfresco_create_organisation."organisationName",
alfresco_create_organisation."organisationNPONumber",
alfresco_create_organisation."organisationContactFullName",
alfresco_create_organisation."organisationContactCellphoneNumber",
alfresco_create_organisation."organisationEmailAddress",
alfresco_create_organisation."organisationTelephoneNumber" ,
alfresco_create_organisation."organisationFaxNumber",
alfresco_create_organisation."organisationPhysicalAddressLine1",
alfresco_create_organisation."organisationPhysicalAddressLine2",
alfresco_create_organisation."organisationPhysicalAddressSuburbCode"::int,
alfresco_create_organisation."organisationPhysicalAddressCityCode"::int,
province_id,
alfresco_create_organisation."organisationPostalAddressLine1",
alfresco_create_organisation."organisationPostalAddressLine2"
)
RETURNING organisations.id INTO organisation_id;
RETURN QUERY SELECT * FROM rpc_alfresco_get_organisations
WHERE rpc_alfresco_get_organisations."organisationId" = organisation_id;
--EXCEPTION WHEN OTHERS THEN /*Catch all*/
--RAISE EXCEPTION 'Something went wrong';
END;$$;
ALTER FUNCTION public.alfresco_create_organisation("organisationName" text, "organisationNPONumber" text, "organisationContactFullName" text, "organisationContactCellphoneNumber" text, "organisationEmailAddress" text, "organisationTelephoneNumber" text, "organisationFaxNumber" text, "organisationPhysicalAddressLine1" text, "organisationPhysicalAddressLine2" text, "organisationPhysicalAddressSuburbCode" text, "organisationPhysicalAddressCityCode" text, "organisationPhysicalAddressProvinceCode" text, "organisationPostalAddressLine1" text, "organisationPostalAddressLine2" text) OWNER TO postgres;
--
-- Name: calls_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE calls_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE calls_id_seq OWNER TO postgres;
--
-- Name: calls; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE calls (
id integer DEFAULT nextval('calls_id_seq'::regclass) NOT NULL,
call_reference character varying(50) NOT NULL,
name character varying(255) NOT NULL,
description text,
call_date date,
evaluation_date date,
key_performance_indicator integer,
admin_compliance_template integer,
relevance_compliance_template integer,
assessment_compliance_template integer,
due_diligence_compliance_template integer
);
ALTER TABLE calls OWNER TO postgres;
--
-- Name: TABLE calls; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE calls IS 'A call is a request for project proposals to support a KPI.';
--
-- Name: key_performance_indicators_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE key_performance_indicators_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE key_performance_indicators_id_seq OWNER TO postgres;
--
-- Name: key_performance_indicators; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE key_performance_indicators (
id integer DEFAULT nextval('key_performance_indicators_id_seq'::regclass) NOT NULL,
code character varying(50) NOT NULL,
name character varying(255) NOT NULL,
description text,
reporting_period text,
baseline text,
remarks text,
status text,
key_result_area integer
);
ALTER TABLE key_performance_indicators OWNER TO postgres;
--
-- Name: TABLE key_performance_indicators; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE key_performance_indicators IS 'A key performance indicator (KPI) is a measure of progress in a KRA.';
--
-- Name: key_result_areas_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE key_result_areas_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE key_result_areas_id_seq OWNER TO postgres;
--
-- Name: key_result_areas; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE key_result_areas (
id integer DEFAULT nextval('key_result_areas_id_seq'::regclass) NOT NULL,
code character varying(50) NOT NULL,
name character varying(255) NOT NULL,
description text,
programme integer
);
ALTER TABLE key_result_areas OWNER TO postgres;
--
-- Name: TABLE key_result_areas; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE key_result_areas IS 'A key result area (KRA) is a component of a programme.';
--
-- Name: programmes_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE programmes_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE programmes_id_seq OWNER TO postgres;
--
-- Name: programmes; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE programmes (
id integer DEFAULT nextval('programmes_id_seq'::regclass) NOT NULL,
code character varying(50) NOT NULL,
name character varying(255) NOT NULL,
description text,
start_date date,
end_date date
);
ALTER TABLE programmes OWNER TO postgres;
--
-- Name: TABLE programmes; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE programmes IS 'A programme is a group of projects that have a common outcome.';
--
-- Name: rpc_alfresco_create_application; Type: VIEW; Schema: public; Owner: postgres
--
CREATE VIEW rpc_alfresco_create_application AS
SELECT call_applications.id AS "projectId",
call_applications.id AS "projectCode",
call_applications.title AS "projectTitle",
programmes.id AS "programmeId",
programmes.code AS "programmeCode",
programmes.name AS "programmeName",
calls.id AS "callId",
calls.call_reference AS "callCode",
calls.name AS "callName",
rpc_alfresco_get_organisations."organisationId",
rpc_alfresco_get_organisations."organisationCode",
rpc_alfresco_get_organisations."organisationName",
rpc_alfresco_get_organisations."organisationContactFullName",
rpc_alfresco_get_organisations."organisationContactCellphoneNumber",
rpc_alfresco_get_organisations."organisationEmailAddress",
rpc_alfresco_get_organisations."organisationTelephoneNumber",
rpc_alfresco_get_organisations."organisationFaxNumber",
rpc_alfresco_get_organisations."organisationPhysicalAddressLine1",
rpc_alfresco_get_organisations."organisationPhysicalAddressLine2",
rpc_alfresco_get_organisations."organisationPhysicalAddressProvinceCode",
rpc_alfresco_get_organisations."organisationPhysicalAddressCityCode",
rpc_alfresco_get_organisations."organisationPhysicalAddressSuburbCode",
rpc_alfresco_get_organisations."organisationPostalAddressLine1",
rpc_alfresco_get_organisations."organisationPostalAddressLine2"
FROM (((((call_applications
LEFT JOIN calls ON ((call_applications.call = calls.id)))
LEFT JOIN key_performance_indicators ON ((key_performance_indicators.id = calls.key_performance_indicator)))
LEFT JOIN key_result_areas ON ((key_performance_indicators.key_result_area = key_result_areas.id)))
LEFT JOIN programmes ON ((key_result_areas.programme = programmes.id)))
JOIN rpc_alfresco_get_organisations ON ((call_applications.applicant = rpc_alfresco_get_organisations."organisationId")));
ALTER TABLE rpc_alfresco_create_application OWNER TO postgres;
--
-- Name: alfresco_create_project(text, text, text, text, text); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION alfresco_create_project("projectCode" text DEFAULT NULL::text, "projectTitle" text DEFAULT NULL::text, "callCode" text DEFAULT NULL::text, "organisationCode" text DEFAULT NULL::text, "projectStatusCode" text DEFAULT NULL::text) RETURNS SETOF rpc_alfresco_create_application
LANGUAGE plpgsql COST 1
AS $$
--#variable_conflict use_variable
DECLARE project_code INTEGER;
DECLARE organisation_id INTEGER;
BEGIN
SET ROLE postgres;
SELECT call_applications.id INTO project_code
FROM call_applications
WHERE call_applications.id = alfresco_create_project."projectCode"::int;
organisation_id := id from organisations where code = alfresco_create_project."organisationCode";
IF project_code IS NULL THEN
--RAISE EXCEPTION 'Application does not Exist!';
select alfresco_create_application_code."projectCode"::int into project_code
from alfresco_create_application_code(alfresco_create_project."callCode");
END IF;
UPDATE call_applications
SET (
title,
applicant
) = (
alfresco_create_project."projectTitle",
organisation_id
)
WHERE call_applications.id = project_code;
RETURN QUERY SELECT * FROM rpc_alfresco_create_application
WHERE rpc_alfresco_create_application."projectId" = project_code;
--EXCEPTION WHEN OTHERS THEN /*Catch all*/
--RAISE EXCEPTION 'Something went wrong';
END;$$;
ALTER FUNCTION public.alfresco_create_project("projectCode" text, "projectTitle" text, "callCode" text, "organisationCode" text, "projectStatusCode" text) OWNER TO postgres;
--
-- Name: rpc_alfresco_get_calls; Type: VIEW; Schema: public; Owner: postgres
--
CREATE VIEW rpc_alfresco_get_calls AS
SELECT calls.id AS "callId",
calls.call_reference AS "callCode",
calls.name AS "callName",
key_performance_indicators.id AS "keyPerformanceIndicatorId",
key_performance_indicators.code AS "keyPerformanceIndicatorCode",
key_performance_indicators.name AS "keyPerformanceIndicatorName",
key_result_areas.id AS "keyResultAreaId",
key_result_areas.code AS "keyResultAreaCode",
key_result_areas.name AS "keyResultAreaName",
programmes.id AS "programmeId",
programmes.code AS "programmeCode",
programmes.name AS "programmeName"
FROM (((calls
LEFT JOIN key_performance_indicators ON ((calls.key_performance_indicator = key_performance_indicators.id)))
LEFT JOIN key_result_areas ON ((key_result_areas.id = key_performance_indicators.key_result_area)))
LEFT JOIN programmes ON ((key_result_areas.programme = programmes.id)));
ALTER TABLE rpc_alfresco_get_calls OWNER TO postgres;
--
-- Name: alfresco_get_calls(integer, text, integer, text); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION alfresco_get_calls("callId" integer DEFAULT NULL::integer, "callCode" text DEFAULT NULL::text, "programmeId" integer DEFAULT NULL::integer, "programmeCode" text DEFAULT NULL::text) RETURNS SETOF rpc_alfresco_get_calls
LANGUAGE plpgsql COST 1 ROWS 50
AS $$
--#variable_conflict use_variable
BEGIN
SET ROLE postgres;
RETURN QUERY SELECT * FROM rpc_alfresco_get_calls
WHERE
rpc_alfresco_get_calls."callId" = COALESCE(alfresco_get_calls."callId",rpc_alfresco_get_calls."callId")
AND rpc_alfresco_get_calls."callCode" = COALESCE(alfresco_get_calls."callCode",rpc_alfresco_get_calls."callCode")
AND rpc_alfresco_get_calls."programmeId" = COALESCE(alfresco_get_calls."programmeId",rpc_alfresco_get_calls."programmeId")
AND rpc_alfresco_get_calls."programmeCode" = COALESCE(alfresco_get_calls."programmeCode",rpc_alfresco_get_calls."programmeCode")
ORDER BY rpc_alfresco_get_calls."callId";
--EXCEPTION WHEN OTHERS THEN
--RAISE EXCEPTION 'Something went wrong';
END;
$$;
ALTER FUNCTION public.alfresco_get_calls("callId" integer, "callCode" text, "programmeId" integer, "programmeCode" text) OWNER TO postgres;
--
-- Name: places_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE places_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE places_id_seq OWNER TO postgres;
--
-- Name: places; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE places (
id integer DEFAULT nextval('places_id_seq'::regclass) NOT NULL,
name character varying(255) NOT NULL,
province integer
);
ALTER TABLE places OWNER TO postgres;
--
-- Name: TABLE places; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE places IS 'A place is a city or town, as defined by SAPO.';
--
-- Name: provinces_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE provinces_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE provinces_id_seq OWNER TO postgres;
--
-- Name: provinces; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE provinces (
id integer DEFAULT nextval('provinces_id_seq'::regclass) NOT NULL,
code character varying(50) NOT NULL,
name character varying(255) NOT NULL
);
ALTER TABLE provinces OWNER TO postgres;
--
-- Name: TABLE provinces; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE provinces IS 'A province is one of the 9 provinces in the country.';
--
-- Name: rpc_alfresco_get_places; Type: VIEW; Schema: public; Owner: postgres
--
CREATE VIEW rpc_alfresco_get_places AS
SELECT places.id AS "placesId",
places.name AS "placesName",
provinces.id AS "provinceId",
provinces.code AS "provinceCode",
provinces.name AS "provinceName"
FROM (places
JOIN provinces ON ((places.province = provinces.id)))
ORDER BY places.name;
ALTER TABLE rpc_alfresco_get_places OWNER TO postgres;
--
-- Name: rpc_alfresco_get_cities; Type: VIEW; Schema: public; Owner: postgres
--
CREATE VIEW rpc_alfresco_get_cities AS
SELECT rpc_alfresco_get_places."placesId" AS "cityId",
(rpc_alfresco_get_places."placesId")::text AS "cityCode",
rpc_alfresco_get_places."placesName" AS "cityName",
rpc_alfresco_get_places."provinceId",
rpc_alfresco_get_places."provinceCode",
rpc_alfresco_get_places."provinceName"
FROM rpc_alfresco_get_places
ORDER BY rpc_alfresco_get_places."placesName";
ALTER TABLE rpc_alfresco_get_cities OWNER TO postgres;
--
-- Name: alfresco_get_cities(integer, text); Type: FUNCTION; Schema: public; Owner: postgres
--