nacos2.3.0 接入pgsql或其他数据库

打印 上一主题 下一主题

主题 1772|帖子 1772|积分 5316

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  首先尝试使用官方插件进行扩展,各种报错后放弃,不如本身修改源码吧。
一、官方解决方案

   1、nocos 文档地址:Nacos 配置中心简介, Nacos 是什么 | Nacos 官网
  2、官方解答:nacos支持postgresql数据库吗 | Nacos 官网
3、源码下载地址:Release 2.3.0 (Nov 30, 2023) · alibaba/nacos · GitHub
  4、Nacos的数据库插件仓库:nacos-plugin/nacos-datasource-plugin-ext at develop · nacos-group/nacos-plugin · GitHub
  按照官方的方案,下载插件后,更改pom文件中nacos的版本,之后将插件打成jar包,放到nacos的plugins目录下,更改配置,启动后各种报错找不到方法,遂放弃。
二、更改源码

1、在项目根(nacos-all)下的pom.xml文件中添加如下依靠:
  
  1. <!--版本可修改-->
  2. <postgresql.version>42.3.8</postgresql.version>
复制代码
  1. <dependency>
  2.     <groupId>org.postgresql</groupId>
  3.     <artifactId>postgresql</artifactId>
  4.     <version>${postgresql.version}</version>
  5. </dependency>
复制代码
2、在项目的nacos-config-plugin、nacos-persistence模块的pom.xml文件中添加如下依靠:
  
  1. <dependency>
  2.     <groupId>org.postgresql</groupId>
  3.     <artifactId>postgresql</artifactId>
  4. </dependency>
复制代码
3、在项目的nacos-plugin模块的nacos-datasource-plugin模块com.alibaba.nacos.plugin.datasource.impl包下新建一个包,名为postgresql,拷贝同级包mysql下的所有文件到postgresql包下,修改类名和文件名为xxxByPostgresql,如图

4、将这几个类中LIMIT ?,?的写法为OFFSET ? LIMIT ? 如图

5、在改项目resource目录下,找到com.alibaba.nacos.plugin.datasource.mapper.Mapper文件,在背面追加:
  
  1. com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoAggrMapperByPostgresql
  2. com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoBetaMapperByPostgresql
  3. com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoMapperByPostgresql
  4. com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoTagMapperByPostgresql
  5. com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigTagsRelationMapperByPostgresql
  6. com.alibaba.nacos.plugin.datasource.impl.postgresql.HistoryConfigInfoMapperByPostgresql
  7. com.alibaba.nacos.plugin.datasource.impl.postgresql.TenantInfoMapperByPostgresql
  8. com.alibaba.nacos.plugin.datasource.impl.postgresql.TenantCapacityMapperByPostgresql
  9. com.alibaba.nacos.plugin.datasource.impl.postgresql.GroupCapacityMapperByPostgresql
复制代码
如图:

6、在DataSourceConstant类中增加pgsql的常量
  1.     public static final String POSTGRESQL = "postgresql";
复制代码
7、persistence模块,修改PersistenceConstant
  1.     public static final String POSTGRESQL = "postgresql";
复制代码
修改ExternalDataSourceProperties类


