dolphinscheduler_ddl.sql 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. -- uc_dolphin_T_t_ds_user_A_state
  18. delimiter ;
  19. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_user_A_state();
  20. delimiter d//
  21. CREATE FUNCTION uc_dolphin_T_t_ds_user_A_state() RETURNS void AS $$
  22. BEGIN
  23. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  24. WHERE TABLE_CATALOG=current_database()
  25. AND TABLE_SCHEMA=current_schema()
  26. AND TABLE_NAME='t_ds_user'
  27. AND COLUMN_NAME ='state')
  28. THEN
  29. ALTER TABLE t_ds_user ADD COLUMN state int DEFAULT 1;
  30. comment on column t_ds_user.state is 'state 0:disable 1:enable';
  31. END IF;
  32. END;
  33. $$ LANGUAGE plpgsql;
  34. d//
  35. delimiter ;
  36. select uc_dolphin_T_t_ds_user_A_state();
  37. DROP FUNCTION uc_dolphin_T_t_ds_user_A_state();
  38. -- uc_dolphin_T_t_ds_tenant_A_tenant_name
  39. delimiter ;
  40. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_tenant_A_tenant_name();
  41. delimiter d//
  42. CREATE FUNCTION uc_dolphin_T_t_ds_tenant_A_tenant_name() RETURNS void AS $$
  43. BEGIN
  44. IF EXISTS (SELECT 1 FROM information_schema.COLUMNS
  45. WHERE TABLE_CATALOG=current_database()
  46. AND TABLE_SCHEMA=current_schema()
  47. AND TABLE_NAME='t_ds_tenant'
  48. AND COLUMN_NAME ='tenant_name')
  49. THEN
  50. ALTER TABLE t_ds_tenant DROP COLUMN "tenant_name";
  51. END IF;
  52. END;
  53. $$ LANGUAGE plpgsql;
  54. d//
  55. delimiter ;
  56. select uc_dolphin_T_t_ds_tenant_A_tenant_name();
  57. DROP FUNCTION uc_dolphin_T_t_ds_tenant_A_tenant_name();
  58. -- uc_dolphin_T_t_ds_task_instance_A_first_submit_time
  59. delimiter d//
  60. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_task_instance_A_first_submit_time() RETURNS void AS $$
  61. BEGIN
  62. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  63. WHERE TABLE_NAME='t_ds_task_instance'
  64. AND COLUMN_NAME ='first_submit_time')
  65. THEN
  66. ALTER TABLE t_ds_task_instance ADD COLUMN first_submit_time timestamp DEFAULT NULL;
  67. END IF;
  68. END;
  69. $$ LANGUAGE plpgsql;
  70. d//
  71. delimiter ;
  72. SELECT uc_dolphin_T_t_ds_task_instance_A_first_submit_time();
  73. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_task_instance_A_first_submit_time();
  74. -- uc_dolphin_T_t_ds_task_instance_A_delay_time
  75. delimiter d//
  76. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_task_instance_A_delay_time() RETURNS void AS $$
  77. BEGIN
  78. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  79. WHERE TABLE_NAME='t_ds_task_instance'
  80. AND COLUMN_NAME ='delay_time')
  81. THEN
  82. ALTER TABLE t_ds_task_instance ADD COLUMN delay_time int DEFAULT '0';
  83. END IF;
  84. END;
  85. $$ LANGUAGE plpgsql;
  86. d//
  87. delimiter ;
  88. SELECT uc_dolphin_T_t_ds_task_instance_A_delay_time();
  89. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_task_instance_A_delay_time();
  90. -- uc_dolphin_T_t_ds_task_instance_A_var_pool
  91. delimiter d//
  92. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_task_instance_A_var_pool() RETURNS void AS $$
  93. BEGIN
  94. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  95. WHERE TABLE_NAME='t_ds_task_instance'
  96. AND COLUMN_NAME ='var_pool')
  97. THEN
  98. ALTER TABLE t_ds_task_instance ADD COLUMN var_pool text;
  99. END IF;
  100. END;
  101. $$ LANGUAGE plpgsql;
  102. d//
  103. delimiter ;
  104. SELECT uc_dolphin_T_t_ds_task_instance_A_var_pool();
  105. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_task_instance_A_var_pool();
  106. -- uc_dolphin_T_t_ds_task_instance_A_task_code
  107. delimiter d//
  108. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_task_instance_A_task_code() RETURNS void AS $$
  109. BEGIN
  110. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  111. WHERE TABLE_NAME='t_ds_task_instance'
  112. AND COLUMN_NAME ='task_code')
  113. THEN
  114. ALTER TABLE t_ds_task_instance ADD COLUMN task_code bigint NOT NULL;
  115. END IF;
  116. END;
  117. $$ LANGUAGE plpgsql;
  118. d//
  119. delimiter ;
  120. SELECT uc_dolphin_T_t_ds_task_instance_A_task_code();
  121. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_task_instance_A_task_code();
  122. -- uc_dolphin_T_t_ds_task_instance_A_task_definition_version
  123. delimiter d//
  124. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_task_instance_A_task_definition_version() RETURNS void AS $$
  125. BEGIN
  126. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  127. WHERE TABLE_NAME='t_ds_task_instance'
  128. AND COLUMN_NAME ='task_definition_version')
  129. THEN
  130. ALTER TABLE t_ds_task_instance ADD COLUMN task_definition_version int DEFAULT NULL;
  131. END IF;
  132. END;
  133. $$ LANGUAGE plpgsql;
  134. d//
  135. delimiter ;
  136. SELECT uc_dolphin_T_t_ds_task_instance_A_task_definition_version();
  137. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_task_instance_A_task_definition_version();
  138. -- uc_dolphin_T_t_ds_task_instance_A_task_params
  139. delimiter d//
  140. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_task_instance_A_task_params() RETURNS void AS $$
  141. BEGIN
  142. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  143. WHERE TABLE_NAME='t_ds_task_instance'
  144. AND COLUMN_NAME ='task_params')
  145. THEN
  146. ALTER TABLE t_ds_task_instance ADD COLUMN task_params text;
  147. END IF;
  148. END;
  149. $$ LANGUAGE plpgsql;
  150. d//
  151. delimiter ;
  152. SELECT uc_dolphin_T_t_ds_task_instance_A_task_params();
  153. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_task_instance_A_task_params();
  154. -- uc_dolphin_T_t_ds_process_instance_A_process_definition_code
  155. delimiter d//
  156. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_instance_A_process_definition_code() RETURNS void AS $$
  157. BEGIN
  158. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  159. WHERE TABLE_NAME='t_ds_process_instance'
  160. AND COLUMN_NAME ='process_definition_code')
  161. THEN
  162. ALTER TABLE t_ds_process_instance ADD COLUMN process_definition_code bigint DEFAULT NULL;
  163. END IF;
  164. END;
  165. $$ LANGUAGE plpgsql;
  166. d//
  167. delimiter ;
  168. SELECT uc_dolphin_T_t_ds_process_instance_A_process_definition_code();
  169. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_instance_A_process_definition_code();
  170. -- uc_dolphin_T_t_ds_process_instance_A_process_definition_version
  171. delimiter d//
  172. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_instance_A_process_definition_version() RETURNS void AS $$
  173. BEGIN
  174. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  175. WHERE TABLE_NAME='t_ds_process_instance'
  176. AND COLUMN_NAME ='process_definition_version')
  177. THEN
  178. ALTER TABLE t_ds_process_instance ADD COLUMN process_definition_version int DEFAULT NULL;
  179. END IF;
  180. END;
  181. $$ LANGUAGE plpgsql;
  182. d//
  183. delimiter ;
  184. SELECT uc_dolphin_T_t_ds_process_instance_A_process_definition_version();
  185. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_instance_A_process_definition_version();
  186. -- uc_dolphin_T_t_ds_process_instance_A_var_pool
  187. delimiter d//
  188. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_instance_A_var_pool() RETURNS void AS $$
  189. BEGIN
  190. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  191. WHERE TABLE_NAME='t_ds_process_instance'
  192. AND COLUMN_NAME ='var_pool')
  193. THEN
  194. ALTER TABLE t_ds_process_instance ADD COLUMN var_pool text;
  195. END IF;
  196. END;
  197. $$ LANGUAGE plpgsql;
  198. d//
  199. delimiter ;
  200. SELECT uc_dolphin_T_t_ds_process_instance_A_var_pool();
  201. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_instance_A_var_pool();
  202. -- uc_dolphin_T_t_ds_project_A_code
  203. delimiter d//
  204. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_project_A_code() RETURNS void AS $$
  205. BEGIN
  206. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  207. WHERE TABLE_NAME='t_ds_project'
  208. AND COLUMN_NAME ='code')
  209. THEN
  210. ALTER TABLE t_ds_project ADD COLUMN code bigint NOT NULL;
  211. END IF;
  212. END;
  213. $$ LANGUAGE plpgsql;
  214. d//
  215. delimiter ;
  216. SELECT uc_dolphin_T_t_ds_project_A_code();
  217. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_project_A_code();
  218. -- uc_dolphin_T_t_ds_process_definition_A_code
  219. delimiter d//
  220. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_definition_A_code() RETURNS void AS $$
  221. BEGIN
  222. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  223. WHERE TABLE_NAME='t_ds_process_definition'
  224. AND COLUMN_NAME ='code')
  225. THEN
  226. ALTER TABLE t_ds_process_definition ADD COLUMN code bigint NOT NULL;
  227. ALTER TABLE t_ds_process_definition ADD CONSTRAINT code_unique UNIQUE (code);
  228. END IF;
  229. END;
  230. $$ LANGUAGE plpgsql;
  231. d//
  232. delimiter ;
  233. SELECT uc_dolphin_T_t_ds_process_definition_A_code();
  234. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_definition_A_code();
  235. -- uc_dolphin_T_t_ds_process_definition_A_project_code
  236. delimiter d//
  237. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_definition_A_project_code() RETURNS void AS $$
  238. BEGIN
  239. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  240. WHERE TABLE_NAME='t_ds_process_definition'
  241. AND COLUMN_NAME ='project_code')
  242. THEN
  243. ALTER TABLE t_ds_process_definition ADD COLUMN project_code bigint NOT NULL;
  244. ALTER TABLE t_ds_process_definition DROP CONSTRAINT process_definition_unique, ADD CONSTRAINT process_definition_unique UNIQUE (name, project_code);
  245. ALTER TABLE t_ds_process_definition DROP project_id, DROP process_definition_json, DROP receivers, DROP receivers_cc, DROP modify_by, DROP resource_ids;
  246. END IF;
  247. END;
  248. $$ LANGUAGE plpgsql;
  249. d//
  250. delimiter ;
  251. SELECT uc_dolphin_T_t_ds_process_definition_A_project_code();
  252. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_definition_A_project_code();
  253. -- uc_dolphin_T_t_ds_process_definition_A_modify_by
  254. delimiter d//
  255. CREATE OR REPLACE FUNCTION ct_dolphin_T_t_ds_process_definition_version() RETURNS void AS $$
  256. BEGIN
  257. CREATE TABLE IF NOT EXISTS t_ds_process_definition_version (
  258. id int NOT NULL ,
  259. process_definition_id int NOT NULL ,
  260. version int DEFAULT NULL ,
  261. process_definition_json text ,
  262. description text ,
  263. global_params text ,
  264. locations text ,
  265. connects text ,
  266. receivers text ,
  267. receivers_cc text ,
  268. create_time timestamp DEFAULT NULL ,
  269. timeout int DEFAULT '0' ,
  270. resource_ids varchar(64),
  271. PRIMARY KEY (id)
  272. ) ;
  273. create index process_definition_id_and_version on t_ds_process_definition_version (process_definition_id,version);
  274. DROP SEQUENCE IF EXISTS t_ds_process_definition_version_id_sequence;
  275. CREATE SEQUENCE t_ds_process_definition_version_id_sequence;
  276. ALTER TABLE t_ds_process_definition_version ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_process_definition_version_id_sequence');
  277. END;
  278. $$ LANGUAGE plpgsql;
  279. d//
  280. delimiter ;
  281. SELECT ct_dolphin_T_t_ds_process_definition_version();
  282. DROP FUNCTION IF EXISTS ct_dolphin_T_t_ds_process_definition_version();
  283. -- ct_dolphin_T_t_ds_task_definition
  284. delimiter d//
  285. CREATE OR REPLACE FUNCTION ct_dolphin_T_t_ds_task_definition() RETURNS void AS $$
  286. BEGIN
  287. CREATE TABLE IF NOT EXISTS t_ds_task_definition (
  288. id int NOT NULL ,
  289. code bigint NOT NULL,
  290. name varchar(255) DEFAULT NULL ,
  291. version int DEFAULT NULL ,
  292. description text ,
  293. project_code bigint DEFAULT NULL ,
  294. user_id int DEFAULT NULL ,
  295. task_type varchar(50) DEFAULT NULL ,
  296. task_params text ,
  297. flag int DEFAULT NULL ,
  298. task_priority int DEFAULT NULL ,
  299. worker_group varchar(255) DEFAULT NULL ,
  300. fail_retry_times int DEFAULT NULL ,
  301. fail_retry_interval int DEFAULT NULL ,
  302. timeout_flag int DEFAULT NULL ,
  303. timeout_notify_strategy int DEFAULT NULL ,
  304. timeout int DEFAULT '0' ,
  305. delay_time int DEFAULT '0' ,
  306. resource_ids varchar(255) DEFAULT NULL ,
  307. create_time timestamp DEFAULT NULL ,
  308. update_time timestamp DEFAULT NULL ,
  309. PRIMARY KEY (id) ,
  310. CONSTRAINT task_definition_unique UNIQUE (name, project_code)
  311. ) ;
  312. create index task_definition_index on t_ds_task_definition (project_code,id);
  313. DROP SEQUENCE IF EXISTS t_ds_task_definition_id_sequence;
  314. CREATE SEQUENCE t_ds_task_definition_id_sequence;
  315. ALTER TABLE t_ds_task_definition ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_task_definition_id_sequence');
  316. END;
  317. $$ LANGUAGE plpgsql;
  318. d//
  319. delimiter ;
  320. SELECT ct_dolphin_T_t_ds_task_definition();
  321. DROP FUNCTION IF EXISTS ct_dolphin_T_t_ds_task_definition();
  322. -- ct_dolphin_T_t_ds_task_definition_log
  323. delimiter d//
  324. CREATE OR REPLACE FUNCTION ct_dolphin_T_t_ds_task_definition_log() RETURNS void AS $$
  325. BEGIN
  326. CREATE TABLE IF NOT EXISTS t_ds_task_definition_log (
  327. id int NOT NULL ,
  328. code bigint NOT NULL,
  329. name varchar(255) DEFAULT NULL ,
  330. version int DEFAULT NULL ,
  331. description text ,
  332. project_code bigint DEFAULT NULL ,
  333. user_id int DEFAULT NULL ,
  334. task_type varchar(50) DEFAULT NULL ,
  335. task_params text ,
  336. flag int DEFAULT NULL ,
  337. task_priority int DEFAULT NULL ,
  338. worker_group varchar(255) DEFAULT NULL ,
  339. fail_retry_times int DEFAULT NULL ,
  340. fail_retry_interval int DEFAULT NULL ,
  341. timeout_flag int DEFAULT NULL ,
  342. timeout_notify_strategy int DEFAULT NULL ,
  343. timeout int DEFAULT '0' ,
  344. delay_time int DEFAULT '0' ,
  345. resource_ids varchar(255) DEFAULT NULL ,
  346. operator int DEFAULT NULL ,
  347. operate_time timestamp DEFAULT NULL ,
  348. create_time timestamp DEFAULT NULL ,
  349. update_time timestamp DEFAULT NULL ,
  350. PRIMARY KEY (id)
  351. ) ;
  352. DROP SEQUENCE IF EXISTS t_ds_task_definition_log_id_sequence;
  353. CREATE SEQUENCE t_ds_task_definition_log_id_sequence;
  354. ALTER TABLE t_ds_task_definition_log ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_task_definition_log_id_sequence');
  355. END;
  356. $$ LANGUAGE plpgsql;
  357. d//
  358. delimiter ;
  359. SELECT ct_dolphin_T_t_ds_task_definition_log();
  360. DROP FUNCTION IF EXISTS ct_dolphin_T_t_ds_task_definition_log();
  361. -- ct_dolphin_T_t_ds_process_task_relation
  362. delimiter d//
  363. CREATE OR REPLACE FUNCTION ct_dolphin_T_t_ds_process_task_relation() RETURNS void AS $$
  364. BEGIN
  365. CREATE TABLE IF NOT EXISTS t_ds_process_task_relation (
  366. id int NOT NULL ,
  367. name varchar(255) DEFAULT NULL ,
  368. process_definition_version int DEFAULT NULL ,
  369. project_code bigint DEFAULT NULL ,
  370. process_definition_code bigint DEFAULT NULL ,
  371. pre_task_code bigint DEFAULT NULL ,
  372. pre_task_version int DEFAULT '0' ,
  373. post_task_code bigint DEFAULT NULL ,
  374. post_task_version int DEFAULT '0' ,
  375. condition_type int DEFAULT NULL ,
  376. condition_params text ,
  377. create_time timestamp DEFAULT NULL ,
  378. update_time timestamp DEFAULT NULL ,
  379. PRIMARY KEY (id)
  380. ) ;
  381. DROP SEQUENCE IF EXISTS t_ds_process_task_relation_id_sequence;
  382. CREATE SEQUENCE t_ds_process_task_relation_id_sequence;
  383. ALTER TABLE t_ds_process_task_relation ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_process_task_relation_id_sequence');
  384. END;
  385. $$ LANGUAGE plpgsql;
  386. d//
  387. delimiter ;
  388. SELECT ct_dolphin_T_t_ds_process_task_relation();
  389. DROP FUNCTION IF EXISTS ct_dolphin_T_t_ds_process_task_relation();
  390. -- ct_dolphin_T_t_ds_process_definition_log
  391. delimiter d//
  392. CREATE OR REPLACE FUNCTION ct_dolphin_T_t_ds_process_definition_log() RETURNS void AS $$
  393. BEGIN
  394. CREATE TABLE IF NOT EXISTS t_ds_process_definition_log (
  395. id int NOT NULL ,
  396. code bigint NOT NULL,
  397. name varchar(255) DEFAULT NULL ,
  398. version int DEFAULT NULL ,
  399. description text ,
  400. project_code bigint DEFAULT NULL ,
  401. release_state int DEFAULT NULL ,
  402. user_id int DEFAULT NULL ,
  403. global_params text ,
  404. locations text ,
  405. connects text ,
  406. warning_group_id int DEFAULT NULL ,
  407. flag int DEFAULT NULL ,
  408. timeout int DEFAULT '0' ,
  409. tenant_id int DEFAULT '-1' ,
  410. operator int DEFAULT NULL ,
  411. operate_time timestamp DEFAULT NULL ,
  412. create_time timestamp DEFAULT NULL ,
  413. update_time timestamp DEFAULT NULL ,
  414. PRIMARY KEY (id)
  415. ) ;
  416. DROP SEQUENCE IF EXISTS t_ds_process_definition_log_id_sequence;
  417. CREATE SEQUENCE t_ds_process_definition_log_id_sequence;
  418. ALTER TABLE t_ds_process_definition_log ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_process_definition_log_id_sequence');
  419. END;
  420. $$ LANGUAGE plpgsql;
  421. d//
  422. delimiter ;
  423. SELECT ct_dolphin_T_t_ds_process_definition_log();
  424. DROP FUNCTION IF EXISTS ct_dolphin_T_t_ds_process_definition_log();
  425. -- ct_dolphin_T_t_ds_process_task_relation_log
  426. delimiter d//
  427. CREATE OR REPLACE FUNCTION ct_dolphin_T_t_ds_process_task_relation_log() RETURNS void AS $$
  428. BEGIN
  429. CREATE TABLE IF NOT EXISTS t_ds_process_task_relation_log (
  430. id int NOT NULL ,
  431. name varchar(255) DEFAULT NULL ,
  432. process_definition_version int DEFAULT NULL ,
  433. project_code bigint DEFAULT NULL ,
  434. process_definition_code bigint DEFAULT NULL ,
  435. pre_task_code bigint DEFAULT NULL ,
  436. pre_task_version int DEFAULT '0' ,
  437. post_task_code bigint DEFAULT NULL ,
  438. post_task_version int DEFAULT '0' ,
  439. condition_type int DEFAULT NULL ,
  440. condition_params text ,
  441. operator int DEFAULT NULL ,
  442. operate_time timestamp DEFAULT NULL ,
  443. create_time timestamp DEFAULT NULL ,
  444. update_time timestamp DEFAULT NULL ,
  445. PRIMARY KEY (id)
  446. ) ;
  447. DROP SEQUENCE IF EXISTS t_ds_process_task_relation_log_id_sequence;
  448. CREATE SEQUENCE t_ds_process_task_relation_log_id_sequence;
  449. ALTER TABLE t_ds_process_task_relation_log ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_process_task_relation_log_id_sequence');
  450. END;
  451. $$ LANGUAGE plpgsql;
  452. d//
  453. delimiter ;
  454. SELECT ct_dolphin_T_t_ds_process_task_relation_log();
  455. DROP FUNCTION IF EXISTS ct_dolphin_T_t_ds_process_task_relation_log();
  456. -- ----------------------------
  457. -- Table structure for t_ds_plugin_define
  458. -- ----------------------------
  459. DROP TABLE IF EXISTS t_ds_plugin_define;
  460. CREATE TABLE t_ds_plugin_define (
  461. id serial NOT NULL,
  462. plugin_name varchar(100) NOT NULL,
  463. plugin_type varchar(100) NOT NULL,
  464. plugin_params text NULL,
  465. create_time timestamp NULL,
  466. update_time timestamp NULL,
  467. CONSTRAINT t_ds_plugin_define_pk PRIMARY KEY (id),
  468. CONSTRAINT t_ds_plugin_define_un UNIQUE (plugin_name, plugin_type)
  469. );
  470. -- ----------------------------
  471. -- Table structure for t_ds_alert_plugin_instance
  472. -- ----------------------------
  473. DROP TABLE IF EXISTS t_ds_alert_plugin_instance;
  474. CREATE TABLE t_ds_alert_plugin_instance (
  475. id serial NOT NULL,
  476. plugin_define_id int4 NOT NULL,
  477. plugin_instance_params text NULL,
  478. create_time timestamp NULL,
  479. update_time timestamp NULL,
  480. instance_name varchar(200) NULL,
  481. CONSTRAINT t_ds_alert_plugin_instance_pk PRIMARY KEY (id)
  482. );
  483. -- uc_dolphin_T_t_ds_process_definition_A_warning_group_id
  484. delimiter d//
  485. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_definition_A_warning_group_id() RETURNS void AS $$
  486. BEGIN
  487. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  488. WHERE TABLE_NAME='t_ds_process_definition'
  489. AND COLUMN_NAME ='warning_group_id')
  490. THEN
  491. ALTER TABLE t_ds_process_definition ADD COLUMN warning_group_id int4 DEFAULT NULL;
  492. COMMENT ON COLUMN t_ds_process_definition.warning_group_id IS 'alert group id';
  493. END IF;
  494. END;
  495. $$ LANGUAGE plpgsql;
  496. d//
  497. delimiter ;
  498. SELECT uc_dolphin_T_t_ds_process_definition_A_warning_group_id();
  499. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_definition_A_warning_group_id();
  500. -- uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id
  501. delimiter d//
  502. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id() RETURNS void AS $$
  503. BEGIN
  504. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  505. WHERE TABLE_NAME='t_ds_process_definition_version'
  506. AND COLUMN_NAME ='warning_group_id')
  507. THEN
  508. ALTER TABLE t_ds_process_definition_version ADD COLUMN warning_group_id int4 DEFAULT NULL;
  509. COMMENT ON COLUMN t_ds_process_definition_version.warning_group_id IS 'alert group id';
  510. END IF;
  511. END;
  512. $$ LANGUAGE plpgsql;
  513. d//
  514. delimiter ;
  515. SELECT uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id();
  516. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id();
  517. -- uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids
  518. delimiter d//
  519. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids() RETURNS void AS $$
  520. BEGIN
  521. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  522. WHERE TABLE_NAME='t_ds_alertgroup'
  523. AND COLUMN_NAME ='alert_instance_ids')
  524. THEN
  525. ALTER TABLE t_ds_alertgroup ADD COLUMN alert_instance_ids varchar (255) DEFAULT NULL;
  526. COMMENT ON COLUMN t_ds_alertgroup.alert_instance_ids IS 'alert instance ids';
  527. END IF;
  528. END;
  529. $$ LANGUAGE plpgsql;
  530. d//
  531. delimiter ;
  532. SELECT uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids();
  533. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids();
  534. -- uc_dolphin_T_t_ds_alertgroup_A_create_user_id
  535. delimiter d//
  536. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_alertgroup_A_create_user_id() RETURNS void AS $$
  537. BEGIN
  538. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  539. WHERE TABLE_NAME='t_ds_alertgroup'
  540. AND COLUMN_NAME ='create_user_id')
  541. THEN
  542. ALTER TABLE t_ds_alertgroup ADD COLUMN create_user_id int4 DEFAULT NULL;
  543. COMMENT ON COLUMN t_ds_alertgroup.create_user_id IS 'create user id';
  544. END IF;
  545. END;
  546. $$ LANGUAGE plpgsql;
  547. d//
  548. delimiter ;
  549. SELECT uc_dolphin_T_t_ds_alertgroup_A_create_user_id();
  550. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_alertgroup_A_create_user_id();
  551. -- uc_dolphin_T_t_ds_alertgroup_A_add_UN_groupName
  552. delimiter d//
  553. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_alertgroup_A_add_UN_groupName() RETURNS void AS $$
  554. BEGIN
  555. IF NOT EXISTS (SELECT 1 FROM pg_stat_all_indexes
  556. WHERE relname='t_ds_alertgroup'
  557. AND indexrelname ='t_ds_alertgroup_name_un')
  558. THEN
  559. ALTER TABLE t_ds_alertgroup ADD CONSTRAINT t_ds_alertgroup_name_un UNIQUE (group_name);
  560. END IF;
  561. END;
  562. $$ LANGUAGE plpgsql;
  563. d//
  564. delimiter ;
  565. SELECT uc_dolphin_T_t_ds_alertgroup_A_add_UN_groupName();
  566. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_alertgroup_A_add_UN_groupName();
  567. -- uc_dolphin_T_t_ds_datasource_A_add_UN_datasourceName
  568. delimiter d//
  569. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_datasource_A_add_UN_datasourceName() RETURNS void AS $$
  570. BEGIN
  571. IF NOT EXISTS (SELECT 1 FROM pg_stat_all_indexes
  572. WHERE relname='t_ds_datasource'
  573. AND indexrelname ='t_ds_datasource_name_un')
  574. THEN
  575. ALTER TABLE t_ds_datasource ADD CONSTRAINT t_ds_datasource_name_un UNIQUE (name, type);
  576. END IF;
  577. END;
  578. $$ LANGUAGE plpgsql;
  579. d//
  580. delimiter ;
  581. SELECT uc_dolphin_T_t_ds_datasource_A_add_UN_datasourceName();
  582. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_datasource_A_add_UN_datasourceName();
  583. -- uc_dolphin_T_t_ds_schedules_A_add_timezone
  584. delimiter d//
  585. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_schedules_A_add_timezone() RETURNS void AS $$
  586. BEGIN
  587. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  588. WHERE TABLE_NAME='t_ds_schedules'
  589. AND COLUMN_NAME ='timezone_id')
  590. THEN
  591. ALTER TABLE t_ds_schedules ADD COLUMN timezone_id varchar(40) DEFAULT NULL;
  592. END IF;
  593. END;
  594. $$ LANGUAGE plpgsql;
  595. d//
  596. delimiter ;
  597. SELECT uc_dolphin_T_t_ds_schedules_A_add_timezone();
  598. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_schedules_A_add_timezone();
  599. -- ----------------------------
  600. -- These columns will not be used in the new version,if you determine that the historical data is useless, you can delete it using the sql below
  601. -- ----------------------------
  602. -- ALTER TABLE t_ds_alert DROP COLUMN "show_type", DROP COLUMN "alert_type", DROP COLUMN "receivers", DROP COLUMN "receivers_cc";
  603. -- ALTER TABLE t_ds_alertgroup DROP COLUMN "group_type";
  604. -- ALTER TABLE t_ds_process_definition DROP COLUMN "receivers", DROP COLUMN "receivers_cc";
  605. -- ALTER TABLE t_ds_process_definition_version DROP COLUMN "receivers", DROP COLUMN "receivers_cc";
  606. -- DROP TABLE IF EXISTS t_ds_relation_user_alertgroup;
  607. -- ALTER TABLE t_ds_command DROP COLUMN "dependence";
  608. -- ALTER TABLE t_ds_error_command DROP COLUMN "dependence";