dolphinscheduler_ddl.sql 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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_process_instance_A_var_pool
  107. delimiter d//
  108. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_instance_A_var_pool() RETURNS void AS $$
  109. BEGIN
  110. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  111. WHERE TABLE_NAME='t_ds_process_instance'
  112. AND COLUMN_NAME ='var_pool')
  113. THEN
  114. ALTER TABLE t_ds_process_instance ADD COLUMN var_pool text;
  115. END IF;
  116. END;
  117. $$ LANGUAGE plpgsql;
  118. d//
  119. delimiter ;
  120. SELECT uc_dolphin_T_t_ds_process_instance_A_var_pool();
  121. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_instance_A_var_pool();
  122. -- uc_dolphin_T_t_ds_process_definition_A_modify_by
  123. delimiter d//
  124. CREATE OR REPLACE FUNCTION ct_dolphin_T_t_ds_process_definition_version() RETURNS void AS $$
  125. BEGIN
  126. CREATE TABLE IF NOT EXISTS t_ds_process_definition_version (
  127. id int NOT NULL ,
  128. process_definition_id int NOT NULL ,
  129. version int DEFAULT NULL ,
  130. process_definition_json text ,
  131. description text ,
  132. global_params text ,
  133. locations text ,
  134. connects text ,
  135. receivers text ,
  136. receivers_cc text ,
  137. create_time timestamp DEFAULT NULL ,
  138. timeout int DEFAULT '0' ,
  139. resource_ids varchar(64),
  140. PRIMARY KEY (id)
  141. ) ;
  142. create index process_definition_id_and_version on t_ds_process_definition_version (process_definition_id,version);
  143. DROP SEQUENCE IF EXISTS t_ds_process_definition_version_id_sequence;
  144. CREATE SEQUENCE t_ds_process_definition_version_id_sequence;
  145. ALTER TABLE t_ds_process_definition_version ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_process_definition_version_id_sequence');
  146. END;
  147. $$ LANGUAGE plpgsql;
  148. d//
  149. delimiter ;
  150. SELECT ct_dolphin_T_t_ds_process_definition_version();
  151. DROP FUNCTION IF EXISTS ct_dolphin_T_t_ds_process_definition_version();
  152. -- ----------------------------
  153. -- Table structure for t_ds_plugin_define
  154. -- ----------------------------
  155. DROP TABLE IF EXISTS t_ds_plugin_define;
  156. CREATE TABLE t_ds_plugin_define (
  157. id serial NOT NULL,
  158. plugin_name varchar(100) NOT NULL,
  159. plugin_type varchar(100) NOT NULL,
  160. plugin_params text NULL,
  161. create_time timestamp NULL,
  162. update_time timestamp NULL,
  163. CONSTRAINT t_ds_plugin_define_pk PRIMARY KEY (id),
  164. CONSTRAINT t_ds_plugin_define_un UNIQUE (plugin_name, plugin_type)
  165. );
  166. -- ----------------------------
  167. -- Table structure for t_ds_alert_plugin_instance
  168. -- ----------------------------
  169. DROP TABLE IF EXISTS t_ds_alert_plugin_instance;
  170. CREATE TABLE t_ds_alert_plugin_instance (
  171. id serial NOT NULL,
  172. plugin_define_id int4 NOT NULL,
  173. plugin_instance_params text NULL,
  174. create_time timestamp NULL,
  175. update_time timestamp NULL,
  176. instance_name varchar(200) NULL,
  177. CONSTRAINT t_ds_alert_plugin_instance_pk PRIMARY KEY (id)
  178. );
  179. -- uc_dolphin_T_t_ds_process_definition_A_warning_group_id
  180. delimiter d//
  181. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_definition_A_warning_group_id() RETURNS void AS $$
  182. BEGIN
  183. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  184. WHERE TABLE_NAME='t_ds_process_definition'
  185. AND COLUMN_NAME ='warning_group_id')
  186. THEN
  187. ALTER TABLE t_ds_process_definition ADD COLUMN warning_group_id int4 DEFAULT NULL;
  188. COMMENT ON COLUMN t_ds_process_definition.warning_group_id IS 'alert group id';
  189. END IF;
  190. END;
  191. $$ LANGUAGE plpgsql;
  192. d//
  193. delimiter ;
  194. SELECT uc_dolphin_T_t_ds_process_definition_A_warning_group_id();
  195. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_definition_A_warning_group_id();
  196. -- uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id
  197. delimiter d//
  198. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id() RETURNS void AS $$
  199. BEGIN
  200. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  201. WHERE TABLE_NAME='t_ds_process_definition_version'
  202. AND COLUMN_NAME ='warning_group_id')
  203. THEN
  204. ALTER TABLE t_ds_process_definition_version ADD COLUMN warning_group_id int4 DEFAULT NULL;
  205. COMMENT ON COLUMN t_ds_process_definition_version.warning_group_id IS 'alert group id';
  206. END IF;
  207. END;
  208. $$ LANGUAGE plpgsql;
  209. d//
  210. delimiter ;
  211. SELECT uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id();
  212. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id();
  213. -- uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids
  214. delimiter d//
  215. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids() RETURNS void AS $$
  216. BEGIN
  217. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  218. WHERE TABLE_NAME='t_ds_alertgroup'
  219. AND COLUMN_NAME ='alert_instance_ids')
  220. THEN
  221. ALTER TABLE t_ds_alertgroup ADD COLUMN alert_instance_ids varchar (255) DEFAULT NULL;
  222. COMMENT ON COLUMN t_ds_alertgroup.alert_instance_ids IS 'alert instance ids';
  223. END IF;
  224. END;
  225. $$ LANGUAGE plpgsql;
  226. d//
  227. delimiter ;
  228. SELECT uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids();
  229. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids();
  230. -- uc_dolphin_T_t_ds_alertgroup_A_create_user_id
  231. delimiter d//
  232. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_alertgroup_A_create_user_id() RETURNS void AS $$
  233. BEGIN
  234. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  235. WHERE TABLE_NAME='t_ds_alertgroup'
  236. AND COLUMN_NAME ='create_user_id')
  237. THEN
  238. ALTER TABLE t_ds_alertgroup ADD COLUMN create_user_id int4 DEFAULT NULL;
  239. COMMENT ON COLUMN t_ds_alertgroup.create_user_id IS 'create user id';
  240. END IF;
  241. END;
  242. $$ LANGUAGE plpgsql;
  243. d//
  244. delimiter ;
  245. SELECT uc_dolphin_T_t_ds_alertgroup_A_create_user_id();
  246. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_alertgroup_A_create_user_id();
  247. -- uc_dolphin_T_t_ds_alertgroup_A_add_UN_groupName
  248. delimiter d//
  249. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_alertgroup_A_add_UN_groupName() RETURNS void AS $$
  250. BEGIN
  251. IF NOT EXISTS (SELECT 1 FROM pg_stat_all_indexes
  252. WHERE relname='t_ds_alertgroup'
  253. AND indexrelname ='t_ds_alertgroup_name_un')
  254. THEN
  255. ALTER TABLE t_ds_alertgroup ADD CONSTRAINT t_ds_alertgroup_name_un UNIQUE (group_name);
  256. END IF;
  257. END;
  258. $$ LANGUAGE plpgsql;
  259. d//
  260. delimiter ;
  261. SELECT uc_dolphin_T_t_ds_alertgroup_A_add_UN_groupName();
  262. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_alertgroup_A_add_UN_groupName();
  263. -- uc_dolphin_T_t_ds_datasource_A_add_UN_datasourceName
  264. delimiter d//
  265. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_datasource_A_add_UN_datasourceName() RETURNS void AS $$
  266. BEGIN
  267. IF NOT EXISTS (SELECT 1 FROM pg_stat_all_indexes
  268. WHERE relname='t_ds_datasource'
  269. AND indexrelname ='t_ds_datasource_name_un')
  270. THEN
  271. ALTER TABLE t_ds_datasource ADD CONSTRAINT t_ds_datasource_name_un UNIQUE (name, type);
  272. END IF;
  273. END;
  274. $$ LANGUAGE plpgsql;
  275. d//
  276. delimiter ;
  277. SELECT uc_dolphin_T_t_ds_datasource_A_add_UN_datasourceName();
  278. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_datasource_A_add_UN_datasourceName();
  279. -- uc_dolphin_T_t_ds_schedules_A_add_timezone
  280. delimiter d//
  281. CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_schedules_A_add_timezone() RETURNS void AS $$
  282. BEGIN
  283. IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
  284. WHERE TABLE_NAME='t_ds_schedules'
  285. AND COLUMN_NAME ='timezone_id')
  286. THEN
  287. ALTER TABLE t_ds_schedules ADD COLUMN timezone_id varchar(40) DEFAULT NULL;
  288. END IF;
  289. END;
  290. $$ LANGUAGE plpgsql;
  291. d//
  292. delimiter ;
  293. SELECT uc_dolphin_T_t_ds_schedules_A_add_timezone();
  294. DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_schedules_A_add_timezone();
  295. --
  296. -- Table structure for table t_ds_environment
  297. --
  298. DROP TABLE IF EXISTS t_ds_environment;
  299. CREATE TABLE t_ds_environment (
  300. id serial NOT NULL ,
  301. code bigint NOT NULL,
  302. name varchar(100) DEFAULT NULL ,
  303. config text DEFAULT NULL ,
  304. description text ,
  305. operator int DEFAULT NULL ,
  306. create_time timestamp DEFAULT NULL ,
  307. update_time timestamp DEFAULT NULL ,
  308. PRIMARY KEY (id) ,
  309. CONSTRAINT environment_name_unique UNIQUE (name),
  310. CONSTRAINT environment_code_unique UNIQUE (code)
  311. );
  312. ALTER TABLE t_ds_task_definition ADD COLUMN environment_code bigint DEFAULT NULL;
  313. comment on column t_ds_task_definition.environment_code is 'environment code';
  314. ALTER TABLE t_ds_task_definition_log ADD COLUMN environment_code bigint DEFAULT NULL;
  315. comment on column t_ds_task_definition_log.environment_code is 'environment code';
  316. ALTER TABLE t_ds_command ADD COLUMN environment_code bigint DEFAULT NULL;
  317. comment on column t_ds_command.environment_code is 'environment code';
  318. ALTER TABLE t_ds_error_command ADD COLUMN environment_code bigint DEFAULT NULL;
  319. comment on column t_ds_error_command.environment_code is 'environment code';
  320. ALTER TABLE t_ds_schedules ADD COLUMN environment_code bigint DEFAULT NULL;
  321. comment on column t_ds_schedules.environment_code is 'environment code';
  322. ALTER TABLE t_ds_process_instance ADD COLUMN environment_code bigint DEFAULT NULL;
  323. comment on column t_ds_process_instance.environment_code is 'environment code';
  324. ALTER TABLE t_ds_task_instance ADD COLUMN environment_code bigint DEFAULT NULL;
  325. comment on column t_ds_task_instance.environment_code is 'environment code';
  326. ALTER TABLE t_ds_task_instance ADD COLUMN environment_config text;
  327. comment on column t_ds_task_instance.environment_config is 'environment config';
  328. --
  329. -- Table structure for table t_ds_environment_worker_group_relation
  330. --
  331. DROP TABLE IF EXISTS t_ds_environment_worker_group_relation;
  332. CREATE TABLE t_ds_environment_worker_group_relation (
  333. id serial NOT NULL,
  334. environment_code bigint NOT NULL,
  335. worker_group varchar(255) NOT NULL,
  336. operator int DEFAULT NULL,
  337. create_time timestamp DEFAULT NULL,
  338. update_time timestamp DEFAULT NULL,
  339. PRIMARY KEY (id) ,
  340. CONSTRAINT environment_worker_group_unique UNIQUE (environment_code,worker_group)
  341. );
  342. -- ----------------------------
  343. -- 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
  344. -- ----------------------------
  345. -- ALTER TABLE t_ds_alert DROP COLUMN "show_type", DROP COLUMN "alert_type", DROP COLUMN "receivers", DROP COLUMN "receivers_cc";
  346. -- ALTER TABLE t_ds_alertgroup DROP COLUMN "group_type";
  347. -- ALTER TABLE t_ds_process_definition DROP COLUMN "receivers", DROP COLUMN "receivers_cc";
  348. -- ALTER TABLE t_ds_process_definition_version DROP COLUMN "receivers", DROP COLUMN "receivers_cc";
  349. -- DROP TABLE IF EXISTS t_ds_relation_user_alertgroup;
  350. -- ALTER TABLE t_ds_command DROP COLUMN "dependence";
  351. -- ALTER TABLE t_ds_error_command DROP COLUMN "dependence";