Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

struct_init.sql 6.8KB

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