代码如下,直接复制粘贴即可:
  1. /*
  2. * Copyright 1999-2023 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. package com.alibaba.nacos.persistence.datasource;
  17. import com.alibaba.nacos.common.utils.CollectionUtils;
  18. import com.alibaba.nacos.common.utils.Preconditions;
  19. import com.alibaba.nacos.common.utils.StringUtils;
  20. import com.zaxxer.hikari.HikariDataSource;
  21. import org.springframework.boot.context.properties.bind.Bindable;
  22. import org.springframework.boot.context.properties.bind.Binder;
  23. import org.springframework.core.env.Environment;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import java.util.Objects;
  27. import static com.alibaba.nacos.common.utils.CollectionUtils.getOrDefault;
  28. /**
  29. * Properties of external DataSource.
  30. *
  31. * @author Nacos
  32. */
  33. public class ExternalDataSourceProperties {
  34.    
  35.     private static final String JDBC_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
  36.     private static final String TEST_QUERY = "SELECT 1";
  37.    
  38.     private Integer num;
  39.    
  40.     private List<String> url = new ArrayList<>();
  41.    
  42.     private List<String> user = new ArrayList<>();
  43.    
  44.     private List<String> password = new ArrayList<>();
  45.     private String jdbcDriverName;
  46.     public void setJdbcDriverName(String jdbcDriverName) {
  47.         if (StringUtils.isBlank(jdbcDriverName)) {
  48.             this.jdbcDriverName = JDBC_DRIVER_NAME;
  49.         } else {
  50.             this.jdbcDriverName = jdbcDriverName;
  51.         }
  52.     }
  53.    
  54.     public void setNum(Integer num) {
  55.         this.num = num;
  56.     }
  57.    
  58.     public void setUrl(List<String> url) {
  59.         this.url = url;
  60.     }
  61.    
  62.     public void setUser(List<String> user) {
  63.         this.user = user;
  64.     }
  65.    
  66.     public void setPassword(List<String> password) {
  67.         this.password = password;
  68.     }
  69.     /**
  70.      * Build serveral HikariDataSource.
  71.      *
  72.      * @param environment {@link Environment}
  73.      * @param callback    Callback function when constructing data source
  74.      * @return List of {@link HikariDataSource}
  75.      */
  76.     List<HikariDataSource> build(Environment environment, Callback<HikariDataSource> callback) {
  77.         List<HikariDataSource> dataSources = new ArrayList<>();
  78.         Binder.get(environment).bind("db", Bindable.ofInstance(this));
  79.         Preconditions.checkArgument(Objects.nonNull(num), "db.num is null");
  80.         Preconditions.checkArgument(CollectionUtils.isNotEmpty(user), "db.user or db.user.[index] is null");
  81.         Preconditions.checkArgument(CollectionUtils.isNotEmpty(password), "db.password or db.password.[index] is null");
  82.         for (int index = 0; index < num; index++) {
  83.             int currentSize = index + 1;
  84.             Preconditions.checkArgument(url.size() >= currentSize, "db.url.%s is null", index);
  85.             DataSourcePoolProperties poolProperties = DataSourcePoolProperties.build(environment);
  86.             if (StringUtils.isEmpty(poolProperties.getDataSource().getDriverClassName())) {
  87.                 poolProperties.setDriverClassName(jdbcDriverName);
  88.             }
  89.             poolProperties.setJdbcUrl(url.get(index).trim());
  90.             poolProperties.setUsername(getOrDefault(user, index, user.get(0)).trim());
  91.             poolProperties.setPassword(getOrDefault(password, index, password.get(0)).trim());
  92.             HikariDataSource ds = poolProperties.getDataSource();
  93.             if (StringUtils.isEmpty(ds.getConnectionTestQuery())) {
  94.                 ds.setConnectionTestQuery(TEST_QUERY);
  95.             }
  96.             
  97.             dataSources.add(ds);
  98.             callback.accept(ds);
  99.         }
  100.         Preconditions.checkArgument(CollectionUtils.isNotEmpty(dataSources), "no datasource available");
  101.         return dataSources;
  102.     }
  103.    
  104.     interface Callback<D> {
  105.         
  106.         /**
  107.          * Perform custom logic.
  108.          *
  109.          * @param datasource dataSource.
  110.          */
  111.         void accept(D datasource);
  112.     }
  113. }
复制代码
8、plugins-defualt-impl模块,子模块nacos-default-auth-plugin中,修改AuthPageConstant,加入以下代码
  1.     public static final String OFFSET_LIMIT = "OFFSET ? LIMIT ?";
复制代码
persistence.handler.support中新增PostgreSqlPageHandlerAdapter类,如图:

