1 CREATE EXTENSION
IF NOT EXISTS plpgsql
WITH SCHEMA pg_catalog
;
2 CREATE EXTENSION
IF NOT EXISTS tsm_system_rows
;
3 COMMENT ON EXTENSION plpgsql
IS 'PL/pgSQL procedural language';
5 CREATE TABLE public.
auth_user (
7 password character varying(128) NOT NULL,
8 last_login
timestamp with time zone,
9 is_superuser
boolean NOT NULL,
10 username
character varying(150) NOT NULL,
11 first_name
character varying(30) NOT NULL,
12 last_name
character varying(30) NOT NULL,
13 email
character varying(254) NOT NULL,
14 is_staff
boolean NOT NULL,
15 is_active
boolean NOT NULL,
16 date_joined
timestamp with time zone DEFAULT now() NOT NULL,
20 ALTER TABLE public.auth_user
OWNER TO gargantua
;
22 -- TODO add publication_date
23 -- TODO typename -> type_id
24 CREATE TABLE public.
nodes (
26 typename
integer NOT NULL,
27 user_id
integer NOT NULL,
28 parent_id
integer REFERENCES public.
nodes(id) ON DELETE CASCADE ,
29 name character varying(255) DEFAULT ''::character varying NOT NULL,
30 date timestamp with time zone DEFAULT now() NOT NULL,
31 hyperdata jsonb
DEFAULT '{}'::jsonb NOT NULL,
34 FOREIGN KEY (user_id
) REFERENCES public.
auth_user(id) ON DELETE CASCADE
36 ALTER TABLE public.nodes
OWNER TO gargantua
;
38 CREATE TABLE public.
ngrams (
40 terms
character varying(255),
44 ALTER TABLE public.ngrams
OWNER TO gargantua
;
46 --------------------------------------------------------------
47 CREATE TABLE public.
node_ngrams (
49 node_id
integer NOT NULL,
51 ngrams_id
integer NOT NULL,
52 ngrams_type
integer, -- change to ngrams_field? (no for pedagogic reason)
56 weight
double precision,
58 FOREIGN KEY (node_id
) REFERENCES public.
nodes(id) ON DELETE CASCADE,
59 FOREIGN KEY (ngrams_id
) REFERENCES public.
ngrams(id) ON DELETE CASCADE
61 ALTER TABLE public.node_ngrams
OWNER TO gargantua
;
63 CREATE TABLE public.
node_ngrams_ngrams (
64 node_id
integer NOT NULL,
65 node_ngrams1_id
integer NOT NULL,
66 node_ngrams2_id
integer NOT NULL,
67 FOREIGN KEY (node_id
) REFERENCES public.
nodes(id) ON DELETE CASCADE,
68 FOREIGN KEY (node_ngrams1_id
) REFERENCES public.
node_ngrams(id) ON DELETE CASCADE,
69 FOREIGN KEY (node_ngrams2_id
) REFERENCES public.
node_ngrams(id) ON DELETE CASCADE,
70 PRIMARY KEY (node_id
, node_ngrams1_id
, node_ngrams2_id
)
72 ALTER TABLE public.node_ngrams_ngrams
OWNER TO gargantua
;
74 --------------------------------------------------------------
75 --------------------------------------------------------------
78 --CREATE TABLE public.nodes_ngrams_ngrams (
79 -- node_id integer NOT NULL REFERENCES public.nodes(id) ON DELETE CASCADE,
80 -- ngram1_id integer NOT NULL REFERENCES public.ngrams(id) ON DELETE CASCADE,
81 -- ngram2_id integer NOT NULL REFERENCES public.ngrams(id) ON DELETE CASCADE,
82 -- weight double precision,
83 -- PRIMARY KEY (node_id,ngram1_id,ngram2_id)
86 --ALTER TABLE public.nodes_ngrams_ngrams OWNER TO gargantua;
87 ---------------------------------------------------------------
88 -- TODO nodes_nodes(node1_id int, node2_id int, edge_type int , weight real)
89 CREATE TABLE public.
nodes_nodes (
90 node1_id
integer NOT NULL REFERENCES public.
nodes(id) ON DELETE CASCADE,
91 node2_id
integer NOT NULL REFERENCES public.
nodes(id) ON DELETE CASCADE,
94 PRIMARY KEY (node1_id
,node2_id
)
96 ALTER TABLE public.nodes_nodes
OWNER TO gargantua
;
98 ---------------------------------------------------------------
99 -- TODO should reference "id" of nodes_nodes (instead of node1_id, node2_id)
100 CREATE TABLE public.
node_node_ngrams (
101 node1_id
INTEGER NOT NULL REFERENCES public.
nodes (id) ON DELETE CASCADE,
102 -- here id to node_ngrams
103 node2_id
INTEGER NOT NULL REFERENCES public.
nodes (id) ON DELETE CASCADE,
104 ngrams_id
INTEGER NOT NULL REFERENCES public.
ngrams (id) ON DELETE CASCADE,
106 --ngrams_tag INTEGER,
107 --ngrams_class INTEGER,
108 weight
double precision,
109 PRIMARY KEY (node1_id
, node2_id
, ngrams_id
, ngrams_type
)
111 ALTER TABLE public.node_node_ngrams
OWNER TO gargantua
;
112 --------------------------------------------------------------
114 --CREATE TABLE public.nodes_ngrams_repo (
115 -- version integer NOT NULL,
116 -- patches jsonb DEFAULT '{}'::jsonb NOT NULL,
117 -- PRIMARY KEY (version)
119 --ALTER TABLE public.nodes_ngrams_repo OWNER TO gargantua;
121 ---------------------------------------------------------
123 -- If needed for rights management at row level
124 -- CREATE EXTENSION IF NOT EXISTS acl WITH SCHEMA public;
126 CREATE TABLE public.
rights (
127 user_id
INTEGER NOT NULL REFERENCES public.
auth_user(id) ON DELETE CASCADE,
128 node_id
INTEGER NOT NULL REFERENCES public.
nodes(id) ON DELETE CASCADE,
129 rights
INTEGER NOT NULL,
130 PRIMARY KEY (user_id
, node_id
)
132 ALTER TABLE public.rights
OWNER TO gargantua
;
134 ------------------------------------------------------------
137 CREATE INDEX ON public.auth_user
USING btree (username varchar_pattern_ops
);
138 CREATE UNIQUE INDEX ON public.auth_user
USING btree (username
);
140 CREATE INDEX ON public.rights
USING btree (user_id
,node_id
);
142 CREATE INDEX ON public.nodes
USING gin (hyperdata
);
143 CREATE INDEX ON public.nodes
USING btree (user_id
, typename
, parent_id
);
144 CREATE INDEX ON public.nodes
USING btree (typename
, id);
145 CREATE UNIQUE INDEX ON public.nodes
USING btree (((hyperdata
->> 'uniqId'::text)));
146 CREATE UNIQUE INDEX ON public.nodes
USING btree (((hyperdata
->> 'uniqIdBdd'::text)));
147 CREATE UNIQUE INDEX ON public.nodes
USING btree (typename
, parent_id
, ((hyperdata
->> 'uniqId'::text)));
149 CREATE UNIQUE INDEX ON public.
ngrams (terms
); -- TEST GIN
150 CREATE INDEX ON public.ngrams
USING btree (id, terms
);
151 CREATE UNIQUE INDEX ON public.node_ngrams
USING btree (node_id
,node_subtype
, ngrams_id
);
153 CREATE INDEX ON public.nodes_nodes
USING btree (node1_id
, node2_id
, category
);
154 CREATE UNIQUE INDEX ON public.nodes_nodes
USING btree (node1_id
, node2_id
);
156 CREATE UNIQUE INDEX ON public.node_node_ngrams
USING btree (node1_id
, node2_id
, ngrams_id
, ngrams_type
);
157 CREATE INDEX ON public.node_node_ngrams
USING btree (node1_id
, node2_id
);
158 CREATE INDEX ON public.node_node_ngrams
USING btree (ngrams_id
, node2_id
);
161 ------------------------------------------------------------------------
162 -- Ngrams Full DB Extraction Optim
163 -- TODO remove hard parameter and move elsewhere
164 CREATE OR REPLACE function node_pos(int, int) returns bigint
165 AS 'SELECT count(id) from nodes
169 LANGUAGE SQL immutable;
171 --drop index node_by_pos;
172 create index node_by_pos
on nodes
using btree(node_pos(id,typename
));