You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_foreigntable_for_es.sql 7.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. CREATE FOREIGN TABLE public."user_es"
  2. (
  3. id bigint NOT NULL ,
  4. lower_name character varying(255) NULL,
  5. name character varying(255) NULL,
  6. full_name character varying(255),
  7. email character varying(255),
  8. keep_email_private boolean,
  9. email_notifications_preference character varying(20) ,
  10. passwd character varying(255) ,
  11. passwd_hash_algo character varying(255) ,
  12. must_change_password boolean NOT NULL DEFAULT false,
  13. login_type integer,
  14. login_source bigint NOT NULL DEFAULT 0,
  15. login_name character varying(255) ,
  16. type integer,
  17. location character varying(255),
  18. website character varying(255),
  19. rands character varying(10),
  20. salt character varying(10),
  21. language character varying(5),
  22. description character varying(255),
  23. created_unix bigint,
  24. updated_unix bigint,
  25. last_login_unix bigint,
  26. last_repo_visibility boolean,
  27. max_repo_creation integer,
  28. is_active boolean,
  29. is_admin boolean,
  30. is_restricted boolean NOT NULL DEFAULT false,
  31. allow_git_hook boolean,
  32. allow_import_local boolean,
  33. allow_create_organization boolean DEFAULT true,
  34. prohibit_login boolean NOT NULL DEFAULT false,
  35. avatar character varying(2048) ,
  36. avatar_email character varying(255),
  37. use_custom_avatar boolean,
  38. num_followers integer,
  39. num_following integer NOT NULL DEFAULT 0,
  40. num_stars integer,
  41. num_repos integer,
  42. num_teams integer,
  43. num_members integer,
  44. visibility integer NOT NULL DEFAULT 0,
  45. repo_admin_change_team_access boolean NOT NULL DEFAULT false,
  46. diff_view_style character varying(255),
  47. theme character varying(255),
  48. token character varying(1024) ,
  49. public_key character varying(255),
  50. private_key character varying(255),
  51. is_operator boolean NOT NULL DEFAULT false
  52. ) SERVER multicorn_es
  53. OPTIONS
  54. (
  55. host '192.168.207.94',
  56. port '9200',
  57. index 'user_es-index',
  58. rowid_column 'id'
  59. )
  60. ;
  61. CREATE OR REPLACE FUNCTION public.insert_user_data() RETURNS trigger AS
  62. $def$
  63. BEGIN
  64. INSERT INTO public."user_es"(
  65. id,
  66. lower_name,
  67. name,
  68. full_name,
  69. email,
  70. keep_email_private,
  71. email_notifications_preference,
  72. must_change_password,
  73. login_type,
  74. login_source,
  75. login_name,
  76. type,
  77. location,
  78. website,
  79. rands,
  80. language,
  81. description,
  82. created_unix,
  83. updated_unix,
  84. last_login_unix,
  85. last_repo_visibility,
  86. max_repo_creation,
  87. is_active,
  88. is_restricted,
  89. allow_git_hook,
  90. allow_import_local,
  91. allow_create_organization,
  92. prohibit_login,
  93. avatar,
  94. avatar_email,
  95. use_custom_avatar,
  96. num_followers,
  97. num_following,
  98. num_stars,
  99. num_repos,
  100. num_teams,
  101. num_members,
  102. visibility,
  103. repo_admin_change_team_access,
  104. diff_view_style,
  105. theme,
  106. is_operator)
  107. VALUES (
  108. NEW.id,
  109. NEW.lower_name,
  110. NEW.name,
  111. NEW.full_name,
  112. NEW.email,
  113. NEW.keep_email_private,
  114. NEW.email_notifications_preference,
  115. NEW.must_change_password,
  116. NEW.login_type,
  117. NEW.login_source,
  118. NEW.login_name,
  119. NEW.type,
  120. NEW.location,
  121. NEW.website,
  122. NEW.rands,
  123. NEW.language,
  124. NEW.description,
  125. NEW.created_unix,
  126. NEW.updated_unix,
  127. NEW.last_login_unix,
  128. NEW.last_repo_visibility,
  129. NEW.max_repo_creation,
  130. NEW.is_active,
  131. NEW.is_restricted,
  132. NEW.allow_git_hook,
  133. NEW.allow_import_local,
  134. NEW.allow_create_organization,
  135. NEW.prohibit_login,
  136. NEW.avatar,
  137. NEW.avatar_email,
  138. NEW.use_custom_avatar,
  139. NEW.num_followers,
  140. NEW.num_following,
  141. NEW.num_stars,
  142. NEW.num_repos,
  143. NEW.num_teams,
  144. NEW.num_members,
  145. NEW.visibility,
  146. NEW.repo_admin_change_team_access,
  147. NEW.diff_view_style,
  148. NEW.theme,
  149. NEW.is_operator
  150. );
  151. RETURN NEW;
  152. END;
  153. $def$
  154. LANGUAGE plpgsql;
  155. DROP TRIGGER IF EXISTS es_insert_user on public.user;
  156. CREATE TRIGGER es_insert_user
  157. AFTER INSERT ON public.user
  158. FOR EACH ROW EXECUTE PROCEDURE insert_user_data();
  159. CREATE OR REPLACE FUNCTION public.update_user_description() RETURNS trigger AS
  160. $def$
  161. declare
  162. BEGIN
  163. UPDATE public.user_es SET description=NEW.description where id=NEW.id;
  164. return new;
  165. END
  166. $def$
  167. LANGUAGE plpgsql;
  168. DROP TRIGGER IF EXISTS es_update_user_description on public.user;
  169. CREATE TRIGGER es_update_user_description
  170. AFTER UPDATE OF "description" ON public.user
  171. FOR EACH ROW EXECUTE PROCEDURE update_user_description();
  172. CREATE OR REPLACE FUNCTION public.update_user_name() RETURNS trigger AS
  173. $def$
  174. declare
  175. BEGIN
  176. UPDATE public.user_es SET name=NEW.name where id=NEW.id;
  177. return new;
  178. END
  179. $def$
  180. LANGUAGE plpgsql;
  181. DROP TRIGGER IF EXISTS es_update_user_name on public.user;
  182. CREATE TRIGGER es_update_user_name
  183. AFTER UPDATE OF "name" ON public.user
  184. FOR EACH ROW EXECUTE PROCEDURE update_user_name();
  185. CREATE OR REPLACE FUNCTION public.update_user_full_name() RETURNS trigger AS
  186. $def$
  187. declare
  188. BEGIN
  189. UPDATE public.user_es SET full_name=NEW.full_name where id=NEW.id;
  190. return new;
  191. END
  192. $def$
  193. LANGUAGE plpgsql;
  194. DROP TRIGGER IF EXISTS es_update_user_full_name on public.user;
  195. CREATE TRIGGER es_update_user_full_name
  196. AFTER UPDATE OF "full_name" ON public.user
  197. FOR EACH ROW EXECUTE PROCEDURE update_user_full_name();
  198. CREATE OR REPLACE FUNCTION public.update_user_location() RETURNS trigger AS
  199. $def$
  200. declare
  201. BEGIN
  202. UPDATE public.user_es SET location=NEW.location where id=NEW.id;
  203. return new;
  204. END
  205. $def$
  206. LANGUAGE plpgsql;
  207. DROP TRIGGER IF EXISTS es_update_user_location on public.user;
  208. CREATE TRIGGER es_update_user_location
  209. AFTER UPDATE OF "location" ON public.user
  210. FOR EACH ROW EXECUTE PROCEDURE update_user_location();
  211. CREATE OR REPLACE FUNCTION public.update_user_website() RETURNS trigger AS
  212. $def$
  213. declare
  214. BEGIN
  215. UPDATE public.user_es SET website=NEW.website where id=NEW.id;
  216. return new;
  217. END
  218. $def$
  219. LANGUAGE plpgsql;
  220. DROP TRIGGER IF EXISTS es_update_user_website on public.user;
  221. CREATE TRIGGER es_update_user_website
  222. AFTER UPDATE OF "website" ON public.user
  223. FOR EACH ROW EXECUTE PROCEDURE update_user_website();
  224. CREATE OR REPLACE FUNCTION public.update_user_email() RETURNS trigger AS
  225. $def$
  226. declare
  227. BEGIN
  228. UPDATE public.user_es SET email=NEW.email where id=NEW.id;
  229. return new;
  230. END
  231. $def$
  232. LANGUAGE plpgsql;
  233. DROP TRIGGER IF EXISTS es_update_user_email on public.user;
  234. CREATE TRIGGER es_update_user_email
  235. AFTER UPDATE OF "email" ON public.user
  236. FOR EACH ROW EXECUTE PROCEDURE update_user_email();
  237. CREATE OR REPLACE FUNCTION public.delete_user() RETURNS trigger AS
  238. $def$
  239. declare
  240. BEGIN
  241. DELETE FROM public.user_es where id=OLD.id;
  242. return new;
  243. END
  244. $def$
  245. LANGUAGE plpgsql;
  246. DROP TRIGGER IF EXISTS es_delete_user on public.user;
  247. CREATE TRIGGER es_delete_user
  248. AFTER DELETE ON public.user
  249. FOR EACH ROW EXECUTE PROCEDURE delete_user();