代码如下:
  1. package com.alibaba.nacos.plugin.auth.impl.persistence.handler.support;
  2. import com.alibaba.nacos.config.server.service.dump.DumpService;
  3. import com.alibaba.nacos.persistence.constants.PersistenceConstant;
  4. import com.alibaba.nacos.plugin.auth.impl.constant.AuthPageConstant;
  5. import com.alibaba.nacos.plugin.auth.impl.model.OffsetFetchResult;
  6. import com.alibaba.nacos.plugin.auth.impl.persistence.handler.PageHandlerAdapter;
  7. import org.slf4j.Logger;
  8. import org.slf4j.LoggerFactory;
  9. import java.util.ArrayList;
  10. import java.util.Arrays;
  11. import java.util.List;
  12. /**
  13. * @author w
  14. */
  15. public class PostgreSqlPageHandlerAdapter implements PageHandlerAdapter {
  16.     @Override
  17.     public boolean supports(String dataSourceType) {
  18.         return PersistenceConstant.POSTGRESQL.equals(dataSourceType);
  19.     }
  20.     @Override
  21.     public OffsetFetchResult addOffsetAndFetchNext(String fetchSql, Object[] arg, int pageNo, int pageSize) {
  22.         if (!fetchSql.contains(AuthPageConstant.LIMIT)) {
  23.             fetchSql += " " + AuthPageConstant.OFFSET_LIMIT;
  24.             List<Object> newArgsList = new ArrayList<>(Arrays.asList(arg));
  25.             newArgsList.add((pageNo - 1) * pageSize);
  26.             newArgsList.add(pageSize);
  27.             Object[] newArgs = newArgsList.toArray(new Object[newArgsList.size()]);
  28.             return new OffsetFetchResult(fetchSql, newArgs);
  29.         }
  30.         return new OffsetFetchResult(fetchSql, arg);
  31.     }
  32. }
复制代码
在 PageHandlerAdapterFactory 类中加入以下代码:

9、终极,执行打包命令
   mvn -Prelease-nacos clean install -Dmaven.test.skip=true -Dcheckstyle.skip=true -Dpmd.skip=true -Drat.skip=true -U
  根据需求,在 nacos-2.3.0\distribution\target 目录下找到打好的包

修改配置文件,记得将数据库ip、库名、schema名称、用户名、密码配置改成本身的:
  1. spring.datasource.platform=postgresql
  2. db.num=1
  3. db.url.0=jdbc:postgresql://xxxx:5432/nacos?currentSchema=public&reWriteBatchedInserts=true&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
  4. db.user.0=xxxx
  5. db.password.0=xxxx
  6. db.pool.config.driverClassName=org.postgresql.Driver
  7. nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
  8. nacos.core.auth.enabled=true
  9. nacos.core.auth.caching.enabled=false
  10. nacos.core.auth.server.identity.key=nacos
  11. nacos.core.auth.server.identity.value=nacos
