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

struct_init.sql 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. --
  2. -- PostgreSQL database dump
  3. --
  4. --
  5. -- Name: sp_lu_get_all_user_permission(integer); Type: FUNCTION; Schema: public; Owner: dev
  6. --
  7. CREATE FUNCTION sp_lu_get_all_user_permission(_user_id integer, OUT _permisson_name character varying, OUT val boolean) RETURNS SETOF record
  8. LANGUAGE sql IMMUTABLE SECURITY DEFINER COST 10
  9. AS $$
  10. SELECT p.name, sp_lu_get_user_permission(_user_id, p.name) FROM luticate_permissions p ORDER bY p.name
  11. $$;
  12. --
  13. -- Name: sp_lu_get_user_permission(integer, character varying); Type: FUNCTION; Schema: public; Owner: dev
  14. --
  15. CREATE FUNCTION sp_lu_get_user_permission(_user_id integer, _permisson_name character varying, OUT val boolean) RETURNS boolean
  16. LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER COST 10
  17. AS $$
  18. DECLARE
  19. groups int[];
  20. g INT;
  21. BEGIN
  22. SELECT "value" INTO val FROM luticate_permissions_users WHERE "user_id" = _user_id AND "name" = _permisson_name;
  23. IF val is null THEN
  24. SELECT lpg."value" into val FROM luticate_permissions_groups lpg
  25. INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
  26. INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
  27. WHERE lpg."name" = _permisson_name and lpg."value" = FALSE;
  28. IF val is null then
  29. SELECT lpg."value" into val FROM luticate_permissions_groups lpg
  30. INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
  31. INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
  32. WHERE lpg."name" = _permisson_name and lpg."value" = TRUE;
  33. IF val is null then
  34. SELECT "value" INTO val FROM luticate_permissions WHERE "name" = _permisson_name;
  35. END IF;
  36. end if;
  37. END IF;
  38. END;
  39. $$;
  40. --
  41. -- Name: luticate_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: dev
  42. --
  43. CREATE SEQUENCE luticate_groups_id_seq
  44. START WITH 1
  45. INCREMENT BY 1
  46. NO MINVALUE
  47. NO MAXVALUE
  48. CACHE 1;
  49. SET default_tablespace = '';
  50. SET default_with_oids = false;
  51. --
  52. -- Name: luticate_groups; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  53. --
  54. CREATE TABLE luticate_groups (
  55. id integer DEFAULT nextval('luticate_groups_id_seq'::regclass) NOT NULL,
  56. name character varying NOT NULL
  57. );
  58. --
  59. -- Name: luticate_permissions; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  60. --
  61. CREATE TABLE luticate_permissions (
  62. name character varying(128) NOT NULL,
  63. value boolean NOT NULL
  64. );
  65. --
  66. -- Name: luticate_permissions_groups; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  67. --
  68. CREATE TABLE luticate_permissions_groups (
  69. name character varying(128) NOT NULL,
  70. value boolean NOT NULL,
  71. group_id integer NOT NULL
  72. );
  73. --
  74. -- Name: luticate_permissions_users; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  75. --
  76. CREATE TABLE luticate_permissions_users (
  77. name character varying(128) NOT NULL,
  78. value boolean,
  79. user_id integer NOT NULL
  80. );
  81. --
  82. -- Name: luticate_users_id_seq; Type: SEQUENCE; Schema: public; Owner: dev
  83. --
  84. CREATE SEQUENCE luticate_users_id_seq
  85. START WITH 1
  86. INCREMENT BY 1
  87. NO MINVALUE
  88. NO MAXVALUE
  89. CACHE 1;
  90. --
  91. -- Name: luticate_users; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  92. --
  93. CREATE TABLE luticate_users (
  94. id integer DEFAULT nextval('luticate_users_id_seq'::regclass) NOT NULL,
  95. username character varying(255) NOT NULL,
  96. email character varying(255) NOT NULL,
  97. password character varying(255) NOT NULL,
  98. salt character varying(10) NOT NULL,
  99. profile_id integer,
  100. firstname character varying(255) NOT NULL,
  101. lastname character varying(255) NOT NULL
  102. );
  103. --
  104. -- Name: luticate_users_groups; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  105. --
  106. CREATE TABLE luticate_users_groups (
  107. user_id integer NOT NULL,
  108. group_id integer NOT NULL
  109. );
  110. --
  111. -- Name: luticate_groups_name_key; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  112. --
  113. ALTER TABLE ONLY luticate_groups
  114. ADD CONSTRAINT luticate_groups_name_key UNIQUE (name);
  115. --
  116. -- Name: luticate_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  117. --
  118. ALTER TABLE ONLY luticate_groups
  119. ADD CONSTRAINT luticate_groups_pkey PRIMARY KEY (id);
  120. --
  121. -- Name: luticate_permissions_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  122. --
  123. ALTER TABLE ONLY luticate_permissions
  124. ADD CONSTRAINT luticate_permissions_pkey PRIMARY KEY (name);
  125. --
  126. -- Name: luticate_permissions_users_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  127. --
  128. ALTER TABLE ONLY luticate_permissions_users
  129. ADD CONSTRAINT luticate_permissions_users_pkey PRIMARY KEY (name, user_id);
  130. --
  131. -- Name: luticate_users_email_key; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  132. --
  133. ALTER TABLE ONLY luticate_users
  134. ADD CONSTRAINT luticate_users_email_key UNIQUE (email);
  135. --
  136. -- Name: luticate_users_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  137. --
  138. ALTER TABLE ONLY luticate_users_groups
  139. ADD CONSTRAINT luticate_users_groups_pkey PRIMARY KEY (user_id, group_id);
  140. --
  141. -- Name: luticate_users_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  142. --
  143. ALTER TABLE ONLY luticate_users
  144. ADD CONSTRAINT luticate_users_pkey PRIMARY KEY (id);
  145. --
  146. -- Name: luticate_users_username_key; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  147. --
  148. ALTER TABLE ONLY luticate_users
  149. ADD CONSTRAINT luticate_users_username_key UNIQUE (username);
  150. --
  151. -- Name: pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  152. --
  153. ALTER TABLE ONLY luticate_permissions_groups
  154. ADD CONSTRAINT pkey PRIMARY KEY (name, group_id);
  155. --
  156. -- Name: foreign_group; Type: FK CONSTRAINT; Schema: public; Owner: dev
  157. --
  158. ALTER TABLE ONLY luticate_permissions_groups
  159. ADD CONSTRAINT foreign_group FOREIGN KEY (group_id) REFERENCES luticate_groups(id) ON DELETE CASCADE;
  160. --
  161. -- Name: foreign_group; Type: FK CONSTRAINT; Schema: public; Owner: dev
  162. --
  163. ALTER TABLE ONLY luticate_users_groups
  164. ADD CONSTRAINT foreign_group FOREIGN KEY (group_id) REFERENCES luticate_groups(id) ON DELETE CASCADE;
  165. --
  166. -- Name: foreign_name; Type: FK CONSTRAINT; Schema: public; Owner: dev
  167. --
  168. ALTER TABLE ONLY luticate_permissions_groups
  169. ADD CONSTRAINT foreign_name FOREIGN KEY (name) REFERENCES luticate_permissions(name) ON DELETE CASCADE;
  170. --
  171. -- Name: foreign_name; Type: FK CONSTRAINT; Schema: public; Owner: dev
  172. --
  173. ALTER TABLE ONLY luticate_permissions_users
  174. ADD CONSTRAINT foreign_name FOREIGN KEY (name) REFERENCES luticate_permissions(name) ON DELETE CASCADE;
  175. --
  176. -- Name: foreign_user; Type: FK CONSTRAINT; Schema: public; Owner: dev
  177. --
  178. ALTER TABLE ONLY luticate_permissions_users
  179. ADD CONSTRAINT foreign_user FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
  180. --
  181. -- Name: foreign_user; Type: FK CONSTRAINT; Schema: public; Owner: dev
  182. --
  183. ALTER TABLE ONLY luticate_users_groups
  184. ADD CONSTRAINT foreign_user FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
  185. --
  186. -- PostgreSQL database dump complete
  187. --