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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. num_dataset_stars integer NOT NULL DEFAULT 0
  54. ) SERVER multicorn_es
  55. OPTIONS
  56. (
  57. host '192.168.207.94',
  58. port '9200',
  59. index 'user-es-index',
  60. rowid_column 'id',
  61. default_sort '_id'
  62. )
  63. ;
  64. delete from public.user_es;
  65. INSERT INTO public.user_es(
  66. id,
  67. lower_name,
  68. name,
  69. full_name,
  70. email,
  71. keep_email_private,
  72. email_notifications_preference,
  73. must_change_password,
  74. login_type,
  75. login_source,
  76. login_name,
  77. type,
  78. location,
  79. website,
  80. rands,
  81. language,
  82. description,
  83. created_unix,
  84. updated_unix,
  85. last_login_unix,
  86. last_repo_visibility,
  87. max_repo_creation,
  88. is_active,
  89. is_restricted,
  90. allow_git_hook,
  91. allow_import_local,
  92. allow_create_organization,
  93. prohibit_login,
  94. avatar,
  95. avatar_email,
  96. use_custom_avatar,
  97. num_followers,
  98. num_following,
  99. num_stars,
  100. num_repos,
  101. num_teams,
  102. num_members,
  103. visibility,
  104. repo_admin_change_team_access,
  105. diff_view_style,
  106. theme,
  107. is_operator,
  108. num_dataset_stars)
  109. SELECT
  110. id,
  111. lower_name,
  112. name,
  113. full_name,
  114. email,
  115. keep_email_private,
  116. email_notifications_preference,
  117. must_change_password,
  118. login_type,
  119. login_source,
  120. login_name,
  121. type,
  122. location,
  123. website,
  124. rands,
  125. language,
  126. description,
  127. created_unix,
  128. updated_unix,
  129. last_login_unix,
  130. last_repo_visibility,
  131. max_repo_creation,
  132. is_active,
  133. is_restricted,
  134. allow_git_hook,
  135. allow_import_local,
  136. allow_create_organization,
  137. prohibit_login,
  138. avatar,
  139. avatar_email,
  140. use_custom_avatar,
  141. num_followers,
  142. num_following,
  143. num_stars,
  144. num_repos,
  145. num_teams,
  146. num_members,
  147. visibility,
  148. repo_admin_change_team_access,
  149. diff_view_style,
  150. theme,
  151. is_operator,
  152. num_dataset_stars
  153. FROM public.user;
  154. DROP TRIGGER IF EXISTS es_insert_user on public.user;
  155. CREATE OR REPLACE FUNCTION public.insert_user_data() RETURNS trigger AS
  156. $def$
  157. BEGIN
  158. INSERT INTO public."user_es"(
  159. id,
  160. lower_name,
  161. name,
  162. full_name,
  163. email,
  164. keep_email_private,
  165. email_notifications_preference,
  166. must_change_password,
  167. login_type,
  168. login_source,
  169. login_name,
  170. type,
  171. location,
  172. website,
  173. rands,
  174. language,
  175. description,
  176. created_unix,
  177. updated_unix,
  178. last_login_unix,
  179. last_repo_visibility,
  180. max_repo_creation,
  181. is_active,
  182. is_restricted,
  183. allow_git_hook,
  184. allow_import_local,
  185. allow_create_organization,
  186. prohibit_login,
  187. avatar,
  188. avatar_email,
  189. use_custom_avatar,
  190. num_followers,
  191. num_following,
  192. num_stars,
  193. num_repos,
  194. num_teams,
  195. num_members,
  196. visibility,
  197. repo_admin_change_team_access,
  198. diff_view_style,
  199. theme,
  200. is_operator,
  201. num_dataset_stars)
  202. VALUES (
  203. NEW.id,
  204. NEW.lower_name,
  205. NEW.name,
  206. NEW.full_name,
  207. NEW.email,
  208. NEW.keep_email_private,
  209. NEW.email_notifications_preference,
  210. NEW.must_change_password,
  211. NEW.login_type,
  212. NEW.login_source,
  213. NEW.login_name,
  214. NEW.type,
  215. NEW.location,
  216. NEW.website,
  217. NEW.rands,
  218. NEW.language,
  219. NEW.description,
  220. NEW.created_unix,
  221. NEW.updated_unix,
  222. NEW.last_login_unix,
  223. NEW.last_repo_visibility,
  224. NEW.max_repo_creation,
  225. NEW.is_active,
  226. NEW.is_restricted,
  227. NEW.allow_git_hook,
  228. NEW.allow_import_local,
  229. NEW.allow_create_organization,
  230. NEW.prohibit_login,
  231. NEW.avatar,
  232. NEW.avatar_email,
  233. NEW.use_custom_avatar,
  234. NEW.num_followers,
  235. NEW.num_following,
  236. NEW.num_stars,
  237. NEW.num_repos,
  238. NEW.num_teams,
  239. NEW.num_members,
  240. NEW.visibility,
  241. NEW.repo_admin_change_team_access,
  242. NEW.diff_view_style,
  243. NEW.theme,
  244. NEW.is_operator,
  245. NEW.num_dataset_stars
  246. );
  247. RETURN NEW;
  248. END;
  249. $def$
  250. LANGUAGE plpgsql;
  251. CREATE TRIGGER es_insert_user
  252. AFTER INSERT ON public.user
  253. FOR EACH ROW EXECUTE PROCEDURE insert_user_data();
  254. ALTER TABLE public.user ENABLE ALWAYS TRIGGER es_insert_user;
  255. DROP TRIGGER IF EXISTS es_update_user on public.user;
  256. CREATE OR REPLACE FUNCTION public.update_user() RETURNS trigger AS
  257. $def$
  258. BEGIN
  259. UPDATE public.user_es
  260. SET description=NEW.description,
  261. name=NEW.name,
  262. full_name=NEW.full_name,
  263. location=NEW.location,
  264. website=NEW.website,
  265. email=NEW.email,
  266. num_dataset_stars=NEW.num_dataset_stars,
  267. updated_unix=NEW.updated_unix
  268. where id=NEW.id;
  269. return new;
  270. END
  271. $def$
  272. LANGUAGE plpgsql;
  273. CREATE TRIGGER es_update_user
  274. AFTER UPDATE ON public.user
  275. FOR EACH ROW EXECUTE PROCEDURE update_user();
  276. ALTER TABLE public.user ENABLE ALWAYS TRIGGER es_update_user;
  277. DROP TRIGGER IF EXISTS es_delete_user on public.user;
  278. CREATE OR REPLACE FUNCTION public.delete_user() RETURNS trigger AS
  279. $def$
  280. declare
  281. BEGIN
  282. DELETE FROM public.user_es where id=OLD.id;
  283. return new;
  284. END
  285. $def$
  286. LANGUAGE plpgsql;
  287. CREATE TRIGGER es_delete_user
  288. AFTER DELETE ON public.user
  289. FOR EACH ROW EXECUTE PROCEDURE delete_user();
  290. ALTER TABLE public.user ENABLE ALWAYS TRIGGER es_delete_user;