-
Notifications
You must be signed in to change notification settings - Fork 0
/
freshports.org.sql
13374 lines (9525 loc) · 335 KB
/
freshports.org.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
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 12.2
-- Dumped by pg_dump version 12.2
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'SQL_ASCII';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: session_variables; Type: SCHEMA; Schema: -; Owner: dan
--
CREATE SCHEMA session_variables;
ALTER SCHEMA session_variables OWNER TO dan;
--
-- Name: plperl; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: dan
--
CREATE OR REPLACE PROCEDURAL LANGUAGE plperl;
ALTER PROCEDURAL LANGUAGE plperl OWNER TO dan;
--
-- Name: LANGUAGE plperl; Type: COMMENT; Schema: -; Owner: dan
--
COMMENT ON LANGUAGE plperl IS 'PL/Perl procedural language';
--
-- Name: also_watched_record; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.also_watched_record AS (
element_id integer,
url text
);
ALTER TYPE public.also_watched_record OWNER TO dan;
--
-- Name: commit_record; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.commit_record AS (
commit_log_id integer,
commit_date_raw timestamp with time zone,
message_subject text,
message_id text,
committer text,
commit_description text,
commit_date text,
commit_time text,
encoding_losses boolean,
port_id integer,
needs_refresh smallint,
forbidden text,
broken text,
deprecated text,
ignore text,
element_id integer,
version text,
revision text,
epoch text,
date_added integer,
short_description text,
category_id integer,
port text,
status character(1),
category text,
vulnerable_current integer,
vulnerable_past integer,
restricted text,
no_cdrom text,
expiration_date date,
is_interactive text,
only_for_archs text,
not_for_archs text,
repo_name text,
svn_revision text,
svn_hostname text,
path_to_repo text,
watch bigint,
element_pathname text
);
ALTER TYPE public.commit_record OWNER TO dan;
--
-- Name: conflicts; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.conflicts AS ENUM (
'conflicts',
'conflicts_build',
'conflicts_install'
);
ALTER TYPE public.conflicts OWNER TO dan;
--
-- Name: element_id_pathname; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.element_id_pathname AS (
element_id integer,
pathname text
);
ALTER TYPE public.element_id_pathname OWNER TO dan;
--
-- Name: element_type; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.element_type AS (
id integer,
name text,
type text,
status text,
iscategory boolean,
isport boolean,
element_pathname text
);
ALTER TYPE public.element_type OWNER TO dan;
--
-- Name: freshports_commit_record; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.freshports_commit_record AS (
port_id integer,
short_description text,
date_added timestamp with time zone,
needs_refresh smallint,
category text,
category_id integer,
message_id text,
committer text,
commit_description text,
commit_log_id integer,
port text,
commit_date text,
commit_date_raw timestamp with time zone,
commit_time text,
encoding_losses boolean,
status character(1),
version text,
revision text,
epoch text,
version_name text,
change_type text,
element_pathname text,
is_port boolean,
element_id integer,
forbidden text,
deprecated text,
ignore text,
broken text,
vulnerable_current integer,
vulnerable_past integer,
restricted text,
expiration_date date,
no_cdrom text,
is_interactive text,
only_for_archs text,
not_for_archs text,
svn_revision text,
svn_hostname text,
path_to_repo text,
repo_name text,
onwatchlist bigint
);
ALTER TYPE public.freshports_commit_record OWNER TO dan;
--
-- Name: getportfrompackagename_record; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.getportfrompackagename_record AS (
port_id integer,
category text,
port text,
element_pathname text
);
ALTER TYPE public.getportfrompackagename_record OWNER TO dan;
--
-- Name: logincounts_record; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.logincounts_record AS (
date date,
count integer
);
ALTER TYPE public.logincounts_record OWNER TO dan;
--
-- Name: mylogincounts_record; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.mylogincounts_record AS (
date date,
count integer
);
ALTER TYPE public.mylogincounts_record OWNER TO dan;
--
-- Name: old_new_ports_record; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.old_new_ports_record AS (
name_old text,
category_old text,
name_new text,
category_new text
);
ALTER TYPE public.old_new_ports_record OWNER TO dan;
--
-- Name: packageflavors_record; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.packageflavors_record AS (
id bigint,
port_id bigint,
flavor_id bigint,
flavor_name text,
name text,
flavor_number integer
);
ALTER TYPE public.packageflavors_record OWNER TO dan;
--
-- Name: vuxml_record; Type: TYPE; Schema: public; Owner: dan
--
CREATE TYPE public.vuxml_record AS (
id integer,
vid text,
package_name text,
op1 text,
v1 text,
op2 text,
v2 text
);
ALTER TYPE public.vuxml_record OWNER TO dan;
--
-- Name: allfilesdeleted(integer); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.allfilesdeleted(integer) RETURNS integer
LANGUAGE plpgsql STABLE
AS $_$
DECLARE
p_element_id ALIAS FOR $1;
queries RECORD;
l_result int;
BEGIN
FOR queries IN
SELECT id, status, directory_file_flag
FROM element
WHERE parent_id = p_element_id
LOOP
IF queries.directory_file_flag = 'F' THEN
IF queries.status = 'A' THEN
return 0;
END IF;
ELSE
l_result := AllFilesDeleted(queries.id);
IF l_result = 0 THEN
return 0;
END IF;
END IF;
END LOOP;
return 1;
END;
$_$;
ALTER FUNCTION public.allfilesdeleted(integer) OWNER TO dan;
--
-- Name: announcementsget(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.announcementsget() RETURNS SETOF text
LANGUAGE sql STABLE
AS $$
SELECT text
FROM announcements
WHERE start_date <= current_date
AND ((end_date IS NULL) OR (end_date >= current_date));
$$;
ALTER FUNCTION public.announcementsget() OWNER TO dan;
--
-- Name: announcementsgetplain(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.announcementsgetplain() RETURNS SETOF text
LANGUAGE sql STABLE
AS $$
SELECT text_plain
FROM announcements
WHERE start_date <= current_date
AND ((end_date IS NULL) OR (end_date >= current_date));
$$;
ALTER FUNCTION public.announcementsgetplain() OWNER TO dan;
--
-- Name: armor(bytea); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.armor(bytea) RETURNS text
LANGUAGE c IMMUTABLE STRICT
AS '$libdir/pgcrypto', 'pg_armor';
ALTER FUNCTION public.armor(bytea) OWNER TO dan;
--
-- Name: categories_insert_update(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.categories_insert_update() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF new.element_id IS NULL AND new.is_primary THEN
RAISE EXCEPTION 'if is_primary is set, then element_id must be non-null for a category (name=% description=%', new.name, new.description;
end if;
IF new.element_id IS NOT NULL AND NOT new.is_primary THEN
RAISE EXCEPTION 'Non primary categories must not have a element_id (name=% description=%', new.name, new.description;
end if;
RETURN new;
END;$$;
ALTER FUNCTION public.categories_insert_update() OWNER TO dan;
--
-- Name: categories_new(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.categories_new() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NOTIFY category_new;
RETURN new;
END;
$$;
ALTER FUNCTION public.categories_new() OWNER TO dan;
--
-- Name: categoryport(integer); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.categoryport(integer) RETURNS text
LANGUAGE sql STABLE
AS $_$
SELECT C.name || '/' || E.name
FROM ports P, categories C, element E
WHERE P.id = $1
AND P.category_id = C.id
AND P.element_id = E.id;
$_$;
ALTER FUNCTION public.categoryport(integer) OWNER TO dan;
--
-- Name: categoryportcount(text); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.categoryportcount(text) RETURNS bigint
LANGUAGE sql STABLE
AS $_$
SELECT count(*)
FROM categories C
JOIN ports_categories PC ON C.id = PC.category_id
JOIN ports P ON PC.port_id = P.id
JOIN element E ON P.element_id = E.id
JOIN element_pathname EP on E.id = EP.element_id
WHERE C.name = $1
AND E.status = 'A'
AND EP.pathname like '/ports/head/%';
$_$;
ALTER FUNCTION public.categoryportcount(text) OWNER TO dan;
--
-- Name: categoryportcount(text, text); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.categoryportcount(text, text) RETURNS bigint
LANGUAGE sql STABLE
AS $_$
SELECT count(*)
FROM categories C
JOIN ports_categories PC ON C.id = PC.category_id
JOIN ports P ON PC.port_id = P.id
JOIN element E ON P.element_id = E.id
JOIN element_pathname EP on E.id = EP.element_id
WHERE C.name = $1
AND E.status = 'A'
AND EP.pathname like '/ports/branches/' || $2 || '%';
$_$;
ALTER FUNCTION public.categoryportcount(text, text) OWNER TO dan;
--
-- Name: categorystatsupdate(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.categorystatsupdate() RETURNS integer
LANGUAGE plpgsql
AS $$
BEGIN
DELETE FROM category_stats;
INSERT INTO category_stats (
SELECT categories.id AS category_id,
count(ports_active.id) AS count,
max(commit_log.commit_date) AS updated
FROM categories, ports_active left outer join commit_log on ( ports_active.last_commit_id = commit_log.id )
WHERE categories.id = ports_active.category_id
AND categories.is_primary
GROUP BY categories.id, categories.name, categories.description, is_primary, categories.element_id
UNION
SELECT categories.id AS category_id,
count(ports_active.id) AS count,
max(commit_log.commit_date) AS updated
FROM ports_categories, categories, ports_active left outer join commit_log on ( ports_active.last_commit_id = commit_log.id )
WHERE ports_active.id = ports_categories.port_id
AND categories.id = ports_categories.category_id
AND NOT categories.is_primary
GROUP BY categories.id, categories.name, categories.description, is_primary, categories.element_id);
return 1;
END;
$$;
ALTER FUNCTION public.categorystatsupdate() OWNER TO dan;
--
-- Name: check_last_commit_id(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.check_last_commit_id() RETURNS trigger
LANGUAGE plpgsql
AS $$
declare
l_max_commit_date timestamp with time zone;
l_commit_log_id integer;
begin
if new.last_commit_id is null then
SELECT max(CL.commit_date)
INTO l_max_commit_date
FROM commit_log CL, commit_log_ports CLP
WHERE CLP.port_id = NEW.id
AND CL.id = CLP.commit_log_id;
IF FOUND THEN
SELECT CL.id
INTO l_commit_log_id
FROM commit_log CL, commit_log_ports CLP
WHERE CLP.port_id = NEW.id
AND CL.id = CLP.commit_log_id
AND CL.commit_date = l_max_commit_date;
IF FOUND THEN
NEW.last_commit_id := l_commit_log_id;
END IF;
END IF;
end if;
RETURN NEW;
end;
$$;
ALTER FUNCTION public.check_last_commit_id() OWNER TO dan;
--
-- Name: check_parent(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.check_parent() RETURNS trigger
LANGUAGE plpgsql
AS $$
declare
ElementCount int4;
begin
-- message 'check_parent';
if new.parent_id is not null then
-- message 'check_parent 2';
select count(*)
into ElementCount
from element
where element.id = new.parent_id;
-- message 'check_parent 3';
if (ElementCount = 0) then
-- message 'no such parent ' || NOW(*);
RAISE EXCEPTION 'modifications to element % with name=% cannot be completed as the parent % does not exist.', new.id, new.name, new.parent_id;
end if;
if new.parent_id = new.id then
RAISE EXCEPTION 'modifications to element % with name=% cannot be completed as the element cannot be a child of itself.', new.id, new.name;
end if;
end if;
-- message 'check_parent 4'
RETURN NEW;
end;
$$;
ALTER FUNCTION public.check_parent() OWNER TO dan;
--
-- Name: check_siblings(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.check_siblings() RETURNS trigger
LANGUAGE plpgsql
AS $$
declare
ElementCount integer;
PortCount integer;
OldParentStatus text;
begin
if new.Parent_ID is null then
select count(*)
into ElementCount
from element
where element.name=new.name
and element.Parent_ID is null
group by element.name;
else
select count(*)
into ElementCount
from element
where element.name=new.name
and element.Parent_ID=new.Parent_ID
group by element.name;
end if;
if (ElementCount > 1) then
RAISE EXCEPTION 'element % cannot be created as it already exists under that parent %', new.name, new.parent_id;
end if;
-- are we dealing with a Makefile which has a parent?
if new.name = 'Makefile' and new.Parent_ID is NOT NULL then
-- is this Makefile part of a port?
SELECT count(*)
INTO PortCount
FROM ports
WHERE element_id = new.Parent_ID;
IF PortCount > 0 THEN
-- we did a truth table. The status of a port is
-- determined by the status of the Makefile.
-- if it is deleted, we delete the port.
-- and if the Makefile is put back, we activate the port
SELECT status
INTO oldParentStatus
FROM element
WHERE id = new.Parent_ID;
if oldParentStatus != new.status then
UPDATE element
SET status = new.status
WHERE id = new.Parent_ID;
end if;
end if;
end if;
RETURN NEW;
end;
$$;
ALTER FUNCTION public.check_siblings() OWNER TO dan;
--
-- Name: clearslaveport(text); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.clearslaveport(text) RETURNS integer
LANGUAGE plpgsql
AS $_$
DECLARE
p_SlaveCategoryPort ALIAS FOR $1;
position int;
l_SlavePortCategory text;
l_SlavePortName text;
l_SlavePortID int4;
BEGIN
position := strpos(p_SlaveCategoryPort, '/');
l_SlavePortCategory := substr(p_SlaveCategoryPort, 1, position - 1);
l_SlavePortName := substr(p_SlaveCategoryPort, position + 1);
l_SlavePortID := GetPort(l_SlavePortCategory, l_SlavePortName);
DELETE FROM master_slave_ports
WHERE slave_port_id = l_SlavePortID;
UPDATE ports
SET is_slave_port = FALSE
WHERE id = l_SlavePortID;
return l_SlavePortID;
END
$_$;
ALTER FUNCTION public.clearslaveport(text) OWNER TO dan;
--
-- Name: commit_log_delete_check(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.commit_log_delete_check() RETURNS trigger
LANGUAGE plpgsql
AS $$
begin
-- if we are removing a commit_log, make sure we remove
-- the commit_log_elements as well
delete
from commit_log_elements
where commit_log_id = old.id;
RETURN OLD;
end;
$$;
ALTER FUNCTION public.commit_log_delete_check() OWNER TO dan;
--
-- Name: commit_log_insert(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.commit_log_insert() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO latest_commits (commit_log_id, commit_date) values (new.id, new.commit_date);
-- see also commit_log_update
INSERT INTO cache_clearing_dates (date_to_clear)
SELECT new.commit_date
WHERE NOT EXISTS (SELECT date_to_clear FROM cache_clearing_dates WHERE date_to_clear = new.commit_date);
IF FOUND THEN
NOTIFY date_updated;
END IF;
RETURN new;
END;$$;
ALTER FUNCTION public.commit_log_insert() OWNER TO dan;
--
-- Name: commit_log_ports_insert(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.commit_log_ports_insert() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO latest_commits_ports (commit_log_id, commit_date)
SELECT new.commit_log_id,
(SELECT commit_log.commit_date
FROM commit_log
WHERE (commit_log.id = new.commit_log_id)
)
WHERE (NOT (EXISTS (SELECT commits_latest_ports.commit_log_id
FROM latest_commits_ports commits_latest_ports
WHERE (commits_latest_ports.commit_log_id = new.commit_log_id)
)
)
);
RETURN new;
END;$$;
ALTER FUNCTION public.commit_log_ports_insert() OWNER TO dan;
--
-- Name: commit_log_ports_insert(integer); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.commit_log_ports_insert(integer) RETURNS boolean
LANGUAGE plpgsql
AS $_$
DECLARE
CommitLogID ALIAS for $1;
BEGIN
INSERT INTO latest_commits_ports (commit_log_id, commit_date)
SELECT CommitLogID,
(SELECT commit_log.commit_date
FROM commit_log
WHERE (commit_log.id = CommitLogID)
)
WHERE (NOT (EXISTS (SELECT commits_latest_ports.commit_log_id
FROM latest_commits_ports commits_latest_ports
WHERE (commits_latest_ports.commit_log_id = CommitLogID)
)
)
);
RETURN FOUND;
END;$_$;
ALTER FUNCTION public.commit_log_ports_insert(integer) OWNER TO dan;
--
-- Name: commit_log_ports_vuxml_clear_cache(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.commit_log_ports_vuxml_clear_cache() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
INSERT INTO cache_clearing_ports(port_id, category, port)
SELECT PA.id, PA.category, PA.name
FROM ports_all PA
WHERE PA.id = NEW.port_id;
NOTIFY port_updated;
END IF;
IF TG_OP = 'DELETE' THEN
INSERT INTO cache_clearing_ports(port_id, category, port)
SELECT PA.id, PA.category, PA.name
FROM ports_all PA
WHERE PA.id = OLD.port_id;
NOTIFY port_updated;
END IF;
RETURN NEW;
END
$$;
ALTER FUNCTION public.commit_log_ports_vuxml_clear_cache() OWNER TO dan;
--
-- Name: commit_log_ports_vuxml_purge(text); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.commit_log_ports_vuxml_purge(text) RETURNS SETOF integer
LANGUAGE sql
AS $_$
DELETE FROM commit_log_ports_vuxml CLPV
USING vuxml V
WHERE V.id = CLPV.vuxml_id
AND V.vid = $1
RETURNING 1
$_$;
ALTER FUNCTION public.commit_log_ports_vuxml_purge(text) OWNER TO dan;
--
-- Name: commit_log_update(); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.commit_log_update() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE latest_commits_ports
SET commit_date = new.commit_date
WHERE (latest_commits_ports.commit_log_id = new.id);
UPDATE latest_commits
SET commit_date = new.commit_date
WHERE (latest_commits.commit_log_id = new.id);
-- see also commit_log_insert
INSERT INTO cache_clearing_dates (date_to_clear)
SELECT new.commit_date
WHERE NOT EXISTS (SELECT date_to_clear FROM cache_clearing_dates WHERE date_to_clear = new.commit_date);
IF FOUND THEN
NOTIFY date_updated;
END IF;
RETURN new;
END;$$;
ALTER FUNCTION public.commit_log_update() OWNER TO dan;
--
-- Name: commitlogbranchesinsert(integer, integer); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.commitlogbranchesinsert(integer, integer) RETURNS boolean
LANGUAGE plpgsql
AS $_$
DECLARE
l_CommitLogId ALIAS for $1;
l_BranchId ALIAS for $2;
BEGIN
INSERT INTO commit_log_branches (commit_log_id, branch_id) values (l_CommitLogId, l_BranchId);
IF FOUND THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END;
$_$;
ALTER FUNCTION public.commitlogbranchesinsert(integer, integer) OWNER TO dan;
--
-- Name: confirmuseraccount(text); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.confirmuseraccount(text) RETURNS integer
LANGUAGE plpgsql
AS $_$
-- return values:
-- 0 : no such token found
-- -1 : some error occurred
-- 1 : confirmed and enabled
-- 2 : more than one user found with that token
-- very unlikely to occur.
DECLARE
TheToken ALIAS for $1;
RowsModified int4;
Result int4;
BEGIN
UPDATE users
SET status = 'A'
WHERE status != 'D'
AND EXISTS (
SELECT user_id
FROM user_confirmations
WHERE token = TheToken
AND user_id = users.id
);
GET DIAGNOSTICS RowsModified = ROW_COUNT;
IF RowsModified = 1 THEN
Result = 1;
ELSE
IF RowsModified = 0 THEN
Result = 0;
ELSE
IF RowsModified > 1 THEN
Result = 2;
ELSE
Result = -1;
END IF;
END IF;
END IF;
RETURN Result;
END;
$_$;
ALTER FUNCTION public.confirmuseraccount(text) OWNER TO dan;
--
-- Name: copyportfilesfromheadtobranch(text, text, text); Type: FUNCTION; Schema: public; Owner: dan
--
CREATE FUNCTION public.copyportfilesfromheadtobranch(text, text, text) RETURNS integer
LANGUAGE plpgsql
AS $_$
DECLARE
a_category_name ALIAS for $1;
a_port_name ALIAS for $2;
a_branch_name ALIAS for $3;
l_r element_id_pathname%rowtype;
l_element_id_of_new_port int4;
BEGIN
-- this query will add the new port... the key is the element_add() function call
FOR l_r IN
WITH RECURSIVE all_descendents AS (
SELECT id, name, parent_id, directory_file_flag, status
FROM element
WHERE id = (select pathname_id('/ports/head/' || a_category_name || '/' || a_port_name || '/'))
UNION
SELECT E.id, E.name, E.parent_id, E.directory_file_flag, E.status
FROM element E
JOIN all_descendents AD
ON (E.parent_id = AD.id)
)
SELECT element_add(replace(element_pathname(id), '/ports/head/', '/ports/branches/' || a_branch_name || '/'), directory_file_flag)
FROM all_descendents
WHERE status = 'A'
LOOP
END LOOP;
IF FOUND THEN
-- based on the element_id of the pathname for newly created port, grab the port id
SELECT pathname_id('/ports/branches/' || a_branch_name || '/' || a_category_name || '/' || a_port_name || '/')
INTO l_element_id_of_new_port;
END IF;
return l_element_id_of_new_port;
END;
$_$;
ALTER FUNCTION public.copyportfilesfromheadtobranch(text, text, text) OWNER TO dan;
--
-- Name: createcategory(text, text, boolean); Type: FUNCTION; Schema: public; Owner: dan
--