复制代码
终极,祝各人乐成!!!
附上pg数据库脚本:
  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. -- ----------------------------
  17. -- Table structure for config_info
  18. -- ----------------------------
  19. DROP TABLE IF EXISTS "config_info";
  20. CREATE TABLE "config_info" (
  21.   "id" bigserial NOT NULL,
  22.   "data_id" varchar(255)  NOT NULL,
  23.   "group_id" varchar(255) ,
  24.   "content" text  NOT NULL,
  25.   "md5" varchar(32) ,
  26.   "gmt_create" timestamp(6) NOT NULL,
  27.   "gmt_modified" timestamp(6) NOT NULL,
  28.   "src_user" text ,
  29.   "src_ip" varchar(20) ,
  30.   "app_name" varchar(128) ,
  31.   "tenant_id" varchar(128) ,
  32.   "c_desc" varchar(256) ,
  33.   "c_use" varchar(64) ,
  34.   "effect" varchar(64) ,
  35.   "type" varchar(64) ,
  36.   "c_schema" text ,
  37.   "encrypted_data_key" text  NOT NULL
  38. )
  39. ;
  40. COMMENT ON COLUMN "config_info"."id" IS 'id';
  41. COMMENT ON COLUMN "config_info"."data_id" IS 'data_id';
  42. COMMENT ON COLUMN "config_info"."content" IS 'content';
  43. COMMENT ON COLUMN "config_info"."md5" IS 'md5';
  44. COMMENT ON COLUMN "config_info"."gmt_create" IS '创建时间';
  45. COMMENT ON COLUMN "config_info"."gmt_modified" IS '修改时间';
  46. COMMENT ON COLUMN "config_info"."src_user" IS 'source user';
  47. COMMENT ON COLUMN "config_info"."src_ip" IS 'source ip';
  48. COMMENT ON COLUMN "config_info"."tenant_id" IS '租户字段';
  49. COMMENT ON COLUMN "config_info"."encrypted_data_key" IS '秘钥';
  50. COMMENT ON TABLE "config_info" IS 'config_info';
  51. -- ----------------------------
  52. -- Table structure for config_info_aggr
  53. -- ----------------------------
  54. DROP TABLE IF EXISTS "config_info_aggr";
  55. CREATE TABLE "config_info_aggr" (
  56.   "id" bigserial NOT NULL,
  57.   "data_id" varchar(255)  NOT NULL,
  58.   "group_id" varchar(255)  NOT NULL,
  59.   "datum_id" varchar(255)  NOT NULL,
  60.   "content" text  NOT NULL,
  61.   "gmt_modified" timestamp(6) NOT NULL,
  62.   "app_name" varchar(128) ,
  63.   "tenant_id" varchar(128)
  64. )
  65. ;
  66. COMMENT ON COLUMN "config_info_aggr"."id" IS 'id';
  67. COMMENT ON COLUMN "config_info_aggr"."data_id" IS 'data_id';
  68. COMMENT ON COLUMN "config_info_aggr"."group_id" IS 'group_id';
  69. COMMENT ON COLUMN "config_info_aggr"."datum_id" IS 'datum_id';
  70. COMMENT ON COLUMN "config_info_aggr"."content" IS '内容';
  71. COMMENT ON COLUMN "config_info_aggr"."gmt_modified" IS '修改时间';
  72. COMMENT ON COLUMN "config_info_aggr"."tenant_id" IS '租户字段';
  73. COMMENT ON TABLE "config_info_aggr" IS '增加租户字段';
  74. -- ----------------------------
  75. -- Records of config_info_aggr
  76. -- ----------------------------
  77. BEGIN;
  78. COMMIT;
  79. -- ----------------------------
  80. -- Table structure for config_info_beta
  81. -- ----------------------------
  82. DROP TABLE IF EXISTS "config_info_beta";
  83. CREATE TABLE "config_info_beta" (
  84.   "id" bigserial NOT NULL,
  85.   "data_id" varchar(255)  NOT NULL,
  86.   "group_id" varchar(128)  NOT NULL,
  87.   "app_name" varchar(128) ,
  88.   "content" text  NOT NULL,
  89.   "beta_ips" varchar(1024) ,
  90.   "md5" varchar(32) ,
  91.   "gmt_create" timestamp(6) NOT NULL,
  92.   "gmt_modified" timestamp(6) NOT NULL,
  93.   "src_user" text ,
  94.   "src_ip" varchar(20) ,
  95.   "tenant_id" varchar(128) ,
  96.   "encrypted_data_key" text  NOT NULL
  97. )
  98. ;
  99. COMMENT ON COLUMN "config_info_beta"."id" IS 'id';
  100. COMMENT ON COLUMN "config_info_beta"."data_id" IS 'data_id';
  101. COMMENT ON COLUMN "config_info_beta"."group_id" IS 'group_id';
  102. COMMENT ON COLUMN "config_info_beta"."app_name" IS 'app_name';
  103. COMMENT ON COLUMN "config_info_beta"."content" IS 'content';
  104. COMMENT ON COLUMN "config_info_beta"."beta_ips" IS 'betaIps';
  105. COMMENT ON COLUMN "config_info_beta"."md5" IS 'md5';
  106. COMMENT ON COLUMN "config_info_beta"."gmt_create" IS '创建时间';
  107. COMMENT ON COLUMN "config_info_beta"."gmt_modified" IS '修改时间';
  108. COMMENT ON COLUMN "config_info_beta"."src_user" IS 'source user';
  109. COMMENT ON COLUMN "config_info_beta"."src_ip" IS 'source ip';
  110. COMMENT ON COLUMN "config_info_beta"."tenant_id" IS '租户字段';
  111. COMMENT ON COLUMN "config_info_beta"."encrypted_data_key" IS '秘钥';
  112. COMMENT ON TABLE "config_info_beta" IS 'config_info_beta';
  113. -- ----------------------------
  114. -- Records of config_info_beta
  115. -- ----------------------------
  116. BEGIN;
  117. COMMIT;
  118. -- ----------------------------
  119. -- Table structure for config_info_tag
  120. -- ----------------------------
  121. DROP TABLE IF EXISTS "config_info_tag";
  122. CREATE TABLE "config_info_tag" (
  123.   "id" bigserial NOT NULL,
  124.   "data_id" varchar(255)  NOT NULL,
  125.   "group_id" varchar(128)  NOT NULL,
  126.   "tenant_id" varchar(128) ,
  127.   "tag_id" varchar(128)  NOT NULL,
  128.   "app_name" varchar(128) ,
  129.   "content" text  NOT NULL,
  130.   "md5" varchar(32) ,
  131.   "gmt_create" timestamp(6) NOT NULL,
  132.   "gmt_modified" timestamp(6) NOT NULL,
  133.   "src_user" text ,
  134.   "src_ip" varchar(20)
  135. )
  136. ;
  137. COMMENT ON COLUMN "config_info_tag"."id" IS 'id';
  138. COMMENT ON COLUMN "config_info_tag"."data_id" IS 'data_id';
  139. COMMENT ON COLUMN "config_info_tag"."group_id" IS 'group_id';
  140. COMMENT ON COLUMN "config_info_tag"."tenant_id" IS 'tenant_id';
  141. COMMENT ON COLUMN "config_info_tag"."tag_id" IS 'tag_id';
  142. COMMENT ON COLUMN "config_info_tag"."app_name" IS 'app_name';
  143. COMMENT ON COLUMN "config_info_tag"."content" IS 'content';
  144. COMMENT ON COLUMN "config_info_tag"."md5" IS 'md5';
  145. COMMENT ON COLUMN "config_info_tag"."gmt_create" IS '创建时间';
  146. COMMENT ON COLUMN "config_info_tag"."gmt_modified" IS '修改时间';
  147. COMMENT ON COLUMN "config_info_tag"."src_user" IS 'source user';
  148. COMMENT ON COLUMN "config_info_tag"."src_ip" IS 'source ip';
  149. COMMENT ON TABLE "config_info_tag" IS 'config_info_tag';
  150. -- ----------------------------
  151. -- Records of config_info_tag
  152. -- ----------------------------
  153. BEGIN;
  154. COMMIT;
  155. -- ----------------------------
  156. -- Table structure for config_tags_relation
  157. -- ----------------------------
  158. DROP TABLE IF EXISTS "config_tags_relation";
  159. CREATE TABLE "config_tags_relation" (
  160.   "id" bigserial NOT NULL,
  161.   "tag_name" varchar(128)  NOT NULL,
  162.   "tag_type" varchar(64) ,
  163.   "data_id" varchar(255)  NOT NULL,
  164.   "group_id" varchar(128)  NOT NULL,
  165.   "tenant_id" varchar(128) ,
  166.   "nid" bigserial NOT NULL
  167. )
  168. ;
  169. COMMENT ON COLUMN "config_tags_relation"."id" IS 'id';
  170. COMMENT ON COLUMN "config_tags_relation"."tag_name" IS 'tag_name';
  171. COMMENT ON COLUMN "config_tags_relation"."tag_type" IS 'tag_type';
  172. COMMENT ON COLUMN "config_tags_relation"."data_id" IS 'data_id';
  173. COMMENT ON COLUMN "config_tags_relation"."group_id" IS 'group_id';
  174. COMMENT ON COLUMN "config_tags_relation"."tenant_id" IS 'tenant_id';
  175. COMMENT ON TABLE "config_tags_relation" IS 'config_tag_relation';
  176. -- ----------------------------
  177. -- Records of config_tags_relation
  178. -- ----------------------------
  179. BEGIN;
  180. COMMIT;
  181. -- ----------------------------
  182. -- Table structure for group_capacity
  183. -- ----------------------------
  184. DROP TABLE IF EXISTS "group_capacity";
  185. CREATE TABLE "group_capacity" (
  186.   "id" bigserial NOT NULL,
  187.   "group_id" varchar(128)  NOT NULL,
  188.   "quota" int4 NOT NULL,
  189.   "usage" int4 NOT NULL,
  190.   "max_size" int4 NOT NULL,
  191.   "max_aggr_count" int4 NOT NULL,
  192.   "max_aggr_size" int4 NOT NULL,
  193.   "max_history_count" int4 NOT NULL,
  194.   "gmt_create" timestamp(6) NOT NULL,
  195.   "gmt_modified" timestamp(6) NOT NULL
  196. )
  197. ;
  198. COMMENT ON COLUMN "group_capacity"."id" IS '主键ID';
  199. COMMENT ON COLUMN "group_capacity"."group_id" IS 'Group ID,空字符表示整个集群';
  200. COMMENT ON COLUMN "group_capacity"."quota" IS '配额,0表示使用默认值';
  201. COMMENT ON COLUMN "group_capacity"."usage" IS '使用量';
  202. COMMENT ON COLUMN "group_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值';
  203. COMMENT ON COLUMN "group_capacity"."max_aggr_count" IS '聚合子配置最大个数,,0表示使用默认值';
  204. COMMENT ON COLUMN "group_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';
  205. COMMENT ON COLUMN "group_capacity"."max_history_count" IS '最大变更历史数量';
  206. COMMENT ON COLUMN "group_capacity"."gmt_create" IS '创建时间';
  207. COMMENT ON COLUMN "group_capacity"."gmt_modified" IS '修改时间';
  208. COMMENT ON TABLE "group_capacity" IS '集群、各Group容量信息表';
  209. -- ----------------------------
  210. -- Records of group_capacity
  211. -- ----------------------------
  212. BEGIN;
  213. COMMIT;
  214. -- ----------------------------
  215. -- Table structure for his_config_info
  216. -- ----------------------------
  217. DROP TABLE IF EXISTS "his_config_info";
  218. CREATE TABLE "his_config_info" (
  219.   "id" int8 NOT NULL,
  220.   "nid" bigserial NOT NULL,
  221.   "data_id" varchar(255)  NOT NULL,
  222.   "group_id" varchar(128)  NOT NULL,
  223.   "app_name" varchar(128) ,
  224.   "content" text  NOT NULL,
  225.   "md5" varchar(32) ,
  226.   "gmt_create" timestamp(6) NOT NULL  DEFAULT '2010-05-05 00:00:00',
  227.   "gmt_modified" timestamp(6) NOT NULL,
  228.   "src_user" text ,
  229.   "src_ip" varchar(20) ,
  230.   "op_type" char(10) ,
  231.   "tenant_id" varchar(128) ,
  232.   "encrypted_data_key" text  NOT NULL
  233. )
  234. ;
  235. COMMENT ON COLUMN "his_config_info"."app_name" IS 'app_name';
  236. COMMENT ON COLUMN "his_config_info"."tenant_id" IS '租户字段';
  237. COMMENT ON COLUMN "his_config_info"."encrypted_data_key" IS '秘钥';
  238. COMMENT ON TABLE "his_config_info" IS '多租户改造';
  239. -- ----------------------------
  240. -- Table structure for permissions
  241. -- ----------------------------
  242. DROP TABLE IF EXISTS "permissions";
  243. CREATE TABLE "permissions" (
  244.   "role" varchar(50)  NOT NULL,
  245.   "resource" varchar(512)  NOT NULL,
  246.   "action" varchar(8)  NOT NULL
  247. )
  248. ;
  249. -- ----------------------------
  250. -- Records of permissions
  251. -- ----------------------------
  252. BEGIN;
  253. COMMIT;
  254. -- ----------------------------
  255. -- Table structure for roles
  256. -- ----------------------------
  257. DROP TABLE IF EXISTS "roles";
  258. CREATE TABLE "roles" (
  259.   "username" varchar(50)  NOT NULL,
  260.   "role" varchar(50)  NOT NULL
  261. )
  262. ;
  263. -- ----------------------------
  264. -- Records of roles
  265. -- ----------------------------
  266. BEGIN;
  267. INSERT INTO "roles" VALUES ('nacos', 'ROLE_ADMIN');
  268. COMMIT;
  269. -- ----------------------------
  270. -- Table structure for tenant_capacity
  271. -- ----------------------------
  272. DROP TABLE IF EXISTS "tenant_capacity";
  273. CREATE TABLE "tenant_capacity" (
  274.   "id" bigserial NOT NULL,
  275.   "tenant_id" varchar(128)  NOT NULL,
  276.   "quota" int4 NOT NULL,
  277.   "usage" int4 NOT NULL,
  278.   "max_size" int4 NOT NULL,
  279.   "max_aggr_count" int4 NOT NULL,
  280.   "max_aggr_size" int4 NOT NULL,
  281.   "max_history_count" int4 NOT NULL,
  282.   "gmt_create" timestamp(6) NOT NULL,
  283.   "gmt_modified" timestamp(6) NOT NULL
  284. )
  285. ;
  286. COMMENT ON COLUMN "tenant_capacity"."id" IS '主键ID';
  287. COMMENT ON COLUMN "tenant_capacity"."tenant_id" IS 'Tenant ID';
  288. COMMENT ON COLUMN "tenant_capacity"."quota" IS '配额,0表示使用默认值';
  289. COMMENT ON COLUMN "tenant_capacity"."usage" IS '使用量';
  290. COMMENT ON COLUMN "tenant_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值';
  291. COMMENT ON COLUMN "tenant_capacity"."max_aggr_count" IS '聚合子配置最大个数';
  292. COMMENT ON COLUMN "tenant_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';
  293. COMMENT ON COLUMN "tenant_capacity"."max_history_count" IS '最大变更历史数量';
  294. COMMENT ON COLUMN "tenant_capacity"."gmt_create" IS '创建时间';
  295. COMMENT ON COLUMN "tenant_capacity"."gmt_modified" IS '修改时间';
  296. COMMENT ON TABLE "tenant_capacity" IS '租户容量信息表';
  297. -- ----------------------------
  298. -- Records of tenant_capacity
  299. -- ----------------------------
  300. BEGIN;
  301. COMMIT;
  302. -- ----------------------------
  303. -- Table structure for tenant_info
  304. -- ----------------------------
  305. DROP TABLE IF EXISTS "tenant_info";
  306. CREATE TABLE "tenant_info" (
  307.   "id" bigserial NOT NULL,
  308.   "kp" varchar(128)  NOT NULL,
  309.   "tenant_id" varchar(128) ,
  310.   "tenant_name" varchar(128) ,
  311.   "tenant_desc" varchar(256) ,
  312.   "create_source" varchar(32) ,
  313.   "gmt_create" int8 NOT NULL,
  314.   "gmt_modified" int8 NOT NULL
  315. )
  316. ;
  317. COMMENT ON COLUMN "tenant_info"."id" IS 'id';
  318. COMMENT ON COLUMN "tenant_info"."kp" IS 'kp';
  319. COMMENT ON COLUMN "tenant_info"."tenant_id" IS 'tenant_id';
  320. COMMENT ON COLUMN "tenant_info"."tenant_name" IS 'tenant_name';
  321. COMMENT ON COLUMN "tenant_info"."tenant_desc" IS 'tenant_desc';
  322. COMMENT ON COLUMN "tenant_info"."create_source" IS 'create_source';
  323. COMMENT ON COLUMN "tenant_info"."gmt_create" IS '创建时间';
  324. COMMENT ON COLUMN "tenant_info"."gmt_modified" IS '修改时间';
  325. COMMENT ON TABLE "tenant_info" IS 'tenant_info';
  326. -- ----------------------------
  327. -- Records of tenant_info
  328. -- ----------------------------
  329. BEGIN;
  330. COMMIT;
  331. -- ----------------------------
  332. -- Table structure for users
  333. -- ----------------------------
  334. DROP TABLE IF EXISTS "users";
  335. CREATE TABLE "users" (
  336.   "username" varchar(50)  NOT NULL,
  337.   "password" varchar(500)  NOT NULL,
  338.   "enabled" boolean NOT NULL
  339. )
  340. ;
  341. -- ----------------------------
  342. -- Records of users
  343. -- ----------------------------
  344. BEGIN;
  345. INSERT INTO "users" VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);
  346. COMMIT;
  347. -- ----------------------------
  348. -- Indexes structure for table config_info
  349. -- ----------------------------
  350. CREATE UNIQUE INDEX "uk_configinfo_datagrouptenant" ON "config_info" ("data_id","group_id","tenant_id");
  351. -- ----------------------------
  352. -- Primary Key structure for table config_info
  353. -- ----------------------------
  354. ALTER TABLE "config_info" ADD CONSTRAINT "config_info_pkey" PRIMARY KEY ("id");
  355. -- ----------------------------
  356. -- Indexes structure for table config_info_aggr
  357. -- ----------------------------
  358. CREATE UNIQUE INDEX "uk_configinfoaggr_datagrouptenantdatum" ON "config_info_aggr" USING btree ("data_id","group_id","tenant_id","datum_id");
  359. -- ----------------------------
  360. -- Primary Key structure for table config_info_aggr
  361. -- ----------------------------
  362. ALTER TABLE "config_info_aggr" ADD CONSTRAINT "config_info_aggr_pkey" PRIMARY KEY ("id");
  363. -- ----------------------------
  364. -- Indexes structure for table config_info_beta
  365. -- ----------------------------
  366. CREATE UNIQUE INDEX "uk_configinfobeta_datagrouptenant" ON "config_info_beta" USING btree ("data_id","group_id","tenant_id");
  367. -- ----------------------------
  368. -- Primary Key structure for table config_info_beta
  369. -- ----------------------------
  370. ALTER TABLE "config_info_beta" ADD CONSTRAINT "config_info_beta_pkey" PRIMARY KEY ("id");
  371. -- ----------------------------
  372. -- Indexes structure for table config_info_tag
  373. -- ----------------------------
  374. CREATE UNIQUE INDEX "uk_configinfotag_datagrouptenanttag" ON "config_info_tag" USING btree ("data_id","group_id","tenant_id","tag_id");
  375. -- ----------------------------
  376. -- Primary Key structure for table config_info_tag
  377. -- ----------------------------
  378. ALTER TABLE "config_info_tag" ADD CONSTRAINT "config_info_tag_pkey" PRIMARY KEY ("id");
  379. -- ----------------------------
  380. -- Indexes structure for table config_tags_relation
  381. -- ----------------------------
  382. CREATE INDEX "idx_tenant_id" ON "config_tags_relation" USING btree (
  383.   "tenant_id"
  384. );
  385. CREATE UNIQUE INDEX "uk_configtagrelation_configidtag" ON "config_tags_relation" USING btree (
  386.   "id",
  387.   "tag_name",
  388.   "tag_type"
  389. );
  390. -- ----------------------------
  391. -- Primary Key structure for table config_tags_relation
  392. -- ----------------------------
  393. ALTER TABLE "config_tags_relation" ADD CONSTRAINT "config_tags_relation_pkey" PRIMARY KEY ("nid");
  394. -- ----------------------------
  395. -- Indexes structure for table group_capacity
  396. -- ----------------------------
  397. CREATE UNIQUE INDEX "uk_group_id" ON "group_capacity" USING btree (
  398.   "group_id"
  399. );
  400. -- ----------------------------
  401. -- Primary Key structure for table group_capacity
  402. -- ----------------------------
  403. ALTER TABLE "group_capacity" ADD CONSTRAINT "group_capacity_pkey" PRIMARY KEY ("id");
  404. -- ----------------------------
  405. -- Indexes structure for table his_config_info
  406. -- ----------------------------
  407. CREATE INDEX "idx_did" ON "his_config_info" USING btree (
  408.   "data_id"
  409. );
  410. CREATE INDEX "idx_gmt_create" ON "his_config_info" USING btree (
  411.   "gmt_create"
  412. );
  413. CREATE INDEX "idx_gmt_modified" ON "his_config_info" USING btree (
  414.   "gmt_modified"
  415. );
  416. -- ----------------------------
  417. -- Primary Key structure for table his_config_info
  418. -- ----------------------------
  419. ALTER TABLE "his_config_info" ADD CONSTRAINT "his_config_info_pkey" PRIMARY KEY ("nid");
  420. -- ----------------------------
  421. -- Indexes structure for table permissions
  422. -- ----------------------------
  423. CREATE UNIQUE INDEX "uk_role_permission" ON "permissions" USING btree (
  424.   "role",
  425.   "resource",
  426.   "action"
  427. );
  428. -- ----------------------------
  429. -- Indexes structure for table roles
  430. -- ----------------------------
  431. CREATE UNIQUE INDEX "uk_username_role" ON "roles" USING btree (
  432.   "username",
  433.   "role"
  434. );
  435. -- ----------------------------
  436. -- Indexes structure for table tenant_capacity
  437. -- ----------------------------
  438. CREATE UNIQUE INDEX "uk_tenant_id" ON "tenant_capacity" USING btree (
  439.   "tenant_id"
  440. );
  441. -- ----------------------------
  442. -- Primary Key structure for table tenant_capacity
  443. -- ----------------------------
  444. ALTER TABLE "tenant_capacity" ADD CONSTRAINT "tenant_capacity_pkey" PRIMARY KEY ("id");
  445. -- ----------------------------
  446. -- Indexes structure for table tenant_info
  447. -- ----------------------------
  448. CREATE UNIQUE INDEX "uk_tenant_info_kptenantid" ON "tenant_info" USING btree (
  449.   "kp",
  450.   "tenant_id"
  451. );
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

数据人与超自然意识

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表