選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

struct_init.sql 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. --
  2. -- PostgreSQL database dump
  3. --
  4. -- Dumped from database version 9.4.7
  5. -- Dumped by pg_dump version 9.4.7
  6. -- Started on 2016-04-27 09:40:56 CEST
  7. SET statement_timeout = 0;
  8. SET lock_timeout = 0;
  9. SET client_encoding = 'UTF8';
  10. SET standard_conforming_strings = on;
  11. SET check_function_bodies = false;
  12. SET client_min_messages = warning;
  13. --
  14. -- TOC entry 1 (class 3079 OID 11893)
  15. -- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
  16. --
  17. CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
  18. --
  19. -- TOC entry 2114 (class 0 OID 0)
  20. -- Dependencies: 1
  21. -- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
  22. --
  23. COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
  24. SET search_path = public, pg_catalog;
  25. --
  26. -- TOC entry 201 (class 1255 OID 25843)
  27. -- Name: sp_get_images(boolean, integer); Type: FUNCTION; Schema: public; Owner: -
  28. --
  29. CREATE FUNCTION sp_get_images(_only_mine boolean, _user_id_me integer, OUT id integer, OUT name text, OUT user_id integer, OUT date timestamp without time zone) RETURNS SETOF record
  30. LANGUAGE sql IMMUTABLE SECURITY DEFINER COST 10
  31. AS $$
  32. SELECT i.id, i.name, i.user_id, i.date
  33. FROM images i
  34. WHERE (CASE WHEN _only_mine THEN i.user_id = _user_id_me ELSE TRUE END)
  35. $$;
  36. --
  37. -- TOC entry 198 (class 1255 OID 25773)
  38. -- Name: sp_lu_get_all_user_permission(integer); Type: FUNCTION; Schema: public; Owner: -
  39. --
  40. CREATE FUNCTION sp_lu_get_all_user_permission(_user_id integer, OUT _permisson_name character varying, OUT val boolean) RETURNS SETOF record
  41. LANGUAGE sql IMMUTABLE SECURITY DEFINER COST 10
  42. AS $$
  43. SELECT p.name, sp_lu_get_user_permission(_user_id, p.name) FROM luticate_permissions p ORDER bY p.name
  44. $$;
  45. --
  46. -- TOC entry 200 (class 1255 OID 25801)
  47. -- Name: sp_lu_get_all_user_settings(integer); Type: FUNCTION; Schema: public; Owner: -
  48. --
  49. CREATE FUNCTION sp_lu_get_all_user_settings(_user_id integer, OUT _settings json) RETURNS SETOF json
  50. LANGUAGE sql IMMUTABLE SECURITY DEFINER COST 10
  51. AS $$
  52. SELECT sp_lu_get_user_setting(_user_id, s.name)
  53. FROM luticate_settings s
  54. WHERE NOT s.is_admin
  55. ORDER BY s.name
  56. $$;
  57. --
  58. -- TOC entry 197 (class 1255 OID 25772)
  59. -- Name: sp_lu_get_user_permission(integer, character varying); Type: FUNCTION; Schema: public; Owner: -
  60. --
  61. CREATE FUNCTION sp_lu_get_user_permission(_user_id integer, _permisson_name character varying, OUT val boolean) RETURNS boolean
  62. LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER COST 10
  63. AS $$
  64. DECLARE
  65. groups int[];
  66. g INT;
  67. BEGIN
  68. SELECT "value" INTO val FROM luticate_permissions_users WHERE "user_id" = _user_id AND "name" = _permisson_name;
  69. IF val is null THEN
  70. SELECT lpg."value" into val FROM luticate_permissions_groups lpg
  71. INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
  72. INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
  73. WHERE lpg."name" = _permisson_name and lpg."value" = FALSE;
  74. IF val is null then
  75. SELECT lpg."value" into val FROM luticate_permissions_groups lpg
  76. INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
  77. INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
  78. WHERE lpg."name" = _permisson_name and lpg."value" = TRUE;
  79. IF val is null then
  80. SELECT "value" INTO val FROM luticate_permissions WHERE "name" = _permisson_name;
  81. END IF;
  82. end if;
  83. END IF;
  84. END;
  85. $$;
  86. --
  87. -- TOC entry 199 (class 1255 OID 25800)
  88. -- Name: sp_lu_get_user_setting(integer, character varying); Type: FUNCTION; Schema: public; Owner: -
  89. --
  90. CREATE FUNCTION sp_lu_get_user_setting(_user_id integer, _setting_name character varying, OUT setting json) RETURNS json
  91. LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER COST 10
  92. AS $$
  93. DECLARE
  94. _setting luticate_settings;
  95. _setting_user luticate_settings_users;
  96. BEGIN
  97. SELECT * INTO _setting FROM luticate_settings WHERE "name" = _setting_name AND NOT "is_admin";
  98. IF _setting IS NULL THEN
  99. setting := NULL;
  100. ELSE
  101. IF NOT _setting.is_blocked THEN
  102. SELECT * INTO _setting_user FROM luticate_settings_users WHERE "user_id" = _user_id AND "name" = _setting_name;
  103. IF _setting_user IS NOT NULL THEN
  104. _setting.value := _setting_user.value;
  105. END IF;
  106. END IF;
  107. setting := to_json(_setting);
  108. END IF;
  109. END;
  110. $$;
  111. SET default_tablespace = '';
  112. SET default_with_oids = false;
  113. --
  114. -- TOC entry 184 (class 1259 OID 25804)
  115. -- Name: images; Type: TABLE; Schema: public; Owner: -; Tablespace:
  116. --
  117. CREATE TABLE images (
  118. id integer NOT NULL,
  119. user_id integer NOT NULL,
  120. path text NOT NULL,
  121. date timestamp without time zone DEFAULT now() NOT NULL,
  122. name text NOT NULL
  123. );
  124. --
  125. -- TOC entry 183 (class 1259 OID 25802)
  126. -- Name: images_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  127. --
  128. CREATE SEQUENCE images_id_seq
  129. START WITH 1
  130. INCREMENT BY 1
  131. NO MINVALUE
  132. NO MAXVALUE
  133. CACHE 1;
  134. --
  135. -- TOC entry 2115 (class 0 OID 0)
  136. -- Dependencies: 183
  137. -- Name: images_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  138. --
  139. ALTER SEQUENCE images_id_seq OWNED BY images.id;
  140. --
  141. -- TOC entry 173 (class 1259 OID 25694)
  142. -- Name: luticate_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  143. --
  144. CREATE SEQUENCE luticate_groups_id_seq
  145. START WITH 1
  146. INCREMENT BY 1
  147. NO MINVALUE
  148. NO MAXVALUE
  149. CACHE 1;
  150. --
  151. -- TOC entry 174 (class 1259 OID 25696)
  152. -- Name: luticate_groups; Type: TABLE; Schema: public; Owner: -; Tablespace:
  153. --
  154. CREATE TABLE luticate_groups (
  155. id integer DEFAULT nextval('luticate_groups_id_seq'::regclass) NOT NULL,
  156. name character varying NOT NULL
  157. );
  158. --
  159. -- TOC entry 175 (class 1259 OID 25703)
  160. -- Name: luticate_permissions; Type: TABLE; Schema: public; Owner: -; Tablespace:
  161. --
  162. CREATE TABLE luticate_permissions (
  163. name character varying(128) NOT NULL,
  164. value boolean NOT NULL
  165. );
  166. --
  167. -- TOC entry 176 (class 1259 OID 25706)
  168. -- Name: luticate_permissions_groups; Type: TABLE; Schema: public; Owner: -; Tablespace:
  169. --
  170. CREATE TABLE luticate_permissions_groups (
  171. name character varying(128) NOT NULL,
  172. value boolean NOT NULL,
  173. group_id integer NOT NULL
  174. );
  175. --
  176. -- TOC entry 177 (class 1259 OID 25709)
  177. -- Name: luticate_permissions_users; Type: TABLE; Schema: public; Owner: -; Tablespace:
  178. --
  179. CREATE TABLE luticate_permissions_users (
  180. name character varying(128) NOT NULL,
  181. value boolean,
  182. user_id integer NOT NULL
  183. );
  184. --
  185. -- TOC entry 181 (class 1259 OID 25774)
  186. -- Name: luticate_settings; Type: TABLE; Schema: public; Owner: -; Tablespace:
  187. --
  188. CREATE TABLE luticate_settings (
  189. name character varying(128) NOT NULL,
  190. type character varying(128) NOT NULL,
  191. value text NOT NULL,
  192. is_blocked boolean NOT NULL,
  193. is_admin boolean NOT NULL
  194. );
  195. --
  196. -- TOC entry 182 (class 1259 OID 25780)
  197. -- Name: luticate_settings_users; Type: TABLE; Schema: public; Owner: -; Tablespace:
  198. --
  199. CREATE TABLE luticate_settings_users (
  200. name character varying(128) NOT NULL,
  201. value text NOT NULL,
  202. user_id integer NOT NULL,
  203. is_blocked boolean NOT NULL
  204. );
  205. --
  206. -- TOC entry 178 (class 1259 OID 25712)
  207. -- Name: luticate_users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  208. --
  209. CREATE SEQUENCE luticate_users_id_seq
  210. START WITH 1
  211. INCREMENT BY 1
  212. NO MINVALUE
  213. NO MAXVALUE
  214. CACHE 1;
  215. --
  216. -- TOC entry 179 (class 1259 OID 25714)
  217. -- Name: luticate_users; Type: TABLE; Schema: public; Owner: -; Tablespace:
  218. --
  219. CREATE TABLE luticate_users (
  220. id integer DEFAULT nextval('luticate_users_id_seq'::regclass) NOT NULL,
  221. username character varying(255) NOT NULL,
  222. email character varying(255) NOT NULL,
  223. password character varying(255) NOT NULL,
  224. salt character varying(10) NOT NULL,
  225. profile_id integer,
  226. firstname character varying(255) NOT NULL,
  227. lastname character varying(255) NOT NULL
  228. );
  229. --
  230. -- TOC entry 180 (class 1259 OID 25721)
  231. -- Name: luticate_users_groups; Type: TABLE; Schema: public; Owner: -; Tablespace:
  232. --
  233. CREATE TABLE luticate_users_groups (
  234. user_id integer NOT NULL,
  235. group_id integer NOT NULL
  236. );
  237. --
  238. -- TOC entry 1965 (class 2604 OID 25807)
  239. -- Name: id; Type: DEFAULT; Schema: public; Owner: -
  240. --
  241. ALTER TABLE ONLY images ALTER COLUMN id SET DEFAULT nextval('images_id_seq'::regclass);
  242. --
  243. -- TOC entry 1990 (class 2606 OID 25812)
  244. -- Name: images_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  245. --
  246. ALTER TABLE ONLY images
  247. ADD CONSTRAINT images_pkey PRIMARY KEY (id);
  248. --
  249. -- TOC entry 1968 (class 2606 OID 25725)
  250. -- Name: luticate_groups_name_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  251. --
  252. ALTER TABLE ONLY luticate_groups
  253. ADD CONSTRAINT luticate_groups_name_key UNIQUE (name);
  254. --
  255. -- TOC entry 1970 (class 2606 OID 25727)
  256. -- Name: luticate_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  257. --
  258. ALTER TABLE ONLY luticate_groups
  259. ADD CONSTRAINT luticate_groups_pkey PRIMARY KEY (id);
  260. --
  261. -- TOC entry 1972 (class 2606 OID 25729)
  262. -- Name: luticate_permissions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  263. --
  264. ALTER TABLE ONLY luticate_permissions
  265. ADD CONSTRAINT luticate_permissions_pkey PRIMARY KEY (name);
  266. --
  267. -- TOC entry 1976 (class 2606 OID 25731)
  268. -- Name: luticate_permissions_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  269. --
  270. ALTER TABLE ONLY luticate_permissions_users
  271. ADD CONSTRAINT luticate_permissions_users_pkey PRIMARY KEY (name, user_id);
  272. --
  273. -- TOC entry 1986 (class 2606 OID 25787)
  274. -- Name: luticate_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  275. --
  276. ALTER TABLE ONLY luticate_settings
  277. ADD CONSTRAINT luticate_settings_pkey PRIMARY KEY (name);
  278. --
  279. -- TOC entry 1988 (class 2606 OID 25789)
  280. -- Name: luticate_settings_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  281. --
  282. ALTER TABLE ONLY luticate_settings_users
  283. ADD CONSTRAINT luticate_settings_users_pkey PRIMARY KEY (name, user_id);
  284. --
  285. -- TOC entry 1978 (class 2606 OID 25733)
  286. -- Name: luticate_users_email_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  287. --
  288. ALTER TABLE ONLY luticate_users
  289. ADD CONSTRAINT luticate_users_email_key UNIQUE (email);
  290. --
  291. -- TOC entry 1984 (class 2606 OID 25735)
  292. -- Name: luticate_users_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  293. --
  294. ALTER TABLE ONLY luticate_users_groups
  295. ADD CONSTRAINT luticate_users_groups_pkey PRIMARY KEY (user_id, group_id);
  296. --
  297. -- TOC entry 1980 (class 2606 OID 25737)
  298. -- Name: luticate_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  299. --
  300. ALTER TABLE ONLY luticate_users
  301. ADD CONSTRAINT luticate_users_pkey PRIMARY KEY (id);
  302. --
  303. -- TOC entry 1982 (class 2606 OID 25739)
  304. -- Name: luticate_users_username_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  305. --
  306. ALTER TABLE ONLY luticate_users
  307. ADD CONSTRAINT luticate_users_username_key UNIQUE (username);
  308. --
  309. -- TOC entry 1974 (class 2606 OID 25741)
  310. -- Name: pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  311. --
  312. ALTER TABLE ONLY luticate_permissions_groups
  313. ADD CONSTRAINT pkey PRIMARY KEY (name, group_id);
  314. --
  315. -- TOC entry 1991 (class 2606 OID 25742)
  316. -- Name: foreign_group; Type: FK CONSTRAINT; Schema: public; Owner: -
  317. --
  318. ALTER TABLE ONLY luticate_permissions_groups
  319. ADD CONSTRAINT foreign_group FOREIGN KEY (group_id) REFERENCES luticate_groups(id) ON DELETE CASCADE;
  320. --
  321. -- TOC entry 1995 (class 2606 OID 25747)
  322. -- Name: foreign_group; Type: FK CONSTRAINT; Schema: public; Owner: -
  323. --
  324. ALTER TABLE ONLY luticate_users_groups
  325. ADD CONSTRAINT foreign_group FOREIGN KEY (group_id) REFERENCES luticate_groups(id) ON DELETE CASCADE;
  326. --
  327. -- TOC entry 1992 (class 2606 OID 25752)
  328. -- Name: foreign_name; Type: FK CONSTRAINT; Schema: public; Owner: -
  329. --
  330. ALTER TABLE ONLY luticate_permissions_groups
  331. ADD CONSTRAINT foreign_name FOREIGN KEY (name) REFERENCES luticate_permissions(name) ON DELETE CASCADE;
  332. --
  333. -- TOC entry 1993 (class 2606 OID 25757)
  334. -- Name: foreign_name; Type: FK CONSTRAINT; Schema: public; Owner: -
  335. --
  336. ALTER TABLE ONLY luticate_permissions_users
  337. ADD CONSTRAINT foreign_name FOREIGN KEY (name) REFERENCES luticate_permissions(name) ON DELETE CASCADE;
  338. --
  339. -- TOC entry 1994 (class 2606 OID 25762)
  340. -- Name: foreign_user; Type: FK CONSTRAINT; Schema: public; Owner: -
  341. --
  342. ALTER TABLE ONLY luticate_permissions_users
  343. ADD CONSTRAINT foreign_user FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
  344. --
  345. -- TOC entry 1996 (class 2606 OID 25767)
  346. -- Name: foreign_user; Type: FK CONSTRAINT; Schema: public; Owner: -
  347. --
  348. ALTER TABLE ONLY luticate_users_groups
  349. ADD CONSTRAINT foreign_user FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
  350. --
  351. -- TOC entry 1997 (class 2606 OID 25790)
  352. -- Name: luticate_settings_users_name_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
  353. --
  354. ALTER TABLE ONLY luticate_settings_users
  355. ADD CONSTRAINT luticate_settings_users_name_fkey FOREIGN KEY (name) REFERENCES luticate_settings(name) ON DELETE CASCADE;
  356. --
  357. -- TOC entry 1998 (class 2606 OID 25795)
  358. -- Name: luticate_settings_users_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
  359. --
  360. ALTER TABLE ONLY luticate_settings_users
  361. ADD CONSTRAINT luticate_settings_users_user_id_fkey FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
  362. -- Completed on 2016-04-27 09:40:56 CEST
  363. --
  364. -- PostgreSQL database dump complete
  365. --