derby-schema.sql 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright 1999-2018 Alibaba Group Holding Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. CREATE SCHEMA nacos AUTHORIZATION nacos;
  17. CREATE TABLE config_info (
  18. id bigint NOT NULL generated by default as identity,
  19. data_id varchar(255) NOT NULL,
  20. group_id varchar(128) NOT NULL,
  21. tenant_id varchar(128) default '',
  22. app_name varchar(128),
  23. content CLOB,
  24. md5 varchar(32) DEFAULT NULL,
  25. gmt_create timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
  26. gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
  27. src_user varchar(128) DEFAULT NULL,
  28. src_ip varchar(50) DEFAULT NULL,
  29. c_desc varchar(256) DEFAULT NULL,
  30. c_use varchar(64) DEFAULT NULL,
  31. effect varchar(64) DEFAULT NULL,
  32. type varchar(64) DEFAULT NULL,
  33. c_schema LONG VARCHAR DEFAULT NULL,
  34. encrypted_data_key LONG VARCHAR DEFAULT NULL,
  35. constraint configinfo_id_key PRIMARY KEY (id),
  36. constraint uk_configinfo_datagrouptenant UNIQUE (data_id,group_id,tenant_id));
  37. CREATE INDEX configinfo_dataid_key_idx ON config_info(data_id);
  38. CREATE INDEX configinfo_groupid_key_idx ON config_info(group_id);
  39. CREATE INDEX configinfo_dataid_group_key_idx ON config_info(data_id, group_id);
  40. CREATE TABLE his_config_info (
  41. id bigint NOT NULL,
  42. nid bigint NOT NULL generated by default as identity,
  43. data_id varchar(255) NOT NULL,
  44. group_id varchar(128) NOT NULL,
  45. tenant_id varchar(128) default '',
  46. app_name varchar(128),
  47. content CLOB,
  48. md5 varchar(32) DEFAULT NULL,
  49. gmt_create timestamp NOT NULL DEFAULT '2010-05-05 00:00:00.000',
  50. gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00.000',
  51. src_user varchar(128),
  52. src_ip varchar(50) DEFAULT NULL,
  53. op_type char(10) DEFAULT NULL,
  54. encrypted_data_key LONG VARCHAR DEFAULT NULL,
  55. constraint hisconfiginfo_nid_key PRIMARY KEY (nid));
  56. CREATE INDEX hisconfiginfo_dataid_key_idx ON his_config_info(data_id);
  57. CREATE INDEX hisconfiginfo_gmt_create_idx ON his_config_info(gmt_create);
  58. CREATE INDEX hisconfiginfo_gmt_modified_idx ON his_config_info(gmt_modified);
  59. CREATE TABLE config_info_beta (
  60. id bigint NOT NULL generated by default as identity,
  61. data_id varchar(255) NOT NULL,
  62. group_id varchar(128) NOT NULL,
  63. tenant_id varchar(128) default '',
  64. app_name varchar(128),
  65. content CLOB,
  66. beta_ips varchar(1024),
  67. md5 varchar(32) DEFAULT NULL,
  68. gmt_create timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
  69. gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
  70. src_user varchar(128),
  71. src_ip varchar(50) DEFAULT NULL,
  72. encrypted_data_key LONG VARCHAR DEFAULT NULL,
  73. constraint configinfobeta_id_key PRIMARY KEY (id),
  74. constraint uk_configinfobeta_datagrouptenant UNIQUE (data_id,group_id,tenant_id));
  75. CREATE TABLE config_info_tag (
  76. id bigint NOT NULL generated by default as identity,
  77. data_id varchar(255) NOT NULL,
  78. group_id varchar(128) NOT NULL,
  79. tenant_id varchar(128) default '',
  80. tag_id varchar(128) NOT NULL,
  81. app_name varchar(128),
  82. content CLOB,
  83. md5 varchar(32) DEFAULT NULL,
  84. gmt_create timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
  85. gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
  86. src_user varchar(128),
  87. src_ip varchar(50) DEFAULT NULL,
  88. constraint configinfotag_id_key PRIMARY KEY (id),
  89. constraint uk_configinfotag_datagrouptenanttag UNIQUE (data_id,group_id,tenant_id,tag_id));
  90. CREATE TABLE config_info_aggr (
  91. id bigint NOT NULL generated by default as identity,
  92. data_id varchar(255) NOT NULL,
  93. group_id varchar(128) NOT NULL,
  94. tenant_id varchar(128) default '',
  95. datum_id varchar(255) NOT NULL,
  96. app_name varchar(128),
  97. content CLOB,
  98. gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
  99. constraint configinfoaggr_id_key PRIMARY KEY (id),
  100. constraint uk_configinfoaggr_datagrouptenantdatum UNIQUE (data_id,group_id,tenant_id,datum_id));
  101. CREATE TABLE app_list (
  102. id bigint NOT NULL generated by default as identity,
  103. app_name varchar(128) NOT NULL,
  104. is_dynamic_collect_disabled smallint DEFAULT 0,
  105. last_sub_info_collected_time timestamp DEFAULT '1970-01-01 08:00:00.0',
  106. sub_info_lock_owner varchar(128),
  107. sub_info_lock_time timestamp DEFAULT '1970-01-01 08:00:00.0',
  108. constraint applist_id_key PRIMARY KEY (id),
  109. constraint uk_appname UNIQUE (app_name));
  110. CREATE TABLE app_configdata_relation_subs (
  111. id bigint NOT NULL generated by default as identity,
  112. app_name varchar(128) NOT NULL,
  113. data_id varchar(255) NOT NULL,
  114. group_id varchar(128) NOT NULL,
  115. gmt_modified timestamp DEFAULT '2010-05-05 00:00:00',
  116. constraint configdatarelationsubs_id_key PRIMARY KEY (id),
  117. constraint uk_app_sub_config_datagroup UNIQUE (app_name, data_id, group_id));
  118. CREATE TABLE app_configdata_relation_pubs (
  119. id bigint NOT NULL generated by default as identity,
  120. app_name varchar(128) NOT NULL,
  121. data_id varchar(255) NOT NULL,
  122. group_id varchar(128) NOT NULL,
  123. gmt_modified timestamp DEFAULT '2010-05-05 00:00:00',
  124. constraint configdatarelationpubs_id_key PRIMARY KEY (id),
  125. constraint uk_app_pub_config_datagroup UNIQUE (app_name, data_id, group_id));
  126. CREATE TABLE config_tags_relation (
  127. id bigint NOT NULL,
  128. tag_name varchar(128) NOT NULL,
  129. tag_type varchar(64) DEFAULT NULL,
  130. data_id varchar(255) NOT NULL,
  131. group_id varchar(128) NOT NULL,
  132. tenant_id varchar(128) DEFAULT '',
  133. nid bigint NOT NULL generated by default as identity,
  134. constraint config_tags_id_key PRIMARY KEY (nid),
  135. constraint uk_configtagrelation_configidtag UNIQUE (id, tag_name, tag_type));
  136. CREATE INDEX config_tags_tenant_id_idx ON config_tags_relation(tenant_id);
  137. CREATE TABLE group_capacity (
  138. id bigint NOT NULL generated by default as identity,
  139. group_id varchar(128) DEFAULT '',
  140. quota int DEFAULT 0,
  141. usage int DEFAULT 0,
  142. max_size int DEFAULT 0,
  143. max_aggr_count int DEFAULT 0,
  144. max_aggr_size int DEFAULT 0,
  145. max_history_count int DEFAULT 0,
  146. gmt_create timestamp DEFAULT '2010-05-05 00:00:00',
  147. gmt_modified timestamp DEFAULT '2010-05-05 00:00:00',
  148. constraint group_capacity_id_key PRIMARY KEY (id),
  149. constraint uk_group_id UNIQUE (group_id));
  150. CREATE TABLE tenant_capacity (
  151. id bigint NOT NULL generated by default as identity,
  152. tenant_id varchar(128) DEFAULT '',
  153. quota int DEFAULT 0,
  154. usage int DEFAULT 0,
  155. max_size int DEFAULT 0,
  156. max_aggr_count int DEFAULT 0,
  157. max_aggr_size int DEFAULT 0,
  158. max_history_count int DEFAULT 0,
  159. gmt_create timestamp DEFAULT '2010-05-05 00:00:00',
  160. gmt_modified timestamp DEFAULT '2010-05-05 00:00:00',
  161. constraint tenant_capacity_id_key PRIMARY KEY (id),
  162. constraint uk_tenant_id UNIQUE (tenant_id));
  163. CREATE TABLE tenant_info (
  164. id bigint NOT NULL generated by default as identity,
  165. kp varchar(128) NOT NULL,
  166. tenant_id varchar(128) DEFAULT '',
  167. tenant_name varchar(128) DEFAULT '',
  168. tenant_desc varchar(256) DEFAULT NULL,
  169. create_source varchar(32) DEFAULT NULL,
  170. gmt_create bigint NOT NULL,
  171. gmt_modified bigint NOT NULL,
  172. constraint tenant_info_id_key PRIMARY KEY (id),
  173. constraint uk_tenant_info_kptenantid UNIQUE (kp,tenant_id));
  174. CREATE INDEX tenant_info_tenant_id_idx ON tenant_info(tenant_id);
  175. CREATE TABLE users (
  176. username varchar(50) NOT NULL PRIMARY KEY,
  177. password varchar(500) NOT NULL,
  178. enabled boolean NOT NULL DEFAULT true
  179. );
  180. CREATE TABLE roles (
  181. username varchar(50) NOT NULL,
  182. role varchar(50) NOT NULL,
  183. constraint uk_username_role UNIQUE (username,role)
  184. );
  185. CREATE TABLE permissions (
  186. role varchar(50) NOT NULL,
  187. resource varchar(512) NOT NULL,
  188. action varchar(8) NOT NULL,
  189. constraint uk_role_permission UNIQUE (role,resource,action)
  190. );
  191. INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);
  192. INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');
  193. /******************************************/
  194. /* ipv6 support */
  195. /******************************************/
  196. ALTER TABLE `config_info_tag`
  197. MODIFY COLUMN `src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip' AFTER `src_user`;
  198. ALTER TABLE `his_config_info`
  199. MODIFY COLUMN `src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL AFTER `src_user`;
  200. ALTER TABLE `config_info`
  201. MODIFY COLUMN `src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip' AFTER `src_user`;
  202. ALTER TABLE `config_info_beta`
  203. MODIFY COLUMN `src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip' AFTER `src_user`;