forked from samv/git-p4raw
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautonormalize_rules.sql
More file actions
92 lines (78 loc) · 2.85 KB
/
autonormalize_rules.sql
File metadata and controls
92 lines (78 loc) · 2.85 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
-- This is the meat of the metadata, really. We index 12 distinct
-- varieties of crap out of this once it's loaded, and end up querying
-- it a lot.
alter table integed rename to integed_normalize;
create table integed (
subject text not null, -- what file this log refers to
object text not null, -- file the record refers to in objective
object_minrev int not null, -- objective revisions range - lower bound
object_maxrev int not null, -- upper bound
subject_minrev int not null, -- subject revision range - lower
subject_maxrev int not null, -- upper
int_type int not null references int_type,
change int not null, -- Change this occurred in
-- primary key (change, subject, subject_maxrev, object, object_maxrev)
) inherits (source_file);
-- -------------------------------------------------------------
create function depotpath_rewrite() RETURNS trigger
language 'plpgsql' as
$$
DECLARE
BEGIN
IF TG_TABLE_NAME = 'integed' then
NEW.subject := create_or_find_depotpaths(NEW.subject);
NEW.object := create_or_find_depotpaths(NEW.object);
ELSIF TG_TABLE_NAME = 'rev' then
NEW.rcs_file := create_or_find_depotpaths(NEW.rcs_file);
NEW.depotpath := create_or_find_depotpaths(NEW.depotpath);
ELSIF TG_TABLE_NAME = 'revcx' then
NEW.depotpath := create_or_find_depotpaths(NEW.depotpath);
ELSIF TG_TABLE_NAME = 'label' then
NEW.depotpath := create_or_find_depotpaths(NEW.depotpath);
NEW.tagname := create_or_find_tagname(NEW.tagname);
END IF;
return NEW;
END;
$$;
/* add triggers to all the tables */
create trigger tg_depotpath_rewrite
BEFORE INSERT ON
integed
FOR EACH ROW EXECUTE PROCEDURE
depotpath_rewrite ()
;
create trigger tg_depotpath_rewrite
BEFORE INSERT ON
rev
FOR EACH ROW EXECUTE PROCEDURE
depotpath_rewrite ()
;
create trigger tg_depotpath_rewrite
BEFORE INSERT ON
revcx
FOR EACH ROW EXECUTE PROCEDURE
depotpath_rewrite ()
;
create trigger tg_depotpath_rewrite
BEFORE INSERT ON
label
FOR EACH ROW EXECUTE PROCEDURE
depotpath_rewrite ()
;
create or replace function D(text) returns integer language 'sql' as $$ select create_or_find_depotpaths($1); $$;
gitp4raw=> create RULE rewrite_integ_insert as on insert to integed do instead
insert into integed values (NEW.source_file_id,
NEW.source_file_max,D(NEW.subject_id),D(NEW.object_id),NEW.object_minrev,NEW.object_maxrev,NEW.subject_minrev,NEW.subject_maxrev,NEW.int_type,NEW.change)
;
/*
TODO: create update triggers. DONE
TODO: fix queries to join tables.
*/
/*
name | bytes | pages | size
------------------------+-------------+---------+------------
public.integed | 24609824768 | 2910239 | 23 GB
public.revcx | 18659000320 | 794270 | 17 GB
public.rev | 26493878272 | 1783629 | 25 GB
public.label | 64189489152 | 2757268 | 60 GB
*/