Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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
  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 array_agg("group_id") INTO groups FROM luticate_users_groups WHERE "user_id" = _user_id;
  25. IF groups is not null then
  26. FOREACH g in ARRAY groups LOOP
  27. SELECT "value" INTO val FROM luticate_permissions_groups WHERE "group_id" = g AND "name" = _permisson_name;
  28. IF val = FALSE THEN
  29. EXIT;
  30. END IF;
  31. END LOOP;
  32. END if;
  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;
  38. $$;
  39. --
  40. -- Name: luticate_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: dev
  41. --
  42. CREATE SEQUENCE luticate_groups_id_seq
  43. START WITH 1
  44. INCREMENT BY 1
  45. NO MINVALUE
  46. NO MAXVALUE
  47. CACHE 1;
  48. SET default_tablespace = '';
  49. SET default_with_oids = false;
  50. --
  51. -- Name: luticate_groups; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  52. --
  53. CREATE TABLE luticate_groups (
  54. id integer DEFAULT nextval('luticate_groups_id_seq'::regclass) NOT NULL,
  55. name character varying NOT NULL
  56. );
  57. --
  58. -- Name: luticate_permissions; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  59. --
  60. CREATE TABLE luticate_permissions (
  61. name character varying(128) NOT NULL,
  62. value boolean NOT NULL
  63. );
  64. --
  65. -- Name: luticate_permissions_groups; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  66. --
  67. CREATE TABLE luticate_permissions_groups (
  68. name character varying(128) NOT NULL,
  69. value boolean NOT NULL,
  70. group_id integer NOT NULL
  71. );
  72. --
  73. -- Name: luticate_permissions_users; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  74. --
  75. CREATE TABLE luticate_permissions_users (
  76. name character varying(128) NOT NULL,
  77. value boolean,
  78. user_id integer NOT NULL
  79. );
  80. --
  81. -- Name: luticate_users_id_seq; Type: SEQUENCE; Schema: public; Owner: dev
  82. --
  83. CREATE SEQUENCE luticate_users_id_seq
  84. START WITH 1
  85. INCREMENT BY 1
  86. NO MINVALUE
  87. NO MAXVALUE
  88. CACHE 1;
  89. --
  90. -- Name: luticate_users; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  91. --
  92. CREATE TABLE luticate_users (
  93. id integer DEFAULT nextval('luticate_users_id_seq'::regclass) NOT NULL,
  94. username character varying(255) NOT NULL,
  95. email character varying(255) NOT NULL,
  96. password character varying(255) NOT NULL,
  97. salt character varying(10) NOT NULL,
  98. profile_id integer,
  99. firstname character varying(255) NOT NULL,
  100. lastname character varying(255) NOT NULL
  101. );
  102. --
  103. -- Name: luticate_users_groups; Type: TABLE; Schema: public; Owner: dev; Tablespace:
  104. --
  105. CREATE TABLE luticate_users_groups (
  106. user_id integer NOT NULL,
  107. group_id integer NOT NULL
  108. );
  109. --
  110. -- Name: luticate_groups_name_key; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  111. --
  112. ALTER TABLE ONLY luticate_groups
  113. ADD CONSTRAINT luticate_groups_name_key UNIQUE (name);
  114. --
  115. -- Name: luticate_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  116. --
  117. ALTER TABLE ONLY luticate_groups
  118. ADD CONSTRAINT luticate_groups_pkey PRIMARY KEY (id);
  119. --
  120. -- Name: luticate_permissions_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  121. --
  122. ALTER TABLE ONLY luticate_permissions
  123. ADD CONSTRAINT luticate_permissions_pkey PRIMARY KEY (name);
  124. --
  125. -- Name: luticate_permissions_users_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  126. --
  127. ALTER TABLE ONLY luticate_permissions_users
  128. ADD CONSTRAINT luticate_permissions_users_pkey PRIMARY KEY (name, user_id);
  129. --
  130. -- Name: luticate_users_email_key; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  131. --
  132. ALTER TABLE ONLY luticate_users
  133. ADD CONSTRAINT luticate_users_email_key UNIQUE (email);
  134. --
  135. -- Name: luticate_users_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  136. --
  137. ALTER TABLE ONLY luticate_users_groups
  138. ADD CONSTRAINT luticate_users_groups_pkey PRIMARY KEY (user_id, group_id);
  139. --
  140. -- Name: luticate_users_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  141. --
  142. ALTER TABLE ONLY luticate_users
  143. ADD CONSTRAINT luticate_users_pkey PRIMARY KEY (id);
  144. --
  145. -- Name: luticate_users_username_key; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  146. --
  147. ALTER TABLE ONLY luticate_users
  148. ADD CONSTRAINT luticate_users_username_key UNIQUE (username);
  149. --
  150. -- Name: pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
  151. --
  152. ALTER TABLE ONLY luticate_permissions_groups
  153. ADD CONSTRAINT pkey PRIMARY KEY (name, group_id);
  154. --
  155. -- Name: foreign_group; Type: FK CONSTRAINT; Schema: public; Owner: dev
  156. --
  157. ALTER TABLE ONLY luticate_permissions_groups
  158. ADD CONSTRAINT foreign_group FOREIGN KEY (group_id) REFERENCES luticate_groups(id) ON DELETE CASCADE;
  159. --
  160. -- Name: foreign_group; Type: FK CONSTRAINT; Schema: public; Owner: dev
  161. --
  162. ALTER TABLE ONLY luticate_users_groups
  163. ADD CONSTRAINT foreign_group FOREIGN KEY (group_id) REFERENCES luticate_groups(id) ON DELETE CASCADE;
  164. --
  165. -- Name: foreign_name; Type: FK CONSTRAINT; Schema: public; Owner: dev
  166. --
  167. ALTER TABLE ONLY luticate_permissions_groups
  168. ADD CONSTRAINT foreign_name FOREIGN KEY (name) REFERENCES luticate_permissions(name) ON DELETE CASCADE;
  169. --
  170. -- Name: foreign_name; Type: FK CONSTRAINT; Schema: public; Owner: dev
  171. --
  172. ALTER TABLE ONLY luticate_permissions_users
  173. ADD CONSTRAINT foreign_name FOREIGN KEY (name) REFERENCES luticate_permissions(name) ON DELETE CASCADE;
  174. --
  175. -- Name: foreign_user; Type: FK CONSTRAINT; Schema: public; Owner: dev
  176. --
  177. ALTER TABLE ONLY luticate_permissions_users
  178. ADD CONSTRAINT foreign_user FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
  179. --
  180. -- Name: foreign_user; Type: FK CONSTRAINT; Schema: public; Owner: dev
  181. --
  182. ALTER TABLE ONLY luticate_users_groups
  183. ADD CONSTRAINT foreign_user FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
  184. --
  185. -- PostgreSQL database dump complete
  186. --