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

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