pod-init-database.sql 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. --
  2. -- PostgreSQL database dump
  3. --
  4. SET statement_timeout = 0;
  5. SET client_encoding = 'UTF8';
  6. SET standard_conforming_strings = on;
  7. SET check_function_bodies = false;
  8. SET client_min_messages = warning;
  9. --
  10. -- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
  11. --
  12. CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
  13. --
  14. -- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
  15. --
  16. COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
  17. SET search_path = public, pg_catalog;
  18. --
  19. -- Name: pod_update_node(); Type: FUNCTION; Schema: public; Owner: pod_intranet
  20. --
  21. CREATE FUNCTION pod_update_node() RETURNS trigger
  22. LANGUAGE plpgsql
  23. AS $$
  24. BEGIN
  25. INSERT INTO pod_nodes_history (node_id, parent_id, node_order, node_type, created_at, updated_at,
  26. data_label, data_content, data_datetime, node_status, data_reminder_datetime,
  27. data_file_name, data_file_content, data_file_mime_type, parent_tree_path,
  28. node_depth, owner_id, version_id, is_shared, is_public, public_url_key) VALUES (NEW.node_id, NEW.parent_id, NEW.node_order, NEW.node_type, NEW.created_at, NEW.updated_at, NEW.data_label, NEW.data_content, NEW.data_datetime, NEW.node_status, NEW.data_reminder_datetime, NEW.data_file_name, NEW.data_file_content, NEW.data_file_mime_type, NEW.parent_tree_path, NEW.node_depth, NEW.owner_id, nextval('pod_nodes_version_id_sequence'), NEW.is_shared, NEW.is_public, NEW.public_url_key);
  29. return new;
  30. END;
  31. $$;
  32. --
  33. -- Name: set_created_at(); Type: FUNCTION; Schema: public; Owner: pod_intranet
  34. --
  35. CREATE FUNCTION set_created_at() RETURNS trigger
  36. LANGUAGE plpgsql
  37. AS $$
  38. BEGIN
  39. NEW.created_at = CURRENT_TIMESTAMP;
  40. NEW.updated_at = CURRENT_TIMESTAMP;
  41. RETURN NEW;
  42. END;
  43. $$;
  44. --
  45. -- Name: set_updated_at(); Type: FUNCTION; Schema: public; Owner: pod_intranet
  46. --
  47. CREATE FUNCTION set_updated_at() RETURNS trigger
  48. LANGUAGE plpgsql
  49. AS $$
  50. BEGIN
  51. NEW.updated_at = CURRENT_TIMESTAMP;
  52. RETURN NEW;
  53. END;
  54. $$;
  55. SET default_tablespace = '';
  56. SET default_with_oids = false;
  57. --
  58. -- Name: migrate_version; Type: TABLE; Schema: public; Owner: pod_intranet; Tablespace:
  59. --
  60. CREATE TABLE migrate_version (
  61. version_num character varying(32) NOT NULL
  62. );
  63. --
  64. -- Name: pod_group; Type: TABLE; Schema: public; Owner: pod_intranet; Tablespace:
  65. --
  66. CREATE TABLE pod_group (
  67. group_id integer NOT NULL,
  68. group_name character varying(16) NOT NULL,
  69. display_name character varying(255),
  70. created timestamp without time zone,
  71. personnal_group boolean
  72. );
  73. --
  74. -- Name: pod_group_group_id_seq; Type: SEQUENCE; Schema: public; Owner: pod_intranet
  75. --
  76. CREATE SEQUENCE pod_group_group_id_seq
  77. START WITH 1
  78. INCREMENT BY 1
  79. NO MINVALUE
  80. NO MAXVALUE
  81. CACHE 1;
  82. --
  83. -- Name: pod_group_group_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: pod_intranet
  84. --
  85. ALTER SEQUENCE pod_group_group_id_seq OWNED BY pod_group.group_id;
  86. --
  87. -- Name: pod_group_node; Type: TABLE; Schema: public; Owner: pod_intranet; Tablespace:
  88. --
  89. CREATE TABLE pod_group_node (
  90. group_id integer NOT NULL,
  91. node_id integer NOT NULL,
  92. rights integer
  93. );
  94. --
  95. -- Name: pod_group_permission; Type: TABLE; Schema: public; Owner: pod_intranet; Tablespace:
  96. --
  97. CREATE TABLE pod_group_permission (
  98. group_id integer NOT NULL,
  99. permission_id integer NOT NULL
  100. );
  101. --
  102. -- Name: pod_nodes_version_id_sequence; Type: SEQUENCE; Schema: public; Owner: pod_intranet
  103. --
  104. CREATE SEQUENCE pod_nodes_version_id_sequence
  105. START WITH 1
  106. INCREMENT BY 1
  107. NO MINVALUE
  108. NO MAXVALUE
  109. CACHE 1;
  110. --
  111. -- Name: pod_nodes_history; Type: TABLE; Schema: public; Owner: pod_intranet; Tablespace:
  112. --
  113. CREATE TABLE pod_nodes_history (
  114. node_id integer NOT NULL,
  115. parent_id integer,
  116. node_order integer DEFAULT 1,
  117. node_type character varying(16) DEFAULT 'data'::character varying NOT NULL,
  118. created_at timestamp without time zone,
  119. updated_at timestamp without time zone,
  120. data_label character varying(1024),
  121. data_content text DEFAULT ''::text NOT NULL,
  122. data_datetime timestamp without time zone,
  123. node_status character varying(16) DEFAULT 'new'::character varying,
  124. data_reminder_datetime timestamp without time zone,
  125. data_file_name character varying(255),
  126. data_file_content bytea,
  127. data_file_mime_type character varying(255),
  128. parent_tree_path character varying(255),
  129. node_depth integer DEFAULT 0 NOT NULL,
  130. owner_id integer,
  131. version_id integer DEFAULT nextval('pod_nodes_version_id_sequence'::regclass) NOT NULL,
  132. is_shared boolean DEFAULT false NOT NULL,
  133. is_public boolean DEFAULT false NOT NULL,
  134. public_url_key character varying(1024)
  135. );
  136. --
  137. -- Name: pod_nodes; Type: VIEW; Schema: public; Owner: pod_intranet
  138. --
  139. CREATE VIEW pod_nodes AS
  140. SELECT DISTINCT ON (pod_nodes_history.node_id) pod_nodes_history.node_id, pod_nodes_history.parent_id, pod_nodes_history.node_order, pod_nodes_history.node_type, pod_nodes_history.created_at, pod_nodes_history.updated_at, pod_nodes_history.data_label, pod_nodes_history.data_content, pod_nodes_history.data_datetime, pod_nodes_history.node_status, pod_nodes_history.data_reminder_datetime, pod_nodes_history.data_file_name, pod_nodes_history.data_file_content, pod_nodes_history.data_file_mime_type, pod_nodes_history.parent_tree_path, pod_nodes_history.node_depth, pod_nodes_history.owner_id, pod_nodes_history.is_shared, pod_nodes_history.is_public, pod_nodes_history.public_url_key FROM pod_nodes_history ORDER BY pod_nodes_history.node_id, pod_nodes_history.updated_at DESC;
  141. --
  142. -- Name: pod_nodes__node_id__sequence; Type: SEQUENCE; Schema: public; Owner: pod_intranet
  143. --
  144. CREATE SEQUENCE pod_nodes__node_id__sequence
  145. START WITH 1
  146. INCREMENT BY 1
  147. NO MINVALUE
  148. NO MAXVALUE
  149. CACHE 1;
  150. --
  151. -- Name: pod_nodes__node_id__sequence; Type: SEQUENCE OWNED BY; Schema: public; Owner: pod_intranet
  152. --
  153. ALTER SEQUENCE pod_nodes__node_id__sequence OWNED BY pod_nodes_history.node_id;
  154. --
  155. -- Name: pod_permission; Type: TABLE; Schema: public; Owner: pod_intranet; Tablespace:
  156. --
  157. CREATE TABLE pod_permission (
  158. permission_id integer NOT NULL,
  159. permission_name character varying(63) NOT NULL,
  160. description character varying(255)
  161. );
  162. --
  163. -- Name: pod_permission_permission_id_seq; Type: SEQUENCE; Schema: public; Owner: pod_intranet
  164. --
  165. CREATE SEQUENCE pod_permission_permission_id_seq
  166. START WITH 1
  167. INCREMENT BY 1
  168. NO MINVALUE
  169. NO MAXVALUE
  170. CACHE 1;
  171. --
  172. -- Name: pod_permission_permission_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: pod_intranet
  173. --
  174. ALTER SEQUENCE pod_permission_permission_id_seq OWNED BY pod_permission.permission_id;
  175. --
  176. -- Name: pod_user; Type: TABLE; Schema: public; Owner: pod_intranet; Tablespace:
  177. --
  178. CREATE TABLE pod_user (
  179. user_id integer NOT NULL,
  180. email_address character varying(255) NOT NULL,
  181. display_name character varying(255),
  182. password character varying(128),
  183. created timestamp without time zone
  184. );
  185. --
  186. -- Name: pod_user_group; Type: TABLE; Schema: public; Owner: pod_intranet; Tablespace:
  187. --
  188. CREATE TABLE pod_user_group (
  189. user_id integer NOT NULL,
  190. group_id integer NOT NULL
  191. );
  192. --
  193. -- Name: pod_user_user_id_seq; Type: SEQUENCE; Schema: public; Owner: pod_intranet
  194. --
  195. CREATE SEQUENCE pod_user_user_id_seq
  196. START WITH 1
  197. INCREMENT BY 1
  198. NO MINVALUE
  199. NO MAXVALUE
  200. CACHE 1;
  201. --
  202. -- Name: pod_user_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: pod_intranet
  203. --
  204. ALTER SEQUENCE pod_user_user_id_seq OWNED BY pod_user.user_id;
  205. --
  206. -- Name: group_id; Type: DEFAULT; Schema: public; Owner: pod_intranet
  207. --
  208. ALTER TABLE ONLY pod_group ALTER COLUMN group_id SET DEFAULT nextval('pod_group_group_id_seq'::regclass);
  209. --
  210. -- Name: node_id; Type: DEFAULT; Schema: public; Owner: pod_intranet
  211. --
  212. ALTER TABLE ONLY pod_nodes_history ALTER COLUMN node_id SET DEFAULT nextval('pod_nodes__node_id__sequence'::regclass);
  213. --
  214. -- Name: permission_id; Type: DEFAULT; Schema: public; Owner: pod_intranet
  215. --
  216. ALTER TABLE ONLY pod_permission ALTER COLUMN permission_id SET DEFAULT nextval('pod_permission_permission_id_seq'::regclass);
  217. --
  218. -- Name: user_id; Type: DEFAULT; Schema: public; Owner: pod_intranet
  219. --
  220. ALTER TABLE ONLY pod_user ALTER COLUMN user_id SET DEFAULT nextval('pod_user_user_id_seq'::regclass);
  221. --
  222. -- Data for Name: migrate_version; Type: TABLE DATA; Schema: public; Owner: pod_intranet
  223. --
  224. COPY migrate_version (version_num) FROM stdin;
  225. \.
  226. --
  227. -- Data for Name: pod_group; Type: TABLE DATA; Schema: public; Owner: pod_intranet
  228. --
  229. COPY pod_group (group_id, group_name, display_name, created, personnal_group) FROM stdin;
  230. 1 managers Managers \N f
  231. 3 admin Admin \N f
  232. -1 user_1 \N 2014-06-11 10:55:36.163634 t
  233. 2 user All Users \N f
  234. \.
  235. --
  236. -- Name: pod_group_group_id_seq; Type: SEQUENCE SET; Schema: public; Owner: pod_intranet
  237. --
  238. SELECT pg_catalog.setval('pod_group_group_id_seq', 1, false);
  239. --
  240. -- Data for Name: pod_group_permission; Type: TABLE DATA; Schema: public; Owner: pod_intranet
  241. --
  242. COPY pod_group_permission (group_id, permission_id) FROM stdin;
  243. \.
  244. --
  245. -- Name: pod_nodes__node_id__sequence; Type: SEQUENCE SET; Schema: public; Owner: pod_intranet
  246. --
  247. SELECT pg_catalog.setval('pod_nodes__node_id__sequence', 25, true);
  248. --
  249. -- Name: pod_nodes_version_id_sequence; Type: SEQUENCE SET; Schema: public; Owner: pod_intranet
  250. --
  251. SELECT pg_catalog.setval('pod_nodes_version_id_sequence', 41, true);
  252. --
  253. -- Data for Name: pod_permission; Type: TABLE DATA; Schema: public; Owner: pod_intranet
  254. --
  255. COPY pod_permission (permission_id, permission_name, description) FROM stdin;
  256. \.
  257. --
  258. -- Name: pod_permission_permission_id_seq; Type: SEQUENCE SET; Schema: public; Owner: pod_intranet
  259. --
  260. SELECT pg_catalog.setval('pod_permission_permission_id_seq', 1, false);
  261. --
  262. -- Data for Name: pod_user; Type: TABLE DATA; Schema: public; Owner: pod_intranet
  263. --
  264. COPY pod_user (user_id, email_address, display_name, password, created) FROM stdin;
  265. 1 admin@localhost Admin b0c2243d8052ebc30e446d557b3249ed143e0ba6922ec49d9c53f3c1a533ae25b5dc4ec00d6cc3dd9fc9c74107e9914b3ace56ba8ded846bda9c140c0d6f721e 2014-06-11 10:55:36.15707
  266. \.
  267. --
  268. -- Data for Name: pod_user_group; Type: TABLE DATA; Schema: public; Owner: pod_intranet
  269. --
  270. COPY pod_user_group (user_id, group_id) FROM stdin;
  271. 1 2
  272. 1 -1
  273. \.
  274. --
  275. -- Name: pod_user_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: pod_intranet
  276. --
  277. SELECT pg_catalog.setval('pod_user_user_id_seq', 1, true);
  278. --
  279. -- Name: pod_group_group_name_key; Type: CONSTRAINT; Schema: public; Owner: pod_intranet; Tablespace:
  280. --
  281. ALTER TABLE ONLY pod_group
  282. ADD CONSTRAINT pod_group_group_name_key UNIQUE (group_name);
  283. --
  284. -- Name: pod_group_node_pkey; Type: CONSTRAINT; Schema: public; Owner: pod_intranet; Tablespace:
  285. --
  286. ALTER TABLE ONLY pod_group_node
  287. ADD CONSTRAINT pod_group_node_pkey PRIMARY KEY (group_id, node_id);
  288. --
  289. -- Name: pod_group_permission_pkey; Type: CONSTRAINT; Schema: public; Owner: pod_intranet; Tablespace:
  290. --
  291. ALTER TABLE ONLY pod_group_permission
  292. ADD CONSTRAINT pod_group_permission_pkey PRIMARY KEY (group_id, permission_id);
  293. --
  294. -- Name: pod_group_pkey; Type: CONSTRAINT; Schema: public; Owner: pod_intranet; Tablespace:
  295. --
  296. ALTER TABLE ONLY pod_group
  297. ADD CONSTRAINT pod_group_pkey PRIMARY KEY (group_id);
  298. --
  299. -- Name: pod_nodes_history_pkey; Type: CONSTRAINT; Schema: public; Owner: pod_intranet; Tablespace:
  300. --
  301. ALTER TABLE ONLY pod_nodes_history
  302. ADD CONSTRAINT pod_nodes_history_pkey PRIMARY KEY (version_id);
  303. --
  304. -- Name: pod_permission_permission_name_key; Type: CONSTRAINT; Schema: public; Owner: pod_intranet; Tablespace:
  305. --
  306. ALTER TABLE ONLY pod_permission
  307. ADD CONSTRAINT pod_permission_permission_name_key UNIQUE (permission_name);
  308. --
  309. -- Name: pod_permission_pkey; Type: CONSTRAINT; Schema: public; Owner: pod_intranet; Tablespace:
  310. --
  311. ALTER TABLE ONLY pod_permission
  312. ADD CONSTRAINT pod_permission_pkey PRIMARY KEY (permission_id);
  313. --
  314. -- Name: pod_user_email_address_key; Type: CONSTRAINT; Schema: public; Owner: pod_intranet; Tablespace:
  315. --
  316. ALTER TABLE ONLY pod_user
  317. ADD CONSTRAINT pod_user_email_address_key UNIQUE (email_address);
  318. --
  319. -- Name: pod_user_group_pkey; Type: CONSTRAINT; Schema: public; Owner: pod_intranet; Tablespace:
  320. --
  321. ALTER TABLE ONLY pod_user_group
  322. ADD CONSTRAINT pod_user_group_pkey PRIMARY KEY (user_id, group_id);
  323. --
  324. -- Name: pod_user_pkey; Type: CONSTRAINT; Schema: public; Owner: pod_intranet; Tablespace:
  325. --
  326. ALTER TABLE ONLY pod_user
  327. ADD CONSTRAINT pod_user_pkey PRIMARY KEY (user_id);
  328. --
  329. -- Name: fki_pod_nodes__owner_id_fk; Type: INDEX; Schema: public; Owner: pod_intranet; Tablespace:
  330. --
  331. CREATE INDEX fki_pod_nodes__owner_id_fk ON pod_nodes_history USING btree (owner_id);
  332. --
  333. -- Name: fki_pod_nodes__parent_id_fk; Type: INDEX; Schema: public; Owner: pod_intranet; Tablespace:
  334. --
  335. CREATE INDEX fki_pod_nodes__parent_id_fk ON pod_nodes_history USING btree (parent_id);
  336. --
  337. -- Name: idx_pod_nodes__parent_tree_path; Type: INDEX; Schema: public; Owner: pod_intranet; Tablespace:
  338. --
  339. CREATE INDEX idx_pod_nodes__parent_tree_path ON pod_nodes_history USING btree (parent_tree_path);
  340. --
  341. -- Name: pod_insert_new_node; Type: RULE; Schema: public; Owner: pod_intranet
  342. --
  343. CREATE RULE pod_insert_new_node AS ON INSERT TO pod_nodes DO INSTEAD INSERT INTO pod_nodes_history (node_id, parent_id, node_order, node_type, created_at, updated_at, data_label, data_content, data_datetime, node_status, data_reminder_datetime, data_file_name, data_file_content, data_file_mime_type, parent_tree_path, node_depth, owner_id, version_id, is_shared, is_public, public_url_key) VALUES (nextval('pod_nodes__node_id__sequence'::regclass), new.parent_id, new.node_order, new.node_type, new.created_at, new.updated_at, new.data_label, new.data_content, new.data_datetime, new.node_status, new.data_reminder_datetime, new.data_file_name, new.data_file_content, new.data_file_mime_type, new.parent_tree_path, new.node_depth, new.owner_id, nextval('pod_nodes_version_id_sequence'::regclass), new.is_shared, new.is_public, new.public_url_key) RETURNING pod_nodes_history.node_id, pod_nodes_history.parent_id, pod_nodes_history.node_order, pod_nodes_history.node_type, pod_nodes_history.created_at, pod_nodes_history.updated_at, pod_nodes_history.data_label, pod_nodes_history.data_content, pod_nodes_history.data_datetime, pod_nodes_history.node_status, pod_nodes_history.data_reminder_datetime, pod_nodes_history.data_file_name, pod_nodes_history.data_file_content, pod_nodes_history.data_file_mime_type, pod_nodes_history.parent_tree_path, pod_nodes_history.node_depth, pod_nodes_history.owner_id, pod_nodes_history.is_shared, pod_nodes_history.is_public, pod_nodes_history.public_url_key;
  344. --
  345. -- Name: pod_nodes__on_insert_set_created_at; Type: TRIGGER; Schema: public; Owner: pod_intranet
  346. --
  347. CREATE TRIGGER pod_nodes__on_insert_set_created_at BEFORE INSERT ON pod_nodes_history FOR EACH ROW EXECUTE PROCEDURE set_created_at();
  348. --
  349. -- Name: pod_nodes__on_update_set_updated_at; Type: TRIGGER; Schema: public; Owner: pod_intranet
  350. --
  351. CREATE TRIGGER pod_nodes__on_update_set_updated_at BEFORE UPDATE ON pod_nodes_history FOR EACH ROW EXECUTE PROCEDURE set_updated_at();
  352. --
  353. -- Name: pod_update_node_tg; Type: TRIGGER; Schema: public; Owner: pod_intranet
  354. --
  355. CREATE TRIGGER pod_update_node_tg INSTEAD OF UPDATE ON pod_nodes FOR EACH ROW EXECUTE PROCEDURE pod_update_node();
  356. --
  357. -- Name: pod_group_node_group_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: pod_intranet
  358. --
  359. ALTER TABLE ONLY pod_group_node
  360. ADD CONSTRAINT pod_group_node_group_id_fkey FOREIGN KEY (group_id) REFERENCES pod_group(group_id) ON UPDATE CASCADE ON DELETE CASCADE;
  361. --
  362. -- Name: pod_group_permission_group_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: pod_intranet
  363. --
  364. ALTER TABLE ONLY pod_group_permission
  365. ADD CONSTRAINT pod_group_permission_group_id_fkey FOREIGN KEY (group_id) REFERENCES pod_group(group_id) ON UPDATE CASCADE ON DELETE CASCADE;
  366. --
  367. -- Name: pod_group_permission_permission_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: pod_intranet
  368. --
  369. ALTER TABLE ONLY pod_group_permission
  370. ADD CONSTRAINT pod_group_permission_permission_id_fkey FOREIGN KEY (permission_id) REFERENCES pod_permission(permission_id) ON UPDATE CASCADE ON DELETE CASCADE;
  371. --
  372. -- Name: pod_nodes__owner_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: pod_intranet
  373. --
  374. ALTER TABLE ONLY pod_nodes_history
  375. ADD CONSTRAINT pod_nodes__owner_id_fk FOREIGN KEY (owner_id) REFERENCES pod_user(user_id);
  376. --
  377. -- Name: pod_user_group_group_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: pod_intranet
  378. --
  379. ALTER TABLE ONLY pod_user_group
  380. ADD CONSTRAINT pod_user_group_group_id_fkey FOREIGN KEY (group_id) REFERENCES pod_group(group_id) ON UPDATE CASCADE ON DELETE CASCADE;
  381. --
  382. -- Name: pod_user_group_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: pod_intranet
  383. --
  384. ALTER TABLE ONLY pod_user_group
  385. ADD CONSTRAINT pod_user_group_user_id_fkey FOREIGN KEY (user_id) REFERENCES pod_user(user_id) ON UPDATE CASCADE ON DELETE CASCADE;