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.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. DROP FOREIGN table if exists public.user_es;
  2. CREATE FOREIGN TABLE public.user_es
  3. (
  4. id bigint NOT NULL ,
  5. lower_name character varying(255) NULL,
  6. name character varying(255) NULL,
  7. full_name character varying(255),
  8. email character varying(255),
  9. keep_email_private boolean,
  10. email_notifications_preference character varying(20) ,
  11. passwd character varying(255) ,
  12. passwd_hash_algo character varying(255) ,
  13. must_change_password boolean NOT NULL DEFAULT false,
  14. login_type integer,
  15. login_source bigint NOT NULL DEFAULT 0,
  16. login_name character varying(255) ,
  17. type integer,
  18. location character varying(255),
  19. website character varying(255),
  20. rands character varying(10),
  21. salt character varying(10),
  22. language character varying(5),
  23. description character varying(255),
  24. created_unix bigint,
  25. updated_unix bigint,
  26. last_login_unix bigint,
  27. last_repo_visibility boolean,
  28. max_repo_creation integer,
  29. is_active boolean,
  30. is_admin boolean,
  31. is_restricted boolean NOT NULL DEFAULT false,
  32. allow_git_hook boolean,
  33. allow_import_local boolean,
  34. allow_create_organization boolean DEFAULT true,
  35. prohibit_login boolean NOT NULL DEFAULT false,
  36. avatar character varying(2048) ,
  37. avatar_email character varying(255),
  38. use_custom_avatar boolean,
  39. num_followers integer,
  40. num_following integer NOT NULL DEFAULT 0,
  41. num_stars integer,
  42. num_repos integer,
  43. num_teams integer,
  44. num_members integer,
  45. visibility integer NOT NULL DEFAULT 0,
  46. repo_admin_change_team_access boolean NOT NULL DEFAULT false,
  47. diff_view_style character varying(255),
  48. theme character varying(255),
  49. token character varying(1024) ,
  50. public_key character varying(255),
  51. private_key character varying(255),
  52. is_operator boolean NOT NULL DEFAULT false
  53. ) SERVER multicorn_es
  54. OPTIONS
  55. (
  56. host '192.168.207.94',
  57. port '9200',
  58. index 'user-es-index',
  59. rowid_column 'id',
  60. default_sort '_id'
  61. )
  62. ;
  63. delete from public.user_es;
  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. SELECT
  108. id,
  109. lower_name,
  110. name,
  111. full_name,
  112. email,
  113. keep_email_private,
  114. email_notifications_preference,
  115. must_change_password,
  116. login_type,
  117. login_source,
  118. login_name,
  119. type,
  120. location,
  121. website,
  122. rands,
  123. language,
  124. description,
  125. created_unix,
  126. updated_unix,
  127. last_login_unix,
  128. last_repo_visibility,
  129. max_repo_creation,
  130. is_active,
  131. is_restricted,
  132. allow_git_hook,
  133. allow_import_local,
  134. allow_create_organization,
  135. prohibit_login,
  136. avatar,
  137. avatar_email,
  138. use_custom_avatar,
  139. num_followers,
  140. num_following,
  141. num_stars,
  142. num_repos,
  143. num_teams,
  144. num_members,
  145. visibility,
  146. repo_admin_change_team_access,
  147. diff_view_style,
  148. theme,
  149. is_operator
  150. FROM public.user;
  151. CREATE OR REPLACE FUNCTION public.insert_user_data() RETURNS trigger AS
  152. $def$
  153. BEGIN
  154. INSERT INTO public."user_es"(
  155. id,
  156. lower_name,
  157. name,
  158. full_name,
  159. email,
  160. keep_email_private,
  161. email_notifications_preference,
  162. must_change_password,
  163. login_type,
  164. login_source,
  165. login_name,
  166. type,
  167. location,
  168. website,
  169. rands,
  170. language,
  171. description,
  172. created_unix,
  173. updated_unix,
  174. last_login_unix,
  175. last_repo_visibility,
  176. max_repo_creation,
  177. is_active,
  178. is_restricted,
  179. allow_git_hook,
  180. allow_import_local,
  181. allow_create_organization,
  182. prohibit_login,
  183. avatar,
  184. avatar_email,
  185. use_custom_avatar,
  186. num_followers,
  187. num_following,
  188. num_stars,
  189. num_repos,
  190. num_teams,
  191. num_members,
  192. visibility,
  193. repo_admin_change_team_access,
  194. diff_view_style,
  195. theme,
  196. is_operator)
  197. VALUES (
  198. NEW.id,
  199. NEW.lower_name,
  200. NEW.name,
  201. NEW.full_name,
  202. NEW.email,
  203. NEW.keep_email_private,
  204. NEW.email_notifications_preference,
  205. NEW.must_change_password,
  206. NEW.login_type,
  207. NEW.login_source,
  208. NEW.login_name,
  209. NEW.type,
  210. NEW.location,
  211. NEW.website,
  212. NEW.rands,
  213. NEW.language,
  214. NEW.description,
  215. NEW.created_unix,
  216. NEW.updated_unix,
  217. NEW.last_login_unix,
  218. NEW.last_repo_visibility,
  219. NEW.max_repo_creation,
  220. NEW.is_active,
  221. NEW.is_restricted,
  222. NEW.allow_git_hook,
  223. NEW.allow_import_local,
  224. NEW.allow_create_organization,
  225. NEW.prohibit_login,
  226. NEW.avatar,
  227. NEW.avatar_email,
  228. NEW.use_custom_avatar,
  229. NEW.num_followers,
  230. NEW.num_following,
  231. NEW.num_stars,
  232. NEW.num_repos,
  233. NEW.num_teams,
  234. NEW.num_members,
  235. NEW.visibility,
  236. NEW.repo_admin_change_team_access,
  237. NEW.diff_view_style,
  238. NEW.theme,
  239. NEW.is_operator
  240. );
  241. RETURN NEW;
  242. END;
  243. $def$
  244. LANGUAGE plpgsql;
  245. DROP TRIGGER IF EXISTS es_insert_user on public.user;
  246. CREATE TRIGGER es_insert_user
  247. AFTER INSERT ON public.user
  248. FOR EACH ROW EXECUTE PROCEDURE insert_user_data();
  249. ALTER TABLE public.user ENABLE ALWAYS TRIGGER es_insert_user;
  250. CREATE OR REPLACE FUNCTION public.update_user() RETURNS trigger AS
  251. $def$
  252. BEGIN
  253. UPDATE public.user_es
  254. SET description=NEW.description,
  255. name=NEW.name,
  256. full_name=NEW.full_name,
  257. location=NEW.location,
  258. website=NEW.website,
  259. email=NEW.email
  260. where id=NEW.id;
  261. return new;
  262. END
  263. $def$
  264. LANGUAGE plpgsql;
  265. DROP TRIGGER IF EXISTS es_update_user on public.user;
  266. CREATE TRIGGER es_update_user
  267. AFTER UPDATE ON public.user
  268. FOR EACH ROW EXECUTE PROCEDURE update_user();
  269. ALTER TABLE public.user ENABLE ALWAYS TRIGGER es_update_user;
  270. CREATE OR REPLACE FUNCTION public.delete_user() RETURNS trigger AS
  271. $def$
  272. declare
  273. BEGIN
  274. DELETE FROM public.user_es where id=OLD.id;
  275. return new;
  276. END
  277. $def$
  278. LANGUAGE plpgsql;
  279. DROP TRIGGER IF EXISTS es_delete_user on public.user;
  280. CREATE TRIGGER es_delete_user
  281. AFTER DELETE ON public.user
  282. FOR EACH ROW EXECUTE PROCEDURE delete_user();
  283. ALTER TABLE public.user ENABLE ALWAYS TRIGGER es_delete_user;