-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprod_views.sql
More file actions
3506 lines (3290 loc) · 116 KB
/
prod_views.sql
File metadata and controls
3506 lines (3290 loc) · 116 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
--======================================================================
/*
Name: prod_views
Parameters: none
Returns:
Author: G. Cattabriga
Date: 2020.01.23
Description: create the production views for ESCALATE v3
Notes:
*/
--======================================================================
--=====================================
-- VIEWS
--=====================================
----------------------------------------
-- view of sys_audit tables trigger on
----------------------------------------
CREATE OR REPLACE VIEW sys_audit_tableslist AS SELECT DISTINCT
trigger_schema AS SCHEMA,
event_object_table AS auditedtable
FROM
information_schema.triggers
WHERE
trigger_name::text IN(
'audit_trigger_row' ::text, 'audit_trigger_stm' ::text)
ORDER BY
auditedtable;
----------------------------------------
-- view of status table (simple)
----------------------------------------
CREATE OR REPLACE VIEW vw_status AS
SELECT
status_uuid,
description,
add_date,
mod_date
FROM
status;
DROP TRIGGER IF EXISTS trigger_status_upsert ON vw_status;
CREATE TRIGGER trigger_status_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_status
FOR EACH ROW
EXECUTE PROCEDURE upsert_status ();
----------------------------------------
-- view of type_def table
----------------------------------------
CREATE OR REPLACE VIEW vw_type_def AS
SELECT
type_def_uuid,
category,
description,
add_date,
mod_date
FROM
type_def;
DROP TRIGGER IF EXISTS trigger_type_def_upsert ON vw_type_def;
CREATE TRIGGER trigger_type_def_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_type_def
FOR EACH ROW
EXECUTE PROCEDURE upsert_type_def ();
----------------------------------------
-- view of note; links to edocument and actor
----------------------------------------
CREATE OR REPLACE VIEW vw_edocument AS
SELECT
doc.edocument_uuid,
doc.title,
doc.description,
doc.filename,
doc.source,
doc.edocument,
doc.doc_type_uuid,
td.description as doc_type_description,
doc.doc_ver,
act.actor_uuid,
act.description AS actor_description,
doc.status_uuid,
sts.description as status_description,
doc.add_date,
doc.mod_date,
docx.edocument_x_uuid,
docx.ref_edocument_uuid
FROM
edocument doc
LEFT JOIN edocument_x docx on docx.edocument_uuid = doc.edocument_uuid
LEFT JOIN actor act ON doc.actor_uuid = act.actor_uuid
LEFT JOIN status sts ON doc.status_uuid = sts.status_uuid
LEFT JOIN type_def td ON doc.doc_type_uuid = td.type_def_uuid;
DROP TRIGGER IF EXISTS trigger_edocument_upsert ON vw_edocument;
CREATE TRIGGER trigger_edocument_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_edocument
FOR EACH ROW
EXECUTE PROCEDURE upsert_edocument ( );
----------------------------------------
-- view of note; links to edocument and actor
----------------------------------------
CREATE OR REPLACE VIEW vw_note AS
SELECT
nt.note_uuid,
nt.notetext,
act.actor_uuid,
act.description AS actor_description,
nt.add_date,
nt.mod_date,
nx.note_x_uuid,
nx.ref_note_uuid
FROM
note nt
LEFT JOIN actor act ON nt.actor_uuid = act.actor_uuid
JOIN note_x nx ON nx.note_uuid = nt.note_uuid;
DROP TRIGGER IF EXISTS trigger_note_upsert ON vw_note;
CREATE TRIGGER trigger_note_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_note
FOR EACH ROW
EXECUTE PROCEDURE upsert_note ();
----------------------------------------
-- view of tag_type
----------------------------------------
CREATE OR REPLACE VIEW vw_tag_type AS
SELECT
tt.tag_type_uuid,
tt.type,
tt.description,
tt.add_date,
tt.mod_date
FROM
tag_type tt;
DROP TRIGGER IF EXISTS trigger_tag_type_upsert ON vw_tag_type;
CREATE TRIGGER trigger_tag_type_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_tag_type
FOR EACH ROW
EXECUTE PROCEDURE upsert_tag_type ();
----------------------------------------
-- view of tag; links to tag_type, actor and note
----------------------------------------
CREATE OR REPLACE VIEW vw_tag AS
SELECT
tg.tag_uuid,
tg.display_text,
tg.description,
tg.actor_uuid,
act.description AS actor_description,
tg.add_date,
tg.mod_date,
tg.tag_type_uuid,
tt.type,
tt.description AS type_description
FROM
tag tg
LEFT JOIN tag_type tt ON tg.tag_type_uuid = tt.tag_type_uuid
LEFT JOIN actor act ON tg.actor_uuid = act.actor_uuid;
DROP TRIGGER IF EXISTS trigger_tag_upsert ON vw_tag;
CREATE TRIGGER trigger_tag_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_tag
FOR EACH ROW
EXECUTE PROCEDURE upsert_tag ( );
----------------------------------------
-- view of tag_x; links to tag_type, actor and note
----------------------------------------
CREATE OR REPLACE VIEW vw_tag_assign AS
SELECT
tx.tag_x_uuid,
tx.ref_tag_uuid,
tx.tag_uuid,
tg.display_text,
tt.type,
tx.add_date,
tx.mod_date
FROM
tag_x tx
LEFT JOIN tag tg ON tx.tag_uuid = tg.tag_uuid
LEFT JOIN tag_type tt ON tg.tag_type_uuid = tt.tag_type_uuid;
DROP TRIGGER IF EXISTS trigger_tag_assign_upsert ON vw_tag_assign;
CREATE TRIGGER trigger_tag_assign_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_tag_assign
FOR EACH ROW
EXECUTE PROCEDURE upsert_tag_assign ();
----------------------------------------
-- integrated view of udf_def
----------------------------------------
CREATE OR REPLACE VIEW vw_udf_def AS
SELECT
ud.udf_def_uuid,
ud.description,
ud.val_type_uuid,
td.category as val_type_category,
td.description as val_type_description,
ud.unit,
ud.add_date,
ud.mod_date,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
udf_def ud
LEFT JOIN type_def td on ud.val_type_uuid = td.type_def_uuid
LEFT JOIN LATERAL (select * from tag_to_array (udf_def_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (udf_def_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_udf_def_upsert ON vw_udf_def;
CREATE TRIGGER trigger_udf_def_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_udf_def
FOR EACH ROW
EXECUTE PROCEDURE upsert_udf_def ( );
----------------------------------------
-- view of udf
----------------------------------------
CREATE OR REPLACE VIEW vw_udf AS
SELECT
ud.udf_uuid,
ud.udf_def_uuid,
udef.description,
ud.udf_val,
( ud.udf_val ).v_type_uuid AS udf_val_type_uuid,
(select val_val from get_val ( ud.udf_val )) AS udf_val_val,
( ud.udf_val ).v_unit AS udf_val_unit,
( ud.udf_val ).v_edocument_uuid AS udf_val_edocument_uuid,
ud.add_date,
ud.mod_date,
udx.udf_x_uuid,
udx.ref_udf_uuid,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
udf ud
LEFT JOIN udf_x udx on ud.udf_uuid = udx.udf_uuid
LEFT JOIN udf_def udef on ud.udf_def_uuid = udef.udf_def_uuid
LEFT JOIN type_def td on udef.val_type_uuid = td.type_def_uuid
LEFT JOIN LATERAL (select * from tag_to_array (ud.udf_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (ud.udf_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_udf_upsert ON vw_udf;
CREATE TRIGGER trigger_udf_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_udf
FOR EACH ROW
EXECUTE PROCEDURE upsert_udf ( );
----------------------------------------
-- view of person; links to organization and note
----------------------------------------
CREATE OR REPLACE VIEW vw_person AS
SELECT
per.person_uuid,
per.first_name,
per.last_name,
per.middle_name,
per.address1,
per.address2,
per.city,
per.state_province,
per.zip,
per.country,
per.phone,
per.email,
per.title,
per.suffix,
per.add_date,
per.mod_date,
org.organization_uuid,
org.full_name AS organization_full_name,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
person per
LEFT JOIN organization org ON per.organization_uuid = org.organization_uuid
LEFT JOIN LATERAL (select * from tag_to_array (person_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (person_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_person_upsert ON vw_person;
CREATE TRIGGER trigger_person_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_person
FOR EACH ROW
EXECUTE PROCEDURE upsert_person ( );
----------------------------------------
-- view of organization; links to parent organization and note
----------------------------------------
CREATE OR REPLACE VIEW vw_organization AS
SELECT
org.organization_uuid,
org.description,
org.full_name,
org.short_name,
org.address1,
org.address2,
org.city,
org.state_province,
org.zip,
org.country,
org.website_url,
org.phone,
org.parent_uuid,
orgp.full_name AS parent_org_full_name,
org.add_date,
org.mod_date,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
organization org
LEFT JOIN organization orgp ON org.parent_uuid = orgp.organization_uuid
LEFT JOIN LATERAL (select * from tag_to_array (org.organization_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (org.organization_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_organization_upsert ON vw_organization;
CREATE TRIGGER trigger_organization_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_organization
FOR EACH ROW
EXECUTE PROCEDURE upsert_organization ( );
----------------------------------------
-- view of actor
----------------------------------------
CREATE OR REPLACE VIEW vw_actor AS
SELECT
act.actor_uuid AS actor_uuid,
org.organization_uuid,
per.person_uuid,
st.systemtool_uuid,
act.description,
sts.status_uuid,
sts.description as status_description,
act.add_date,
act.mod_date,
org.full_name AS org_full_name,
org.short_name AS org_short_name,
per.last_name AS person_last_name,
per.first_name AS person_first_name,
CASE WHEN per.person_uuid IS NOT NULL THEN
CAST(
concat(per.last_name, ', ', per.first_name ) AS VARCHAR )
END AS person_last_first,
porg.full_name AS person_org,
porg.organization_uuid as person_organization_uuid,
porg.description as person_organization_description,
st.systemtool_name,
st.description AS systemtool_description,
stt.description AS systemtool_type,
vorg.full_name AS systemtool_vendor,
st.model AS systemtool_model,
st.serial AS systemtool_serial,
st.ver AS systemtool_version,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
actor act
LEFT JOIN organization org ON act.organization_uuid = org.organization_uuid
LEFT JOIN person per ON act.person_uuid = per.person_uuid
LEFT JOIN organization porg ON per.organization_uuid = porg.organization_uuid
LEFT JOIN systemtool st ON act.systemtool_uuid = st.systemtool_uuid
LEFT JOIN systemtool_type stt ON st.systemtool_type_uuid = stt.systemtool_type_uuid
LEFT JOIN organization vorg ON st.vendor_organization_uuid = vorg.organization_uuid
LEFT JOIN status sts ON act.status_uuid = sts.status_uuid
LEFT JOIN LATERAL (select * from tag_to_array (actor_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (actor_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_actor_upsert ON vw_actor;
CREATE TRIGGER trigger_actor_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_actor
FOR EACH ROW
EXECUTE PROCEDURE upsert_actor ( );
----------------------------------------
-- integrated view of actor_pref
----------------------------------------
CREATE OR REPLACE VIEW vw_actor_pref AS
SELECT
ap.actor_pref_uuid,
ap.actor_uuid,
ap.pkey,
ap.pvalue,
ap.add_date,
ap.mod_date
FROM
actor_pref ap;
DROP TRIGGER IF EXISTS trigger_actor_pref_upsert ON vw_actor_pref;
CREATE TRIGGER trigger_actor_pref_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_actor_pref
FOR EACH ROW
EXECUTE PROCEDURE upsert_actor_pref ( );
----------------------------------------
-- integrated view of systemtool_type
----------------------------------------
CREATE OR REPLACE VIEW vw_systemtool_type AS
SELECT
stt.systemtool_type_uuid,
stt.description,
stt.add_date,
stt.mod_date
FROM
systemtool_type stt;
DROP TRIGGER IF EXISTS trigger_systemtool_type_upsert ON vw_systemtool_type;
CREATE TRIGGER trigger_systemtool_type_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_systemtool_type
FOR EACH ROW
EXECUTE PROCEDURE upsert_systemtool_type ( );
----------------------------------------
-- get most recent version of a systemtool in raw format
-- return all columns from the systemtool table
----------------------------------------
CREATE OR REPLACE VIEW vw_systemtool_raw AS
SELECT
stl.*
FROM
systemtool stl
JOIN (
SELECT
st.systemtool_name,
-- st.systemtool_type_uuid,
-- st.vendor_organization_uuid,
MAX(st.ver) AS ver
FROM
systemtool st
-- WHERE
-- st.systemtool_name IS NOT NULL
-- AND st.ver IS NOT NULL
GROUP BY
st.systemtool_name
-- st.systemtool_type_uuid,
-- st.vendor_organization_uuid,
-- st.note_uuid
) mrs ON stl.systemtool_name = mrs.systemtool_name and stl.ver = mrs.ver;
-- AND stl.systemtool_type_uuid = mrs.systemtool_type_uuid
-- AND stl.vendor_organization_uuid = mrs.vendor_organization_uuid
-- AND stl.ver = mrs.ver;
----------------------------------------
-- get most recent version of a systemtool
-- return all columns from actor table
----------------------------------------
CREATE OR REPLACE VIEW vw_systemtool AS
SELECT
vst.systemtool_uuid,
vst.systemtool_name,
vst.description,
vst.vendor_organization_uuid,
org.full_name organization_fullname,
vst.systemtool_type_uuid,
stt.description AS systemtool_type_description,
vst.model,
vst.serial,
vst.ver,
vst.add_date,
vst.mod_date,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
systemtool vst
LEFT JOIN organization org ON vst.vendor_organization_uuid = org.organization_uuid
LEFT JOIN systemtool_type stt ON vst.systemtool_type_uuid = stt.systemtool_type_uuid
LEFT JOIN LATERAL (select * from tag_to_array (systemtool_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (systemtool_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_systemtool_upsert ON vw_systemtool;
CREATE TRIGGER trigger_systemtool_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_systemtool
FOR EACH ROW
EXECUTE PROCEDURE upsert_systemtool ( );
----------------------------------------
-- view measure_type
-- DROP VIEW vw_measure_type cascade
----------------------------------------
CREATE OR REPLACE VIEW vw_measure_type AS
SELECT
mt.measure_type_uuid,
mt.description,
mt.actor_uuid,
act.description as actor_description,
mt.status_uuid,
st.description as status_description,
mt.add_date,
mt.mod_date
FROM
measure_type mt
LEFT JOIN actor act ON mt.actor_uuid = act.actor_uuid
LEFT JOIN status st ON mt.status_uuid = st.status_uuid;
DROP TRIGGER IF EXISTS trigger_measure_type_upsert ON vw_measure_type;
CREATE TRIGGER trigger_measure_type_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_measure_type
FOR EACH ROW
EXECUTE PROCEDURE upsert_measure_type ( );
----------------------------------------
-- view measure_def
-- DROP VIEW vw_measure_def cascade
----------------------------------------
CREATE OR REPLACE VIEW vw_measure_def AS
SELECT
md.measure_def_uuid,
md.default_measure_type_uuid,
md.description,
md.default_measure_value,
( md.default_measure_value ).v_type_uuid AS default_measure_value_type_uuid,
(select val_val from get_val ( md.default_measure_value )) AS default_measure_value_value,
( md.default_measure_value ).v_unit AS default_measure_value_unit,
md.property_def_uuid,
pd.description as property_def_description,
pd.short_description as property_def_short_description,
md.actor_uuid,
act.description as actor_description,
md.status_uuid,
st.description as status_description,
md.add_date,
md.mod_date,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
measure_def md
LEFT JOIN property_def pd ON md.property_def_uuid = pd.property_def_uuid
LEFT JOIN actor act ON md.actor_uuid = act.actor_uuid
LEFT JOIN status st ON md.status_uuid = st.status_uuid
LEFT JOIN LATERAL (select * from tag_to_array (measure_def_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (measure_def_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_measure_def_upsert ON vw_measure_def;
CREATE TRIGGER trigger_measure_def_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_measure_def
FOR EACH ROW
EXECUTE PROCEDURE upsert_measure_def ( );
----------------------------------------
-- view measure
-- DROP VIEW vw_measure cascade
----------------------------------------
CREATE OR REPLACE VIEW vw_measure AS
SELECT
m.measure_uuid,
m.measure_def_uuid,
md.description as measure_def_description,
m.measure_type_uuid,
mt.description as measure_type_description,
mx.ref_measure_uuid,
m.description,
m.measure_value,
( m.measure_value ).v_type_uuid AS measure_value_type_uuid,
td.description as measure_value_type_description,
(select val_val from get_val ( m.measure_value )) AS measure_value_value,
( m.measure_value ).v_unit AS measure_value_unit,
m.actor_uuid,
act.description as actor_description,
m.status_uuid,
st.description as status_description,
m.add_date,
m.mod_date,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
measure m
LEFT JOIN measure_def md ON m.measure_def_uuid = md.measure_def_uuid
LEFT JOIN measure_x mx ON m.measure_uuid = mx.measure_uuid
LEFT JOIN measure_type mt ON m.measure_type_uuid = mt.measure_type_uuid
LEFT JOIN type_def td ON ( m.measure_value ).v_type_uuid = td.type_def_uuid
LEFT JOIN actor act ON m.actor_uuid = act.actor_uuid
LEFT JOIN status st ON m.status_uuid = st.status_uuid
LEFT JOIN LATERAL (select * from tag_to_array (m.measure_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (m.measure_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_measure_upsert ON vw_measure;
CREATE TRIGGER trigger_measure_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_measure
FOR EACH ROW
EXECUTE PROCEDURE upsert_measure ( );
----------------------------------------
-- view experiment
-- DROP VIEW vw_experiment cascade
----------------------------------------
CREATE OR REPLACE VIEW vw_experiment AS
SELECT
ex.experiment_uuid,
ex.experiment_type_uuid,
et.description as experiment_type,
ex.ref_uid,
ex.description,
ex.parent_uuid,
exp.description as parent_description,
ex.parent_path,
ex.owner_uuid,
aown.description as owner_description,
ex.operator_uuid,
aop.description as operator_description,
ex.lab_uuid,
alab.description as lab_description,
ex.status_uuid,
st.description as status_description,
ex.add_date,
ex.mod_date,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM experiment ex
LEFT JOIN experiment_type et ON ex.experiment_type_uuid = et.experiment_type_uuid
LEFT JOIN experiment exp ON ex.parent_uuid = exp.experiment_uuid
LEFT JOIN actor aown ON ex.owner_uuid = aown.actor_uuid
LEFT JOIN actor aop ON ex.owner_uuid = aop.actor_uuid
LEFT JOIN actor alab ON ex.owner_uuid = alab.actor_uuid
LEFT JOIN status st ON ex.status_uuid = st.status_uuid
LEFT JOIN LATERAL (select * from tag_to_array (ex.experiment_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (ex.experiment_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_experiment_upsert ON vw_experiment;
CREATE TRIGGER trigger_experiment_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_experiment
FOR EACH ROW
EXECUTE PROCEDURE upsert_experiment ( );
----------------------------------------
-- view experiment_type
-- DROP VIEW vw_experiment_type cascade
----------------------------------------
CREATE OR REPLACE VIEW vw_experiment_type AS
SELECT
et.experiment_type_uuid,
et.description,
et.actor_uuid,
act.description as actor_description,
et.status_uuid,
st.description as status_description,
et.add_date,
et.mod_date,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM experiment_type et
LEFT JOIN actor act ON et.actor_uuid = act.actor_uuid
LEFT JOIN status st ON et.status_uuid = st.status_uuid
LEFT JOIN LATERAL (select * from tag_to_array (experiment_type_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (experiment_type_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_experiment_type_upsert ON vw_experiment_type;
CREATE TRIGGER trigger_experiment_type_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_experiment_type
FOR EACH ROW
EXECUTE PROCEDURE upsert_experiment_type ( );
----------------------------------------
-- view workflow_type
-- DROP VIEW vw_workflow_type
----------------------------------------
CREATE OR REPLACE VIEW vw_workflow_type AS
SELECT
wt.workflow_type_uuid,
wt.description,
wt.add_date,
wt.mod_date
FROM
workflow_type wt
ORDER BY
2;
DROP TRIGGER IF EXISTS trigger_workflow_type_upsert ON vw_workflow_type;
CREATE TRIGGER trigger_workflow_type_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_workflow_type
FOR EACH ROW
EXECUTE PROCEDURE upsert_workflow_type ( );
----------------------------------------
-- view workflow
-- DROP VIEW vw_workflow
----------------------------------------
CREATE OR REPLACE VIEW vw_workflow AS
SELECT
wf.workflow_uuid,
wf.description,
wf.parent_uuid,
wf.workflow_type_uuid,
wt.description as workflow_type_description,
wf.actor_uuid,
act.description as actor_description,
wf.status_uuid,
st.description as status_description,
wf.add_date,
wf.mod_date,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
workflow wf
LEFT JOIN workflow_type wt ON wf.workflow_type_uuid = wt.workflow_type_uuid
LEFT JOIN actor act ON wf.actor_uuid = act.actor_uuid
LEFT JOIN status st ON wf.status_uuid = st.status_uuid
LEFT JOIN LATERAL (select * from tag_to_array (workflow_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (workflow_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_workflow_upsert ON vw_workflow;
CREATE TRIGGER trigger_workflow_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_workflow
FOR EACH ROW
EXECUTE PROCEDURE upsert_workflow ( );
----------------------------------------
-- view experiment_workflow
-- DROP VIEW vw_experiment_workflow cascade
----------------------------------------
CREATE OR REPLACE VIEW vw_experiment_workflow AS
SELECT
ew.experiment_workflow_uuid,
e.experiment_uuid,
e.ref_uid as experiment_ref_uid,
e.description as experiment_description,
e.parent_uuid as experiment_parent_uuid,
e.owner_uuid as experiment_owner_uuid,
e.owner_description as experiment_owner_description,
e.operator_uuid as experiment_operator_uuid,
e.operator_description as experiment_operator_description,
e.lab_uuid as experiment_lab_uuid,
e.lab_description as experiment_lab_description,
e.status_uuid as experiment_status_uuid,
e.status_description as experiment_status_description,
e.add_date as experiment_add_date,
e.mod_date as experiment_mod_date,
e.tags as experiment_tags,
e.notes as experiment_notes,
ew.experiment_workflow_seq,
w.workflow_uuid as workflow_uuid,
w.description as workflow_description,
w.workflow_type_uuid,
w.workflow_type_description,
w.actor_uuid as workflow_actor_uuid,
w.actor_description as workflow_actor_description,
w.status_uuid as workflow_status_uuid,
w.status_description as workflow_status_description,
w.add_date as workflow_add_date,
w.mod_date as workflow_mod_date,
w.tags as workflow_tags,
w.notes as workflow_notes
FROM experiment_workflow ew
LEFT JOIN vw_experiment e ON ew.experiment_uuid = e.experiment_uuid
LEFT JOIN vw_workflow w ON ew.workflow_uuid = w.workflow_uuid;
DROP TRIGGER IF EXISTS trigger_experiment_workflow_upsert ON vw_experiment_workflow;
CREATE TRIGGER trigger_experiment_workflow_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_experiment_workflow
FOR EACH ROW
EXECUTE PROCEDURE upsert_experiment_workflow ( );
----------------------------------------
-- view outcome
-- DROP VIEW vw_outcome cascade
----------------------------------------
CREATE OR REPLACE VIEW vw_outcome AS
SELECT
o.outcome_uuid,
o.description,
o.experiment_uuid,
o.actor_uuid,
act.description as actor_description,
o.status_uuid,
st.description AS status_description,
o.add_date,
o.mod_date,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
outcome o
LEFT JOIN vw_experiment exp ON o.experiment_uuid = exp.experiment_uuid
LEFT JOIN vw_actor act ON o.actor_uuid = act.actor_uuid
LEFT JOIN status st ON o.status_uuid = st.status_uuid
LEFT JOIN LATERAL (select * from tag_to_array (outcome_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (outcome_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_outcome_upsert ON vw_outcome;
CREATE TRIGGER trigger_outcome_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_outcome
FOR EACH ROW
EXECUTE PROCEDURE upsert_outcome ( );
----------------------------------------
-- view outcome_measure
-- DROP VIEW vw_outcome cascade
----------------------------------------
CREATE OR REPLACE VIEW vw_outcome_measure AS
SELECT
o.outcome_uuid,
o.description,
o.experiment_uuid,
exp.description as experiment_description,
o.actor_uuid,
act.description as outcome_actor_description,
o.status_uuid,
st.description AS outcome_status_description,
o.add_date as outcome_add_date,
o.mod_date as outcome_mod_date,
o.tags as outcome_tags,
o.notes as outcome_notes,
m.measure_uuid,
m.description as measure_description,
m.measure_type_uuid,
m.measure_type_description,
m.measure_value,
m.measure_value_type_uuid,
m.measure_value_type_description,
m.measure_value_value,
m.measure_value_unit,
m.actor_uuid as measure_actor_uuid,
actm.description as measure_actor_description,
m.status_uuid as measure_status_uuid,
stm.description AS measure_status_description,
m.add_date as measure_add_date,
m.mod_date as measure_mod_date,
m.tags as measure_tags,
m.notes as measure_notes
FROM
vw_outcome o
LEFT JOIN vw_measure m ON o.outcome_uuid = m.ref_measure_uuid
LEFT JOIN vw_experiment exp ON o.experiment_uuid = exp.experiment_uuid
LEFT JOIN vw_actor act ON o.actor_uuid = act.actor_uuid
LEFT JOIN vw_actor actm ON m.actor_uuid = actm.actor_uuid
LEFT JOIN vw_status st ON o.status_uuid = st.status_uuid
LEFT JOIN vw_status stm ON m.status_uuid = stm.status_uuid;
----------------------------------------
-- get the calculation_def and associated actor
----------------------------------------
CREATE OR REPLACE VIEW vw_calculation_def AS
SELECT
cd.calculation_def_uuid,
cd.short_name,
cd.calc_definition,
cd.description,
cd.in_source_uuid,
cd.in_type_uuid,
tdi.description as in_type_description,
cd.in_opt_source_uuid,
cd.in_opt_type_uuid,
tdio.description as in_opt_type_description,
cd.out_type_uuid,
cd.out_unit,
tdo.description as out_type_description,
cd.systemtool_uuid,
st.systemtool_name,
stt.description AS systemtool_type_description,
org.short_name AS systemtool_vendor_organization,
st.ver AS systemtool_version,
cd.actor_uuid AS actor_uuid,
act.description AS actor_description,
sts.status_uuid as status_uuid,
sts.description as status_description,
cd.calculation_class_uuid,
cd.add_date,
cd.mod_date,
atag.tag_to_array AS tags,
anote.note_to_array AS notes
FROM
calculation_def cd
LEFT JOIN vw_actor act ON cd.actor_uuid = act.actor_uuid
LEFT JOIN vw_systemtool st ON cd.systemtool_uuid = st.systemtool_uuid
LEFT JOIN vw_type_def tdi ON cd.in_type_uuid = tdi.type_def_uuid
LEFT JOIN vw_type_def tdio ON cd.in_opt_type_uuid = tdio.type_def_uuid
LEFT JOIN vw_type_def tdo ON cd.out_type_uuid = tdo.type_def_uuid
LEFT JOIN systemtool_type stt ON st.systemtool_type_uuid = stt.systemtool_type_uuid
LEFT JOIN organization org ON st.vendor_organization_uuid = org.organization_uuid
LEFT JOIN status sts ON cd.status_uuid = sts.status_uuid
LEFT JOIN LATERAL (select * from tag_to_array (calculation_def_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (calculation_def_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_calculation_def_upsert ON vw_calculation_def;
CREATE TRIGGER trigger_calculation_def_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_calculation_def
FOR EACH ROW
EXECUTE PROCEDURE upsert_calculation_def ( );
----------------------------------------
-- get the calculations and associated entities
-- DROP VIEW vw_calculation;
----------------------------------------
CREATE OR REPLACE VIEW vw_calculation AS
SELECT
md.calculation_uuid,
md.in_val,
( md.in_val ).v_type_uuid AS in_val_type_uuid,
(select val_val from get_val ( md.in_val )) AS in_val_value,
( md.in_val ).v_unit AS in_val_unit,
( md.in_val ).v_edocument_uuid AS in_val_edocument_uuid,
md.in_opt_val,
( md.in_opt_val ).v_type_uuid AS in_opt_val_type_uuid,
(select val_val from get_val ( md.in_opt_val )) AS in_opt_val_value,
( md.in_opt_val ).v_unit AS in_opt_val_unit,
( md.in_opt_val ).v_edocument_uuid AS in_opt_val_edocument_uuid,
md.out_val,
( md.out_val ).v_type_uuid AS out_val_type_uuid,
(select val_val from get_val ( md.out_val )) AS out_val_value,
( md.out_val ).v_unit AS out_val_unit,
( md.out_val ).v_edocument_uuid AS out_val_edocument_uuid,
md.calculation_alias_name,
md.add_date as calculation_add_date,
md.mod_date as calculation_mod_date,
md.actor_uuid as calculation_actor_uuid,
dact.description as calculation_actor_description,
sts.status_uuid AS calculation_status_uuid,
sts.description AS calculation_status_description,
atag.tag_to_array AS calculation_tags,
anote.note_to_array AS calculation_notes,
cd.*
FROM
calculation md
LEFT JOIN vw_calculation_def cd ON md.calculation_def_uuid = cd.calculation_def_uuid
LEFT JOIN vw_edocument ed ON (
md.out_val ).v_edocument_uuid = ed.edocument_uuid
LEFT JOIN actor dact ON md.actor_uuid = dact.actor_uuid
LEFT JOIN status sts ON md.status_uuid = sts.status_uuid
LEFT JOIN LATERAL (select * from tag_to_array (calculation_uuid)) atag ON true
LEFT JOIN LATERAL (select * from note_to_array (calculation_uuid)) anote ON true;
DROP TRIGGER IF EXISTS trigger_calculation_upsert ON vw_calculation;
CREATE TRIGGER trigger_calculation_upsert INSTEAD OF INSERT
OR UPDATE
OR DELETE ON vw_calculation
FOR EACH ROW
EXECUTE PROCEDURE upsert_calculation ( );
----------------------------------------
-- get material_refname_def
-- DROP VIEW vw_material_refname_def
----------------------------------------
CREATE OR REPLACE VIEW vw_material_refname_def AS
SELECT
mrt.material_refname_def_uuid,
mrt.description,
mrt.add_date,
mrt.mod_date
FROM
material_refname_def mrt
ORDER BY