diff --git a/.gitignore b/.gitignore index afc643b1c68b9ea8d4d40fc8f7a6df96fcda1706..b089f005b165cd33cb61a49f4c919ea22a0b8374 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,7 @@ hs_err_pid* .idea/ .gitee/ -.git/ \ No newline at end of file +.git/ +target/ + +dependency-reduced-pom.xml \ No newline at end of file diff --git a/.wiki/dev.md b/.wiki/dev.md new file mode 100644 index 0000000000000000000000000000000000000000..1d7389d46cc57217cab0cb8aa5ff0f64d314ec8d --- /dev/null +++ b/.wiki/dev.md @@ -0,0 +1,9 @@ +## SQL 参考手册 ++ [达梦 SQL 参考手册](https://eco.dameng.com/document/dm/zh-cn/pm/index.html) ++ [Kingbase SQL 参考手册](https://help.kingbase.com.cn/v8/development/sql-plsql/sql/index.html) ++ [MagicData SQL 参考手册](https://docs-opengauss.osinfra.cn/zh/docs/5.0.0/docs/SQLReference/%E5%87%BD%E6%95%B0%E5%92%8C%E6%93%8D%E4%BD%9C%E7%AC%A6.html) ++ [SqlServer SQL 参考手册](https://learn.microsoft.com/zh-cn/sql/t-sql/language-reference?view=sql-server-ver16) ++ [OpenGauss SQL 参考手册](https://docs-opengauss.osinfra.cn/zh/docs/5.0.0/docs/SQLReference/%E5%87%BD%E6%95%B0%E5%92%8C%E6%93%8D%E4%BD%9C%E7%AC%A6.html) ++ [Oracle SQL 参考手册](https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/index.html) ++ [PostgreSQL SQL 参考手册](https://www.postgresql.org/docs/15/index.html) + diff --git a/README.en.md b/README.en.md deleted file mode 100644 index b73edd823cb19581a98cc43ec42e31de63cc84dd..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# nacos-plugins - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index 6d74523172ea8ad6d0c0f1b6f82ec4df0515dd87..506d0dc3e30c7b26efb14cf9266c93433657bfc4 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,34 @@ # nacos-plugins #### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +针对Nacos提供多种插件支持: ++ nacos-plugin-datasource: 理论上可支持任意关系型数据库,实际已测试过的数据库清单: + + DM (达梦) + + Kingbase (金仓) + + MSSQL (SQLServer) + + OpenGauss (高斯) + + Oracle(8, 9, 10, 11, 12 ... ) + + PostgreSQL #### 软件架构 -软件架构说明 +作为nacos的插件使用 + +#### 版本映射 + +| 插件版本 | 构建时使用的nacos版本 | 支持的Nacos版本 | 测试过的nacos版本 | +| ------------- | :-------------------: | :-------------: | ----------------- | +| 1.0.x | 2.4.1 | 理论上是 all | 2.3.2、2.4.1 | +| 2.0.0 - 2.0.5 | 2.4.1 | 理论上是 all | 2.3.2、2.4.1 | +| | | | | + -#### 安装教程 -1. xxxx -2. xxxx -3. xxxx +#### 安装教程 +1. [nacosplugin-datasource 安装](./nacosplugin-datasource/installation.MD) #### 使用说明 -1. xxxx -2. xxxx -3. xxxx #### 参与贡献 @@ -27,13 +36,3 @@ Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/RELEASE-LOG.MD b/RELEASE-LOG.MD new file mode 100644 index 0000000000000000000000000000000000000000..16f098a29a5c0930503fd28533ec9387a46a5ab9 --- /dev/null +++ b/RELEASE-LOG.MD @@ -0,0 +1,29 @@ +## 2.0.6 +1. 解决OpenGauss中将`''`处理成NULL的情况 +## 2.0.5 +1. 完善版本比较机制,支持自行构建在版本。 +## 2.0.4 +1. 解决nacos中某些sql带有 \` 引号, 给其它数据库带来SQL语法错误的问题 +## 2.0.3 +1. 完善对oracle数据库的支持,重点针处理 oracle 会把 `''` 作为 `null` 处理。 +## 2.0.2 +1. 兼容nacos中的不合理SQL,对应nacos [github上的bug](https://github.com/alibaba/nacos/issues/12598) +2. 完善 oracle 的sql 脚本 + +## 2.0.1 +1. derby, mysql 仍然使用官方的 +2. 兼容nacos中的不合理设计,对于部分sql不使用?替换(nacos设计有问题),对应nacos [github上的bug](https://github.com/alibaba/nacos/issues/12585) + +## 2.0.0 +1. 代码重构,用一套代码即可实现数据库的支持 + +## 1.0.0 ++ 新特性: + + 提供nacos 数据源插件, nacos-plugin-datasource, 支持多种数据库: + + DM (达梦) + + Kingbase (金仓) + + MagicData + + MSSQL (SQLServer) + + OpenGauss (高斯) + + Oracle(8, 9, 10, 11, 12 ... ) + + PostgreSQL \ No newline at end of file diff --git a/build.bat b/build.bat new file mode 100644 index 0000000000000000000000000000000000000000..ac49d33b469cc34827dfa130a8c8bd20e0ed4dd7 --- /dev/null +++ b/build.bat @@ -0,0 +1,4 @@ +set JAVA_HOME=%JAVA_8_201_HOME% +set Path=%JAVA_HOME%/bin;%Path% +REM mvn -v +mvn clean package -DskipTests \ No newline at end of file diff --git a/nacosplugin-all/pom.xml b/nacosplugin-all/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..596699c6709823e84cb5f97acad7bea2e05ec2c1 --- /dev/null +++ b/nacosplugin-all/pom.xml @@ -0,0 +1,201 @@ + + + 4.0.0 + + io.github.bes2008.solution.nacosplugins + nacos-plugins + 2.0.6 + + + nacosplugin-all + ${project.groupId}:${project.artifactId}:${project.version} + + 3.4.1 + + + + + + io.github.bes2008.solution.nacosplugins + nacosplugin-datasource + + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + true + true + + + + shade-all + package + + shade + + + true + false + + + io.github.bes2008.solution.nacosplugins + io.github.bes2008.solution.sqlhelper + io.github.bes2008.solution.langx:langx-java + + + + + + io.github.bes2008.solution.nacosplugins + + META-INF/maven/** + + + + io.github.bes2008.solution.sqlhelper:sqlhelper-dialect + + META-INF/maven/** + + com/jn/sqlhelper/dialect/config/** + com/jn/sqlhelper/dialect/expression/** + com/jn/sqlhelper/dialect/instrument/** + com/jn/sqlhelper/dialect/orderby/** + com/jn/sqlhelper/dialect/pagination/Paged* + com/jn/sqlhelper/dialect/pagination/*Pagin* + com/jn/sqlhelper/dialect/parameter/** + com/jn/sqlhelper/dialect/sqlparser/** + com/jn/sqlhelper/dialect/tenant/** + com/jn/sqlhelper/dialect/SelectRequest* + com/jn/sqlhelper/dialect/SqlRequest* + + + + io.github.bes2008.solution.sqlhelper:sqlhelper-common + + META-INF/maven/** + + com/jn/sqlhelper/common/batch/** + com/jn/sqlhelper/common/connection/** + com/jn/sqlhelper/common/er/** + com/jn/sqlhelper/common/formatter/** + com/jn/sqlhelper/common/jdbc/** + com/jn/sqlhelper/common/resultset/** + com/jn/sqlhelper/common/security/** + com/jn/sqlhelper/common/statement/** + com/jn/sqlhelper/common/symbolmapper/** + com/jn/sqlhelper/common/transaction/** + + + + io.github.bes2008.solution.langx:langx-java + + META-INF/maven/** + + com/jn/langx/accessor/** + com/jn/langx/beans/** + com/jn/langx/cache/** + com/jn/langx/chain/** + com/jn/langx/codec/** + com/jn/langx/configuration/** + com/jn/langx/environment/** + com/jn/langx/event/** + com/jn/langx/http/** + com/jn/langx/invocation/** + com/jn/langx/io/stream/bandwidthlimit/** + com/jn/langx/io/stream/obj/** + com/jn/langx/io/stream/BufferEx* + com/jn/langx/io/stream/ConsumerTo* + com/jn/langx/io/stream/IOStream* + com/jn/langx/io/stream/InputStream* + com/jn/langx/io/stream/OutputStream* + com/jn/langx/io/stream/Progress* + com/jn/langx/io/stream/Unicode* + com/jn/langx/io/stream/UnsyncByte* + com/jn/langx/io/stream/Wrapped* + com/jn/langx/management/** + com/jn/langx/navigation/** + com/jn/langx/pipeline/** + com/jn/langx/plugin/** + com/jn/langx/propertyset/** + com/jn/langx/repository/** + com/jn/langx/security/** + + com/jn/langx/text/dfa/** + com/jn/langx/text/fragment/** + com/jn/langx/text/grok/** + com/jn/langx/text/i18n/** + com/jn/langx/text/ini/** + com/jn/langx/text/lexer/** + com/jn/langx/text/repository/** + com/jn/langx/text/sensitive/** + com/jn/langx/text/translate/** + com/jn/langx/text/xml/** + + com/jn/langx/util/bean/** + com/jn/langx/util/bit/** + com/jn/langx/util/bloom/** + + com/jn/langx/util/collection/exclusion/** + com/jn/langx/util/collection/forwarding/** + com/jn/langx/util/collection/graph/** + com/jn/langx/util/collection/list/** + com/jn/langx/util/collection/multivalue/** + com/jn/langx/util/collection/pushback/** + com/jn/langx/util/collection/stack/** + com/jn/langx/util/collection/tree/** + com/jn/langx/util/collection/trie/** + + com/jn/langx/util/concurrent/async/** + com/jn/langx/util/concurrent/clhm/** + com/jn/langx/util/concurrent/executor/** + com/jn/langx/util/concurrent/lock/** + com/jn/langx/util/concurrent/ConcurrentCyclicSequence* + com/jn/langx/util/concurrent/CopyOnWrite* + com/jn/langx/util/concurrent/MpscQueue* + com/jn/langx/util/concurrent/ThreadPoolProperties* + + com/jn/langx/util/converter/** + com/jn/langx/util/datetime/** + com/jn/langx/util/hash/*streming/** + com/jn/langx/util/hash/Hashing*Stream* + com/jn/langx/util/id/** + + com/jn/langx/util/io/bytes/** + com/jn/langx/util/io/unicode/** + com/jn/langx/util/io/Channels + com/jn/langx/util/io/IODebugger + com/jn/langx/util/io/ObjectIOs + + com/jn/langx/util/jar/** + com/jn/langx/util/jni/** + com/jn/langx/util/memory/** + com/jn/langx/util/net/** + com/jn/langx/util/pagination/** + com/jn/langx/util/pattern/** + com/jn/langx/util/progress/** + com/jn/langx/util/ranges/** + com/jn/langx/util/retry/** + com/jn/langx/util/reflect/classparse/** + com/jn/langx/util/script/** + com/jn/langx/util/timing/** + com/jn/langx/util/transformer/** + + + + + + + + + + + + + \ No newline at end of file diff --git a/nacosplugin-all/src/main/java/com/jn/nacos/plugin/JnNacosPlugin.java b/nacosplugin-all/src/main/java/com/jn/nacos/plugin/JnNacosPlugin.java new file mode 100644 index 0000000000000000000000000000000000000000..9785176d081b7e46175a057992ad2c8d75c83bad --- /dev/null +++ b/nacosplugin-all/src/main/java/com/jn/nacos/plugin/JnNacosPlugin.java @@ -0,0 +1,5 @@ +package com.jn.nacos.plugin; + +public class JnNacosPlugin { + private JnNacosPlugin(){} +} diff --git a/nacosplugin-datasource-sqlscript/pom.xml b/nacosplugin-datasource-sqlscript/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..cce5a821e750f2b382bab04b7ceee2a0056f0739 --- /dev/null +++ b/nacosplugin-datasource-sqlscript/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + io.github.bes2008.solution.nacosplugins + nacos-plugins + 2.0.6 + + + nacosplugin-datasource-sqlscript + ${project.groupId}:${project.artifactId}:${project.version} + + true + + + \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/README.MD b/nacosplugin-datasource-sqlscript/resources/sql/README.MD new file mode 100644 index 0000000000000000000000000000000000000000..0b2ebf461cd3085858bab78e7a984c25fac35ac1 --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/README.MD @@ -0,0 +1,6 @@ +在DDL语句中,identifier(表名、列名)的要求: ++ 尽量统一加上引号 ++ 如果不想统一加引号,按如下规则来处理: + + 不加引号的identifier,必须使用小写形式 (原因: nacos 中的代码中,将列名、表名都是定死的小写),由数据库内部自行处理。 + + 加引号的identifier,按照数据库对不加引号的identifier的处理方式来处理。 + + 例如:oracle 对不加引号的 identifier 默认全部转换成大写形式。那么在使用引号时,就必须全部使用大写形式。 \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/dm/create-schema.sql b/nacosplugin-datasource-sqlscript/resources/sql/dm/create-schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..e3c3c18f6bffe87cb09fad1bfde5e5348de5c578 --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/dm/create-schema.sql @@ -0,0 +1,5 @@ +DROP SCHEMA if EXISTS nacos CASCADE; +CREATE SCHEMA nacos; +/ + +exit \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/dm/create-tables.sql b/nacosplugin-datasource-sqlscript/resources/sql/dm/create-tables.sql new file mode 100644 index 0000000000000000000000000000000000000000..f2e127c925e1cd5ad41a409791c82579ffff84de --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/dm/create-tables.sql @@ -0,0 +1,454 @@ +ALTER SESSION SET CURRENT_SCHEMA=nacos; + +-- ---------------------------- +-- Table structure for config_info +-- ---------------------------- +DROP TABLE IF EXISTS "config_info"; +CREATE TABLE "config_info" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "app_name" varchar(128) , + "tenant_id" varchar(128) , + "c_desc" varchar(256) , + "c_use" varchar(64) , + "effect" varchar(64) , + "type" varchar(64) , + "c_schema" text , + "encrypted_data_key" text +); + +COMMENT ON COLUMN "config_info"."id" IS 'id'; +COMMENT ON COLUMN "config_info"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info"."content" IS 'content'; +COMMENT ON COLUMN "config_info"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info"."src_ip" IS 'source ip'; +COMMENT ON COLUMN "config_info"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "config_info"."effect" IS '配置生效描述'; +COMMENT ON COLUMN "config_info"."type" IS '配置的类型'; +COMMENT ON COLUMN "config_info"."c_schema" IS '配置的模式'; +COMMENT ON COLUMN "config_info"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "config_info" IS 'config_info'; + +-- ---------------------------- +-- Indexes structure for table config_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfo_datagrouptenant" ON "config_info" ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info +-- ---------------------------- +ALTER TABLE "config_info" ADD CONSTRAINT "config_info_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_aggr +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_aggr"; +CREATE TABLE "config_info_aggr" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) NOT NULL, + "datum_id" varchar(255) NOT NULL, + "content" text NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "app_name" varchar(128) , + "tenant_id" varchar(128) +); + +COMMENT ON COLUMN "config_info_aggr"."id" IS 'id'; +COMMENT ON COLUMN "config_info_aggr"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_aggr"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_aggr"."datum_id" IS 'datum_id'; +COMMENT ON COLUMN "config_info_aggr"."content" IS '内容'; +COMMENT ON COLUMN "config_info_aggr"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_aggr"."tenant_id" IS '租户字段'; +COMMENT ON TABLE "config_info_aggr" IS '增加租户字段'; + + +-- ---------------------------- +-- Indexes structure for table config_info_aggr +-- ---------------------------- +CREATE UNIQUE INDEX IF NOT EXISTS "uk_configinfoaggr_datagrouptenantdatum" ON "config_info_aggr" ("data_id","group_id","tenant_id","datum_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_aggr +-- ---------------------------- +ALTER TABLE "config_info_aggr" ADD CONSTRAINT "config_info_aggr_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_beta +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_beta"; +CREATE TABLE "config_info_beta" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "beta_ips" varchar(1024) , + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "tenant_id" varchar(128) , + "encrypted_data_key" text +); +COMMENT ON COLUMN "config_info_beta"."id" IS 'id'; +COMMENT ON COLUMN "config_info_beta"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_beta"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_beta"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info_beta"."content" IS 'content'; +COMMENT ON COLUMN "config_info_beta"."beta_ips" IS 'betaIps'; +COMMENT ON COLUMN "config_info_beta"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info_beta"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info_beta"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_beta"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info_beta"."src_ip" IS 'source ip'; +COMMENT ON COLUMN "config_info_beta"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "config_info_beta"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "config_info_beta" IS 'config_info_beta'; + + +-- ---------------------------- +-- Indexes structure for table config_info_beta +-- ---------------------------- +CREATE UNIQUE INDEX IF NOT EXISTS "uk_configinfobeta_datagrouptenant" ON "config_info_beta" ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_beta +-- ---------------------------- +ALTER TABLE "config_info_beta" ADD CONSTRAINT "config_info_beta_pkey" PRIMARY KEY ("id"); + + +-- ---------------------------- +-- Table structure for config_info_tag +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_tag"; +CREATE TABLE "config_info_tag" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tag_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) +); +COMMENT ON COLUMN "config_info_tag"."id" IS 'id'; +COMMENT ON COLUMN "config_info_tag"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_tag"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_tag"."tenant_id" IS 'tenant_id'; +COMMENT ON COLUMN "config_info_tag"."tag_id" IS 'tag_id'; +COMMENT ON COLUMN "config_info_tag"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info_tag"."content" IS 'content'; +COMMENT ON COLUMN "config_info_tag"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info_tag"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info_tag"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_tag"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info_tag"."src_ip" IS 'source ip'; +COMMENT ON TABLE "config_info_tag" IS 'config_info_tag'; + + +-- ---------------------------- +-- Indexes structure for table config_info_tag +-- ---------------------------- +CREATE UNIQUE INDEX IF NOT EXISTS "uk_configinfotag_datagrouptenanttag" ON "config_info_tag" ("data_id","group_id","tenant_id","tag_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_tag +-- ---------------------------- +ALTER TABLE "config_info_tag" ADD CONSTRAINT "config_info_tag_pkey" PRIMARY KEY ("id"); + +-- ---------------------------- +-- Table structure for config_tags_relation +-- ---------------------------- +DROP TABLE IF EXISTS "config_tags_relation"; +CREATE TABLE "config_tags_relation" ( + "id" BIGINT NOT NULL, + "tag_name" varchar(128) NOT NULL, + "tag_type" varchar(64) , + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "nid" BIGINT NOT NULL IDENTITY(1,1) +); + +COMMENT ON COLUMN "config_tags_relation"."id" IS 'id'; +COMMENT ON COLUMN "config_tags_relation"."tag_name" IS 'tag_name'; +COMMENT ON COLUMN "config_tags_relation"."tag_type" IS 'tag_type'; +COMMENT ON COLUMN "config_tags_relation"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_tags_relation"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_tags_relation"."tenant_id" IS 'tenant_id'; +COMMENT ON TABLE "config_tags_relation" IS 'config_tag_relation'; + + + +-- ---------------------------- +-- Indexes structure for table config_tags_relation +-- ---------------------------- +CREATE INDEX IF NOT EXISTS "idx_tenant_id" ON "config_tags_relation" ( + "tenant_id" + ); +CREATE UNIQUE INDEX IF NOT EXISTS "uk_configtagrelation_configidtag" ON "config_tags_relation" ( + "id", + "tag_name", + "tag_type" + ); + +-- ---------------------------- +-- Primary Key structure for table config_tags_relation +-- ---------------------------- +ALTER TABLE "config_tags_relation" ADD CONSTRAINT "config_tags_relation_pkey" PRIMARY KEY ("nid"); + + + + +-- ---------------------------- +-- Table structure for group_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "group_capacity"; +CREATE TABLE "group_capacity" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "group_id" varchar(128) NOT NULL, + "quota" INT NOT NULL, + "usage" INT NOT NULL, + "max_size" INT NOT NULL, + "max_aggr_count" INT NOT NULL, + "max_aggr_size" INT NOT NULL, + "max_history_count" INT NOT NULL, + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL +); +COMMENT ON COLUMN "group_capacity"."id" IS '主键ID'; +COMMENT ON COLUMN "group_capacity"."group_id" IS 'Group ID,空字符表示整个集群'; +COMMENT ON COLUMN "group_capacity"."quota" IS '配额,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."usage" IS '使用量'; +COMMENT ON COLUMN "group_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_aggr_count" IS '聚合子配置最大个数,,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_history_count" IS '最大变更历史数量'; +COMMENT ON COLUMN "group_capacity"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "group_capacity"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "group_capacity" IS '集群、各Group容量信息表'; + + + +-- ---------------------------- +-- Indexes structure for table group_capacity +-- ---------------------------- +CREATE UNIQUE INDEX IF NOT EXISTS "uk_group_id" ON "group_capacity" ( + "group_id" + ); + +-- ---------------------------- +-- Primary Key structure for table group_capacity +-- ---------------------------- +ALTER TABLE "group_capacity" ADD CONSTRAINT "group_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for his_config_info +-- ---------------------------- +DROP TABLE IF EXISTS "his_config_info"; +CREATE TABLE "his_config_info" ( + "id" BIGINT NOT NULL, + "nid" BIGINT NOT NULL IDENTITY(1,1), + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL DEFAULT '2010-05-05 00:00:00', + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "op_type" char(10) , + "tenant_id" varchar(128) , + "encrypted_data_key" text +); +COMMENT ON COLUMN "his_config_info"."app_name" IS 'app_name'; +COMMENT ON COLUMN "his_config_info"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "his_config_info"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "his_config_info" IS '多租户改造'; + + +-- ---------------------------- +-- Indexes structure for table his_config_info +-- ---------------------------- +CREATE INDEX IF NOT EXISTS "idx_did" ON "his_config_info" ( + "data_id" + ); +CREATE INDEX IF NOT EXISTS "idx_gmt_create" ON "his_config_info" ( + "gmt_create" + ); +CREATE INDEX IF NOT EXISTS "idx_gmt_modified" ON "his_config_info" ( + "gmt_modified" + ); + +-- ---------------------------- +-- Primary Key structure for table his_config_info +-- ---------------------------- +ALTER TABLE "his_config_info" ADD CONSTRAINT "his_config_info_pkey" PRIMARY KEY ("nid"); + + +-- ---------------------------- +-- Table structure for tenant_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_capacity"; +CREATE TABLE "tenant_capacity" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "tenant_id" varchar(128) NOT NULL, + "quota" INT NOT NULL, + "usage" INT NOT NULL, + "max_size" INT NOT NULL, + "max_aggr_count" INT NOT NULL, + "max_aggr_size" INT NOT NULL, + "max_history_count" INT NOT NULL, + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL +) +; +COMMENT ON COLUMN "tenant_capacity"."id" IS '主键ID'; +COMMENT ON COLUMN "tenant_capacity"."tenant_id" IS 'Tenant ID'; +COMMENT ON COLUMN "tenant_capacity"."quota" IS '配额,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."usage" IS '使用量'; +COMMENT ON COLUMN "tenant_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."max_aggr_count" IS '聚合子配置最大个数'; +COMMENT ON COLUMN "tenant_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."max_history_count" IS '最大变更历史数量'; +COMMENT ON COLUMN "tenant_capacity"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "tenant_capacity"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "tenant_capacity" IS '租户容量信息表'; + + +-- ---------------------------- +-- Indexes structure for table tenant_capacity +-- ---------------------------- +CREATE UNIQUE INDEX IF NOT EXISTS "uk_tenant_id" ON "tenant_capacity" ( + "tenant_id" + ); + +-- ---------------------------- +-- Primary Key structure for table tenant_capacity +-- ---------------------------- +ALTER TABLE "tenant_capacity" ADD CONSTRAINT "tenant_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for tenant_info +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_info"; +CREATE TABLE "tenant_info" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "kp" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tenant_name" varchar(128) , + "tenant_desc" varchar(256) , + "create_source" varchar(32) , + "gmt_create" BIGINT NOT NULL, + "gmt_modified" BIGINT NOT NULL +); +COMMENT ON COLUMN "tenant_info"."id" IS 'id'; +COMMENT ON COLUMN "tenant_info"."kp" IS 'kp'; +COMMENT ON COLUMN "tenant_info"."tenant_id" IS 'tenant_id'; +COMMENT ON COLUMN "tenant_info"."tenant_name" IS 'tenant_name'; +COMMENT ON COLUMN "tenant_info"."tenant_desc" IS 'tenant_desc'; +COMMENT ON COLUMN "tenant_info"."create_source" IS 'create_source'; +COMMENT ON COLUMN "tenant_info"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "tenant_info"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "tenant_info" IS 'tenant_info'; + +-- ---------------------------- +-- Indexes structure for table tenant_info +-- ---------------------------- +CREATE UNIQUE INDEX IF NOT EXISTS "uk_tenant_info_kptenantid" ON "tenant_info" ( + "kp", + "tenant_id" + ); + + + +-- ---------------------------- +-- Table structure for users +-- ---------------------------- +DROP TABLE IF EXISTS "users"; +CREATE TABLE "users" ( + "username" varchar(50) NOT NULL, + "password" varchar(500) NOT NULL, + "enabled" BIT NOT NULL +); + + +-- ---------------------------- +-- Table structure for roles +-- ---------------------------- +DROP TABLE IF EXISTS "roles"; +CREATE TABLE "roles" ( + "username" varchar(50) NOT NULL, + "role" varchar(50) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table roles +-- ---------------------------- +CREATE UNIQUE INDEX IF NOT EXISTS "uk_username_role" ON "roles" ( + "username", + "role" + ); + +-- ---------------------------- +-- Table structure for permissions +-- ---------------------------- +DROP TABLE IF EXISTS "permissions"; +CREATE TABLE "permissions" ( + "role" varchar(50) NOT NULL, + "resource" varchar(512) NOT NULL, + "action" varchar(8) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table permissions +-- ---------------------------- +CREATE UNIQUE INDEX IF NOT EXISTS "uk_role_permission" ON "permissions" ( + "role", + "resource", + "action" + ); + + +-- ---------------------------- +-- Records of users +-- ---------------------------- +INSERT INTO "users" VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1); + + +-- ---------------------------- +-- Records of roles +-- ---------------------------- + +INSERT INTO "roles" VALUES ('nacos', 'ROLE_ADMIN'); + +exit \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/kingbase/create-schema.sql b/nacosplugin-datasource-sqlscript/resources/sql/kingbase/create-schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..15640f509da2b1915c8d626e16828799c9a3803e --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/kingbase/create-schema.sql @@ -0,0 +1,2 @@ +DROP schema if EXISTS nacos CASCADE; +CREATE SCHEMA nacos; \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/kingbase/create-tables.sql b/nacosplugin-datasource-sqlscript/resources/sql/kingbase/create-tables.sql new file mode 100644 index 0000000000000000000000000000000000000000..0c91adfca7b9ddcc312fd3c324d878eb132159c4 --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/kingbase/create-tables.sql @@ -0,0 +1,453 @@ +SET search_path TO nacos; + + +-- ---------------------------- +-- Table structure for config_info +-- ---------------------------- +DROP TABLE IF EXISTS "config_info"; +CREATE TABLE "config_info" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "app_name" varchar(128) , + "tenant_id" varchar(128) , + "c_desc" varchar(256) , + "c_use" varchar(64) , + "effect" varchar(64) , + "type" varchar(64) , + "c_schema" text , + "encrypted_data_key" text +); + +COMMENT ON COLUMN "config_info"."id" IS 'id'; +COMMENT ON COLUMN "config_info"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info"."content" IS 'content'; +COMMENT ON COLUMN "config_info"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info"."src_ip" IS 'source ip'; +COMMENT ON COLUMN "config_info"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "config_info"."effect" IS '配置生效描述'; +COMMENT ON COLUMN "config_info"."type" IS '配置的类型'; +COMMENT ON COLUMN "config_info"."c_schema" IS '配置的模式'; +COMMENT ON COLUMN "config_info"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "config_info" IS 'config_info'; + +-- ---------------------------- +-- Indexes structure for table config_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfo_datagrouptenant" ON "config_info" ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info +-- ---------------------------- +ALTER TABLE "config_info" ADD CONSTRAINT "config_info_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_aggr +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_aggr"; +CREATE TABLE "config_info_aggr" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) NOT NULL, + "datum_id" varchar(255) NOT NULL, + "content" text NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "app_name" varchar(128) , + "tenant_id" varchar(128) +); +COMMENT ON COLUMN "config_info_aggr"."id" IS 'id'; +COMMENT ON COLUMN "config_info_aggr"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_aggr"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_aggr"."datum_id" IS 'datum_id'; +COMMENT ON COLUMN "config_info_aggr"."content" IS '内容'; +COMMENT ON COLUMN "config_info_aggr"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_aggr"."tenant_id" IS '租户字段'; +COMMENT ON TABLE "config_info_aggr" IS '增加租户字段'; + + +-- ---------------------------- +-- Indexes structure for table config_info_aggr +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfoaggr_datagrouptenantdatum" ON "config_info_aggr" USING btree ("data_id","group_id","tenant_id","datum_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_aggr +-- ---------------------------- +ALTER TABLE "config_info_aggr" ADD CONSTRAINT "config_info_aggr_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_beta +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_beta"; +CREATE TABLE "config_info_beta" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "beta_ips" varchar(1024) , + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "tenant_id" varchar(128) , + "encrypted_data_key" text +); +COMMENT ON COLUMN "config_info_beta"."id" IS 'id'; +COMMENT ON COLUMN "config_info_beta"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_beta"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_beta"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info_beta"."content" IS 'content'; +COMMENT ON COLUMN "config_info_beta"."beta_ips" IS 'betaIps'; +COMMENT ON COLUMN "config_info_beta"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info_beta"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info_beta"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_beta"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info_beta"."src_ip" IS 'source ip'; +COMMENT ON COLUMN "config_info_beta"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "config_info_beta"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "config_info_beta" IS 'config_info_beta'; + + +-- ---------------------------- +-- Indexes structure for table config_info_beta +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfobeta_datagrouptenant" ON "config_info_beta" USING btree ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_beta +-- ---------------------------- +ALTER TABLE "config_info_beta" ADD CONSTRAINT "config_info_beta_pkey" PRIMARY KEY ("id"); + + +-- ---------------------------- +-- Table structure for config_info_tag +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_tag"; +CREATE TABLE "config_info_tag" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tag_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) +); +COMMENT ON COLUMN "config_info_tag"."id" IS 'id'; +COMMENT ON COLUMN "config_info_tag"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_tag"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_tag"."tenant_id" IS 'tenant_id'; +COMMENT ON COLUMN "config_info_tag"."tag_id" IS 'tag_id'; +COMMENT ON COLUMN "config_info_tag"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info_tag"."content" IS 'content'; +COMMENT ON COLUMN "config_info_tag"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info_tag"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info_tag"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_tag"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info_tag"."src_ip" IS 'source ip'; +COMMENT ON TABLE "config_info_tag" IS 'config_info_tag'; + + +-- ---------------------------- +-- Indexes structure for table config_info_tag +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfotag_datagrouptenanttag" ON "config_info_tag" USING btree ("data_id","group_id","tenant_id","tag_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_tag +-- ---------------------------- +ALTER TABLE "config_info_tag" ADD CONSTRAINT "config_info_tag_pkey" PRIMARY KEY ("id"); + +-- ---------------------------- +-- Table structure for config_tags_relation +-- ---------------------------- +DROP TABLE IF EXISTS "config_tags_relation"; +CREATE TABLE "config_tags_relation" ( + "id" bigint NOT NULL, + "tag_name" varchar(128) NOT NULL, + "tag_type" varchar(64) , + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "nid" bigserial NOT NULL +); +COMMENT ON COLUMN "config_tags_relation"."id" IS 'id'; +COMMENT ON COLUMN "config_tags_relation"."tag_name" IS 'tag_name'; +COMMENT ON COLUMN "config_tags_relation"."tag_type" IS 'tag_type'; +COMMENT ON COLUMN "config_tags_relation"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_tags_relation"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_tags_relation"."tenant_id" IS 'tenant_id'; +COMMENT ON TABLE "config_tags_relation" IS 'config_tag_relation'; + + + +-- ---------------------------- +-- Indexes structure for table config_tags_relation +-- ---------------------------- +CREATE INDEX "idx_tenant_id" ON "config_tags_relation" USING btree ( + "tenant_id" + ); +CREATE UNIQUE INDEX "uk_configtagrelation_configidtag" ON "config_tags_relation" USING btree ( + "id", + "tag_name", + "tag_type" + ); + +-- ---------------------------- +-- Primary Key structure for table config_tags_relation +-- ---------------------------- +ALTER TABLE "config_tags_relation" ADD CONSTRAINT "config_tags_relation_pkey" PRIMARY KEY ("nid"); + + + + +-- ---------------------------- +-- Table structure for group_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "group_capacity"; +CREATE TABLE "group_capacity" ( + "id" bigserial NOT NULL, + "group_id" varchar(128) NOT NULL, + "quota" int4 NOT NULL, + "usage" int4 NOT NULL, + "max_size" int4 NOT NULL, + "max_aggr_count" int4 NOT NULL, + "max_aggr_size" int4 NOT NULL, + "max_history_count" int4 NOT NULL, + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL +); +COMMENT ON COLUMN "group_capacity"."id" IS '主键ID'; +COMMENT ON COLUMN "group_capacity"."group_id" IS 'Group ID,空字符表示整个集群'; +COMMENT ON COLUMN "group_capacity"."quota" IS '配额,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."usage" IS '使用量'; +COMMENT ON COLUMN "group_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_aggr_count" IS '聚合子配置最大个数,,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_history_count" IS '最大变更历史数量'; +COMMENT ON COLUMN "group_capacity"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "group_capacity"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "group_capacity" IS '集群、各Group容量信息表'; + + + +-- ---------------------------- +-- Indexes structure for table group_capacity +-- ---------------------------- +CREATE UNIQUE INDEX "uk_group_id" ON "group_capacity" USING btree ( + "group_id" + ); + +-- ---------------------------- +-- Primary Key structure for table group_capacity +-- ---------------------------- +ALTER TABLE "group_capacity" ADD CONSTRAINT "group_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for his_config_info +-- ---------------------------- +DROP TABLE IF EXISTS "his_config_info"; +CREATE TABLE "his_config_info" ( + "id" int8 NOT NULL, + "nid" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL DEFAULT '2010-05-05 00:00:00', + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "op_type" char(10) , + "tenant_id" varchar(128) , + "encrypted_data_key" text +); +COMMENT ON COLUMN "his_config_info"."app_name" IS 'app_name'; +COMMENT ON COLUMN "his_config_info"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "his_config_info"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "his_config_info" IS '多租户改造'; + + +-- ---------------------------- +-- Indexes structure for table his_config_info +-- ---------------------------- +CREATE INDEX "idx_did" ON "his_config_info" USING btree ( + "data_id" + ); +CREATE INDEX "idx_gmt_create" ON "his_config_info" USING btree ( + "gmt_create" + ); +CREATE INDEX "idx_gmt_modified" ON "his_config_info" USING btree ( + "gmt_modified" + ); + +-- ---------------------------- +-- Primary Key structure for table his_config_info +-- ---------------------------- +ALTER TABLE "his_config_info" ADD CONSTRAINT "his_config_info_pkey" PRIMARY KEY ("nid"); + + +-- ---------------------------- +-- Table structure for tenant_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_capacity"; +CREATE TABLE "tenant_capacity" ( + "id" bigserial NOT NULL, + "tenant_id" varchar(128) NOT NULL, + "quota" int4 NOT NULL, + "usage" int4 NOT NULL, + "max_size" int4 NOT NULL, + "max_aggr_count" int4 NOT NULL, + "max_aggr_size" int4 NOT NULL, + "max_history_count" int4 NOT NULL, + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL +); +COMMENT ON COLUMN "tenant_capacity"."id" IS '主键ID'; +COMMENT ON COLUMN "tenant_capacity"."tenant_id" IS 'Tenant ID'; +COMMENT ON COLUMN "tenant_capacity"."quota" IS '配额,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."usage" IS '使用量'; +COMMENT ON COLUMN "tenant_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."max_aggr_count" IS '聚合子配置最大个数'; +COMMENT ON COLUMN "tenant_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."max_history_count" IS '最大变更历史数量'; +COMMENT ON COLUMN "tenant_capacity"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "tenant_capacity"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "tenant_capacity" IS '租户容量信息表'; + + +-- ---------------------------- +-- Indexes structure for table tenant_capacity +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_id" ON "tenant_capacity" USING btree ( + "tenant_id" + ); + +-- ---------------------------- +-- Primary Key structure for table tenant_capacity +-- ---------------------------- +ALTER TABLE "tenant_capacity" ADD CONSTRAINT "tenant_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for tenant_info +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_info"; +CREATE TABLE "tenant_info" ( + "id" bigserial NOT NULL, + "kp" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tenant_name" varchar(128) , + "tenant_desc" varchar(256) , + "create_source" varchar(32) , + "gmt_create" int8 NOT NULL, + "gmt_modified" int8 NOT NULL +); +COMMENT ON COLUMN "tenant_info"."id" IS 'id'; +COMMENT ON COLUMN "tenant_info"."kp" IS 'kp'; +COMMENT ON COLUMN "tenant_info"."tenant_id" IS 'tenant_id'; +COMMENT ON COLUMN "tenant_info"."tenant_name" IS 'tenant_name'; +COMMENT ON COLUMN "tenant_info"."tenant_desc" IS 'tenant_desc'; +COMMENT ON COLUMN "tenant_info"."create_source" IS 'create_source'; +COMMENT ON COLUMN "tenant_info"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "tenant_info"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "tenant_info" IS 'tenant_info'; + +-- ---------------------------- +-- Indexes structure for table tenant_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_info_kptenantid" ON "tenant_info" USING btree ( + "kp", + "tenant_id" + ); + + + +-- ---------------------------- +-- Table structure for users +-- ---------------------------- +DROP TABLE IF EXISTS "users"; +CREATE TABLE "users" ( + "username" varchar(50) NOT NULL, + "password" varchar(500) NOT NULL, + "enabled" boolean NOT NULL +); + + +-- ---------------------------- +-- Table structure for roles +-- ---------------------------- +DROP TABLE IF EXISTS "roles"; +CREATE TABLE "roles" ( + "username" varchar(50) NOT NULL, + "role" varchar(50) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table roles +-- ---------------------------- +CREATE UNIQUE INDEX "uk_username_role" ON "roles" USING btree ( + "username", + "role" + ); + +-- ---------------------------- +-- Table structure for permissions +-- ---------------------------- +DROP TABLE IF EXISTS "permissions"; +CREATE TABLE "permissions" ( + "role" varchar(50) NOT NULL, + "resource" varchar(512) NOT NULL, + "action" varchar(8) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table permissions +-- ---------------------------- +CREATE UNIQUE INDEX "uk_role_permission" ON "permissions" USING btree ( + "role", + "resource", + "action" + ); + + +-- ---------------------------- +-- Records of users +-- ---------------------------- +INSERT INTO "users" VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE); + + +-- ---------------------------- +-- Records of roles +-- ---------------------------- + +INSERT INTO "roles" VALUES ('nacos', 'ROLE_ADMIN'); + + +COMMIT; \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/magicdata/create-schema.sql b/nacosplugin-datasource-sqlscript/resources/sql/magicdata/create-schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..3d934f29815e053851af8b46e04620dfe12b0dc8 --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/magicdata/create-schema.sql @@ -0,0 +1 @@ +CREATE SCHEMA nacos; \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/magicdata/create-tables.sql b/nacosplugin-datasource-sqlscript/resources/sql/magicdata/create-tables.sql new file mode 100644 index 0000000000000000000000000000000000000000..1c3e1f8a8d0090c082c77075a46025885db8024f --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/magicdata/create-tables.sql @@ -0,0 +1,449 @@ +SET search_path TO nacos; + + +-- ---------------------------- +-- Table structure for config_info +-- ---------------------------- +DROP TABLE IF EXISTS "config_info"; +CREATE TABLE "config_info" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(6) NOT NULL, + "gmt_modified" timestamp(6) NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "app_name" varchar(128) , + "tenant_id" varchar(128) , + "c_desc" varchar(256) , + "c_use" varchar(64) , + "effect" varchar(64) , + "type" varchar(64) , + "c_schema" text , + "encrypted_data_key" text +); + +COMMENT ON COLUMN "config_info"."id" IS 'id'; +COMMENT ON COLUMN "config_info"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info"."content" IS 'content'; +COMMENT ON COLUMN "config_info"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info"."src_ip" IS 'source ip'; +COMMENT ON COLUMN "config_info"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "config_info"."effect" IS '配置生效描述'; +COMMENT ON COLUMN "config_info"."type" IS '配置的类型'; +COMMENT ON COLUMN "config_info"."c_schema" IS '配置的模式'; +COMMENT ON COLUMN "config_info"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "config_info" IS 'config_info'; + +-- ---------------------------- +-- Indexes structure for table config_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfo_datagrouptenant" ON "config_info" ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info +-- ---------------------------- +ALTER TABLE "config_info" ADD CONSTRAINT "config_info_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_aggr +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_aggr"; +CREATE TABLE "config_info_aggr" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) NOT NULL, + "datum_id" varchar(255) NOT NULL, + "content" text NOT NULL, + "gmt_modified" timestamp(6) NOT NULL, + "app_name" varchar(128) , + "tenant_id" varchar(128) +); +COMMENT ON COLUMN "config_info_aggr"."id" IS 'id'; +COMMENT ON COLUMN "config_info_aggr"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_aggr"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_aggr"."datum_id" IS 'datum_id'; +COMMENT ON COLUMN "config_info_aggr"."content" IS '内容'; +COMMENT ON COLUMN "config_info_aggr"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_aggr"."tenant_id" IS '租户字段'; +COMMENT ON TABLE "config_info_aggr" IS '增加租户字段'; + + +-- ---------------------------- +-- Indexes structure for table config_info_aggr +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfoaggr_datagrouptenantdatum" ON "config_info_aggr" USING btree ("data_id","group_id","tenant_id","datum_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_aggr +-- ---------------------------- +ALTER TABLE "config_info_aggr" ADD CONSTRAINT "config_info_aggr_pkey" PRIMARY KEY ("id"); + + +-- ---------------------------- +-- Table structure for config_info_beta +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_beta"; +CREATE TABLE "config_info_beta" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "beta_ips" varchar(1024) , + "md5" varchar(32) , + "gmt_create" timestamp(6) NOT NULL, + "gmt_modified" timestamp(6) NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "tenant_id" varchar(128) , + "encrypted_data_key" text +); +COMMENT ON COLUMN "config_info_beta"."id" IS 'id'; +COMMENT ON COLUMN "config_info_beta"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_beta"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_beta"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info_beta"."content" IS 'content'; +COMMENT ON COLUMN "config_info_beta"."beta_ips" IS 'betaIps'; +COMMENT ON COLUMN "config_info_beta"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info_beta"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info_beta"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_beta"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info_beta"."src_ip" IS 'source ip'; +COMMENT ON COLUMN "config_info_beta"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "config_info_beta"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "config_info_beta" IS 'config_info_beta'; + + +-- ---------------------------- +-- Indexes structure for table config_info_beta +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfobeta_datagrouptenant" ON "config_info_beta" USING btree ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_beta +-- ---------------------------- +ALTER TABLE "config_info_beta" ADD CONSTRAINT "config_info_beta_pkey" PRIMARY KEY ("id"); + + + + +-- ---------------------------- +-- Table structure for config_info_tag +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_tag"; +CREATE TABLE "config_info_tag" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tag_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(6) NOT NULL, + "gmt_modified" timestamp(6) NOT NULL, + "src_user" text , + "src_ip" varchar(20) +); +COMMENT ON COLUMN "config_info_tag"."id" IS 'id'; +COMMENT ON COLUMN "config_info_tag"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_tag"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_tag"."tenant_id" IS 'tenant_id'; +COMMENT ON COLUMN "config_info_tag"."tag_id" IS 'tag_id'; +COMMENT ON COLUMN "config_info_tag"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info_tag"."content" IS 'content'; +COMMENT ON COLUMN "config_info_tag"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info_tag"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info_tag"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_tag"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info_tag"."src_ip" IS 'source ip'; +COMMENT ON TABLE "config_info_tag" IS 'config_info_tag'; + + +-- ---------------------------- +-- Indexes structure for table config_info_tag +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfotag_datagrouptenanttag" ON "config_info_tag" USING btree ("data_id","group_id","tenant_id","tag_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_tag +-- ---------------------------- +ALTER TABLE "config_info_tag" ADD CONSTRAINT "config_info_tag_pkey" PRIMARY KEY ("id"); + + +-- ---------------------------- +-- Table structure for config_tags_relation +-- ---------------------------- +DROP TABLE IF EXISTS "config_tags_relation"; +CREATE TABLE "config_tags_relation" ( + "id" bigint NOT NULL, + "tag_name" varchar(128) NOT NULL, + "tag_type" varchar(64) , + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "nid" bigserial NOT NULL +); +COMMENT ON COLUMN "config_tags_relation"."id" IS 'id'; +COMMENT ON COLUMN "config_tags_relation"."tag_name" IS 'tag_name'; +COMMENT ON COLUMN "config_tags_relation"."tag_type" IS 'tag_type'; +COMMENT ON COLUMN "config_tags_relation"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_tags_relation"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_tags_relation"."tenant_id" IS 'tenant_id'; +COMMENT ON TABLE "config_tags_relation" IS 'config_tag_relation'; + + + +-- ---------------------------- +-- Indexes structure for table config_tags_relation +-- ---------------------------- +CREATE INDEX "idx_tenant_id" ON "config_tags_relation" USING btree ( + "tenant_id" + ); +CREATE UNIQUE INDEX "uk_configtagrelation_configidtag" ON "config_tags_relation" USING btree ( + "id", + "tag_name", + "tag_type" + ); + +-- ---------------------------- +-- Primary Key structure for table config_tags_relation +-- ---------------------------- +ALTER TABLE "config_tags_relation" ADD CONSTRAINT "config_tags_relation_pkey" PRIMARY KEY ("nid"); + +-- ---------------------------- +-- Table structure for group_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "group_capacity"; +CREATE TABLE "group_capacity" ( + "id" bigserial NOT NULL, + "group_id" varchar(128) NOT NULL, + "quota" int4 NOT NULL, + "usage" int4 NOT NULL, + "max_size" int4 NOT NULL, + "max_aggr_count" int4 NOT NULL, + "max_aggr_size" int4 NOT NULL, + "max_history_count" int4 NOT NULL, + "gmt_create" timestamp(6) NOT NULL, + "gmt_modified" timestamp(6) NOT NULL +) +; +COMMENT ON COLUMN "group_capacity"."id" IS '主键ID'; +COMMENT ON COLUMN "group_capacity"."group_id" IS 'Group ID,空字符表示整个集群'; +COMMENT ON COLUMN "group_capacity"."quota" IS '配额,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."usage" IS '使用量'; +COMMENT ON COLUMN "group_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_aggr_count" IS '聚合子配置最大个数,,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_history_count" IS '最大变更历史数量'; +COMMENT ON COLUMN "group_capacity"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "group_capacity"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "group_capacity" IS '集群、各Group容量信息表'; + + + +-- ---------------------------- +-- Indexes structure for table group_capacity +-- ---------------------------- +CREATE UNIQUE INDEX "uk_group_id" ON "group_capacity" USING btree ( + "group_id" + ); + +-- ---------------------------- +-- Primary Key structure for table group_capacity +-- ---------------------------- +ALTER TABLE "group_capacity" ADD CONSTRAINT "group_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for his_config_info +-- ---------------------------- +DROP TABLE IF EXISTS "his_config_info"; +CREATE TABLE "his_config_info" ( + "id" int8 NOT NULL, + "nid" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(6) NOT NULL DEFAULT '2010-05-05 00:00:00', + "gmt_modified" timestamp(6) NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "op_type" char(10) , + "tenant_id" varchar(128) , + "encrypted_data_key" text +); +COMMENT ON COLUMN "his_config_info"."app_name" IS 'app_name'; +COMMENT ON COLUMN "his_config_info"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "his_config_info"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "his_config_info" IS '多租户改造'; + + +-- ---------------------------- +-- Indexes structure for table his_config_info +-- ---------------------------- +CREATE INDEX "idx_did" ON "his_config_info" USING btree ( + "data_id" + ); +CREATE INDEX "idx_gmt_create" ON "his_config_info" USING btree ( + "gmt_create" + ); +CREATE INDEX "idx_gmt_modified" ON "his_config_info" USING btree ( + "gmt_modified" + ); + +-- ---------------------------- +-- Primary Key structure for table his_config_info +-- ---------------------------- +ALTER TABLE "his_config_info" ADD CONSTRAINT "his_config_info_pkey" PRIMARY KEY ("nid"); + + +-- ---------------------------- +-- Table structure for tenant_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_capacity"; +CREATE TABLE "tenant_capacity" ( + "id" bigserial NOT NULL, + "tenant_id" varchar(128) NOT NULL, + "quota" int4 NOT NULL, + "usage" int4 NOT NULL, + "max_size" int4 NOT NULL, + "max_aggr_count" int4 NOT NULL, + "max_aggr_size" int4 NOT NULL, + "max_history_count" int4 NOT NULL, + "gmt_create" timestamp(6) NOT NULL, + "gmt_modified" timestamp(6) NOT NULL +); +COMMENT ON COLUMN "tenant_capacity"."id" IS '主键ID'; +COMMENT ON COLUMN "tenant_capacity"."tenant_id" IS 'Tenant ID'; +COMMENT ON COLUMN "tenant_capacity"."quota" IS '配额,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."usage" IS '使用量'; +COMMENT ON COLUMN "tenant_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."max_aggr_count" IS '聚合子配置最大个数'; +COMMENT ON COLUMN "tenant_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."max_history_count" IS '最大变更历史数量'; +COMMENT ON COLUMN "tenant_capacity"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "tenant_capacity"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "tenant_capacity" IS '租户容量信息表'; + + +-- ---------------------------- +-- Indexes structure for table tenant_capacity +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_id" ON "tenant_capacity" USING btree ( + "tenant_id" + ); + +-- ---------------------------- +-- Primary Key structure for table tenant_capacity +-- ---------------------------- +ALTER TABLE "tenant_capacity" ADD CONSTRAINT "tenant_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for tenant_info +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_info"; +CREATE TABLE "tenant_info" ( + "id" bigserial NOT NULL, + "kp" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tenant_name" varchar(128) , + "tenant_desc" varchar(256) , + "create_source" varchar(32) , + "gmt_create" int8 NOT NULL, + "gmt_modified" int8 NOT NULL +); +COMMENT ON COLUMN "tenant_info"."id" IS 'id'; +COMMENT ON COLUMN "tenant_info"."kp" IS 'kp'; +COMMENT ON COLUMN "tenant_info"."tenant_id" IS 'tenant_id'; +COMMENT ON COLUMN "tenant_info"."tenant_name" IS 'tenant_name'; +COMMENT ON COLUMN "tenant_info"."tenant_desc" IS 'tenant_desc'; +COMMENT ON COLUMN "tenant_info"."create_source" IS 'create_source'; +COMMENT ON COLUMN "tenant_info"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "tenant_info"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "tenant_info" IS 'tenant_info'; + +-- ---------------------------- +-- Indexes structure for table tenant_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_info_kptenantid" ON "tenant_info" USING btree ( + "kp", + "tenant_id" + ); + + +-- ---------------------------- +-- Table structure for users +-- ---------------------------- +DROP TABLE IF EXISTS "users"; +CREATE TABLE "users" ( + "username" varchar(50) NOT NULL, + "password" varchar(500) NOT NULL, + "enabled" boolean NOT NULL +); + + +-- ---------------------------- +-- Table structure for roles +-- ---------------------------- +DROP TABLE IF EXISTS "roles"; +CREATE TABLE "roles" ( + "username" varchar(50) NOT NULL, + "role" varchar(50) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table roles +-- ---------------------------- +CREATE UNIQUE INDEX "uk_username_role" ON "roles" USING btree ( + "username", + "role" + ); + + + + + +-- ---------------------------- +-- Table structure for permissions +-- ---------------------------- +DROP TABLE IF EXISTS "permissions"; +CREATE TABLE "permissions" ( + "role" varchar(50) NOT NULL, + "resource" varchar(512) NOT NULL, + "action" varchar(8) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table permissions +-- ---------------------------- +CREATE UNIQUE INDEX "uk_role_permission" ON "permissions" USING btree ( + "role", + "resource", + "action" + ); + + + +INSERT INTO "users" VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE); +INSERT INTO "roles" VALUES ('nacos', 'ROLE_ADMIN'); +COMMIT; + + + diff --git a/nacosplugin-datasource-sqlscript/resources/sql/mssql/create-schema.sql b/nacosplugin-datasource-sqlscript/resources/sql/mssql/create-schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..0a95548eca1f36cae2ca5fdfdbd419a02575ef72 --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/mssql/create-schema.sql @@ -0,0 +1,6 @@ +-- DROP SCHEMA IF EXISTS nacos; + +-- IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name='nacos') EXEC('CREATE SCHEMA [nacos]'); + +DROP DATABASE IF EXISTS nacos; +CREATE DATABASE nacos COLLATE Chinese_PRC_CI_AS ; diff --git a/nacosplugin-datasource-sqlscript/resources/sql/mssql/create-tables.sql b/nacosplugin-datasource-sqlscript/resources/sql/mssql/create-tables.sql new file mode 100644 index 0000000000000000000000000000000000000000..07d29788191813c8a6390b4c000c23edb767e72a --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/mssql/create-tables.sql @@ -0,0 +1,360 @@ +USE nacos; + +-- ---------------------------- +-- Table structure for config_info +-- ---------------------------- +DROP TABLE IF EXISTS "config_info"; +CREATE TABLE "config_info" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) , + "content" ntext NOT NULL, + "md5" varchar(32) , + "gmt_create" datetime NOT NULL, + "gmt_modified" datetime NOT NULL, + "src_user" ntext , + "src_ip" varchar(20) , + "app_name" varchar(128) , + "tenant_id" varchar(128) , + "c_desc" varchar(256) , + "c_use" varchar(64) , + "effect" varchar(64) , + "type" varchar(64) , + "c_schema" ntext , + "encrypted_data_key" ntext +); + + +-- ---------------------------- +-- Indexes structure for table config_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfo_datagrouptenant" ON "config_info" ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info +-- ---------------------------- +ALTER TABLE "config_info" ADD CONSTRAINT "config_info_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_aggr +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_aggr"; +CREATE TABLE "config_info_aggr" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) NOT NULL, + "datum_id" varchar(255) NOT NULL, + "content" ntext NOT NULL, + "gmt_modified" datetime NOT NULL, + "app_name" varchar(128) , + "tenant_id" varchar(128) +); + + +-- ---------------------------- +-- Indexes structure for table config_info_aggr +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfoaggr_datagrouptenantdatum" ON "config_info_aggr" ("data_id","group_id","tenant_id","datum_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_aggr +-- ---------------------------- +ALTER TABLE "config_info_aggr" ADD CONSTRAINT "config_info_aggr_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_beta +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_beta"; +CREATE TABLE "config_info_beta" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" ntext NOT NULL, + "beta_ips" varchar(1024) , + "md5" varchar(32) , + "gmt_create" datetime NOT NULL, + "gmt_modified" datetime NOT NULL, + "src_user" ntext , + "src_ip" varchar(20) , + "tenant_id" varchar(128) , + "encrypted_data_key" ntext +); + + +-- ---------------------------- +-- Indexes structure for table config_info_beta +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfobeta_datagrouptenant" ON "config_info_beta" ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_beta +-- ---------------------------- +ALTER TABLE "config_info_beta" ADD CONSTRAINT "config_info_beta_pkey" PRIMARY KEY ("id"); + + +-- ---------------------------- +-- Table structure for config_info_tag +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_tag"; +CREATE TABLE "config_info_tag" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tag_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" ntext NOT NULL, + "md5" varchar(32) , + "gmt_create" datetime NOT NULL, + "gmt_modified" datetime NOT NULL, + "src_user" ntext , + "src_ip" varchar(20) +); + + + +-- ---------------------------- +-- Indexes structure for table config_info_tag +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfotag_datagrouptenanttag" ON "config_info_tag" ("data_id","group_id","tenant_id","tag_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_tag +-- ---------------------------- +ALTER TABLE "config_info_tag" ADD CONSTRAINT "config_info_tag_pkey" PRIMARY KEY ("id"); + +-- ---------------------------- +-- Table structure for config_tags_relation +-- ---------------------------- +DROP TABLE IF EXISTS "config_tags_relation"; +CREATE TABLE "config_tags_relation" ( + "id" BIGINT NOT NULL, + "tag_name" varchar(128) NOT NULL, + "tag_type" varchar(64) , + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "nid" BIGINT NOT NULL IDENTITY(1,1) +); + + + +-- ---------------------------- +-- Indexes structure for table config_tags_relation +-- ---------------------------- +CREATE INDEX "idx_tenant_id" ON "config_tags_relation" ( + "tenant_id" + ); +CREATE UNIQUE INDEX "uk_configtagrelation_configidtag" ON "config_tags_relation" ( + "id", + "tag_name", + "tag_type" + ); + +-- ---------------------------- +-- Primary Key structure for table config_tags_relation +-- ---------------------------- +ALTER TABLE "config_tags_relation" ADD CONSTRAINT "config_tags_relation_pkey" PRIMARY KEY ("nid"); + + + + +-- ---------------------------- +-- Table structure for group_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "group_capacity"; +CREATE TABLE "group_capacity" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "group_id" varchar(128) NOT NULL, + "quota" INT NOT NULL, + "usage" INT NOT NULL, + "max_size" INT NOT NULL, + "max_aggr_count" INT NOT NULL, + "max_aggr_size" INT NOT NULL, + "max_history_count" INT NOT NULL, + "gmt_create" datetime NOT NULL, + "gmt_modified" datetime NOT NULL +); + + + +-- ---------------------------- +-- Indexes structure for table group_capacity +-- ---------------------------- +CREATE UNIQUE INDEX "uk_group_id" ON "group_capacity" ( + "group_id" + ); + +-- ---------------------------- +-- Primary Key structure for table group_capacity +-- ---------------------------- +ALTER TABLE "group_capacity" ADD CONSTRAINT "group_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for his_config_info +-- ---------------------------- +DROP TABLE IF EXISTS "his_config_info"; +CREATE TABLE "his_config_info" ( + "id" BIGINT NOT NULL, + "nid" BIGINT NOT NULL IDENTITY(1,1), + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" ntext NOT NULL, + "md5" varchar(32) , + "gmt_create" datetime NOT NULL DEFAULT '2010-05-05 00:00:00', + "gmt_modified" datetime NOT NULL, + "src_user" ntext , + "src_ip" varchar(20) , + "op_type" char(10) , + "tenant_id" varchar(128) , + "encrypted_data_key" ntext +); + + + +-- ---------------------------- +-- Indexes structure for table his_config_info +-- ---------------------------- +CREATE INDEX "idx_did" ON "his_config_info" ( + "data_id" + ); +CREATE INDEX "idx_gmt_create" ON "his_config_info" ( + "gmt_create" + ); +CREATE INDEX "idx_gmt_modified" ON "his_config_info" ( + "gmt_modified" + ); + +-- ---------------------------- +-- Primary Key structure for table his_config_info +-- ---------------------------- +ALTER TABLE "his_config_info" ADD CONSTRAINT "his_config_info_pkey" PRIMARY KEY ("nid"); + + +-- ---------------------------- +-- Table structure for tenant_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_capacity"; +CREATE TABLE "tenant_capacity" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "tenant_id" varchar(128) NOT NULL, + "quota" INT NOT NULL, + "usage" INT NOT NULL, + "max_size" INT NOT NULL, + "max_aggr_count" INT NOT NULL, + "max_aggr_size" INT NOT NULL, + "max_history_count" INT NOT NULL, + "gmt_create" datetime NOT NULL, + "gmt_modified" datetime NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table tenant_capacity +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_id" ON "tenant_capacity" ( + "tenant_id" + ); + +-- ---------------------------- +-- Primary Key structure for table tenant_capacity +-- ---------------------------- +ALTER TABLE "tenant_capacity" ADD CONSTRAINT "tenant_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for tenant_info +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_info"; +CREATE TABLE "tenant_info" ( + "id" BIGINT NOT NULL IDENTITY(1,1), + "kp" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tenant_name" varchar(128) , + "tenant_desc" varchar(256) , + "create_source" varchar(32) , + "gmt_create" BIGINT NOT NULL, + "gmt_modified" BIGINT NOT NULL +); + +-- ---------------------------- +-- Indexes structure for table tenant_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_info_kptenantid" ON "tenant_info" ( + "kp", + "tenant_id" + ); + + + +-- ---------------------------- +-- Table structure for users +-- ---------------------------- +DROP TABLE IF EXISTS "users"; +CREATE TABLE "users" ( + "username" varchar(50) NOT NULL, + "password" varchar(500) NOT NULL, + "enabled" BIT NOT NULL +); + + +-- ---------------------------- +-- Table structure for roles +-- ---------------------------- +DROP TABLE IF EXISTS "roles"; +CREATE TABLE "roles" ( + "username" varchar(50) NOT NULL, + "role" varchar(50) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table roles +-- ---------------------------- +CREATE UNIQUE INDEX "uk_username_role" ON "roles" ( + "username", + "role" + ); + +-- ---------------------------- +-- Table structure for permissions +-- ---------------------------- +DROP TABLE IF EXISTS "permissions"; +CREATE TABLE "permissions" ( + "role" varchar(50) NOT NULL, + "resource" varchar(512) NOT NULL, + "action" varchar(8) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table permissions +-- ---------------------------- +CREATE UNIQUE INDEX "uk_role_permission" ON "permissions" ( + "role", + "resource", + "action" + ); + + +-- ---------------------------- +-- Records of users +-- ---------------------------- +INSERT INTO "users" VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1); + + +-- ---------------------------- +-- Records of roles +-- ---------------------------- + +INSERT INTO "roles" VALUES ('nacos', 'ROLE_ADMIN'); + diff --git a/nacosplugin-datasource-sqlscript/resources/sql/mysql/create-schema.sql b/nacosplugin-datasource-sqlscript/resources/sql/mysql/create-schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..993873bb7a7d8c857bf9fb0838211ad947217251 --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/mysql/create-schema.sql @@ -0,0 +1 @@ +CREATE SCHEMA IF NOT EXISTS nacos; \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/mysql/create-tables.sql b/nacosplugin-datasource-sqlscript/resources/sql/mysql/create-tables.sql new file mode 100644 index 0000000000000000000000000000000000000000..305bec3e628af3098abc04348f9cff484a43fea6 --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/mysql/create-tables.sql @@ -0,0 +1,209 @@ +use nacos; +/******************************************/ +/* 表名称 = config_info */ +/******************************************/ +DROP TABLE IF EXISTS `config_info`; +CREATE TABLE `config_info` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', + `data_id` varchar(255) NOT NULL COMMENT 'data_id', + `group_id` varchar(128) DEFAULT NULL COMMENT 'group_id', + `content` longtext NOT NULL COMMENT 'content', + `md5` varchar(32) DEFAULT NULL COMMENT 'md5', + `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', + `src_user` text COMMENT 'source user', + `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip', + `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name', + `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段', + `c_desc` varchar(256) DEFAULT NULL COMMENT 'configuration description', + `c_use` varchar(64) DEFAULT NULL COMMENT 'configuration usage', + `effect` varchar(64) DEFAULT NULL COMMENT '配置生效的描述', + `type` varchar(64) DEFAULT NULL COMMENT '配置的类型', + `c_schema` text COMMENT '配置的模式', + `encrypted_data_key` text NOT NULL COMMENT '密钥', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_configinfo_datagrouptenant` (`data_id`,`group_id`,`tenant_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info'; + +/******************************************/ +/* 表名称 = config_info_aggr */ +/******************************************/ +DROP TABLE IF EXISTS `config_info_aggr`; +CREATE TABLE `config_info_aggr` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', + `data_id` varchar(255) NOT NULL COMMENT 'data_id', + `group_id` varchar(128) NOT NULL COMMENT 'group_id', + `datum_id` varchar(255) NOT NULL COMMENT 'datum_id', + `content` longtext NOT NULL COMMENT '内容', + `gmt_modified` datetime NOT NULL COMMENT '修改时间', + `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name', + `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_configinfoaggr_datagrouptenantdatum` (`data_id`,`group_id`,`tenant_id`,`datum_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='增加租户字段'; + + +/******************************************/ +/* 表名称 = config_info_beta */ +/******************************************/ +DROP TABLE IF EXISTS `config_info_beta`; +CREATE TABLE `config_info_beta` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', + `data_id` varchar(255) NOT NULL COMMENT 'data_id', + `group_id` varchar(128) NOT NULL COMMENT 'group_id', + `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name', + `content` longtext NOT NULL COMMENT 'content', + `beta_ips` varchar(1024) DEFAULT NULL COMMENT 'betaIps', + `md5` varchar(32) DEFAULT NULL COMMENT 'md5', + `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', + `src_user` text COMMENT 'source user', + `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip', + `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段', + `encrypted_data_key` text NOT NULL COMMENT '密钥', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_configinfobeta_datagrouptenant` (`data_id`,`group_id`,`tenant_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_beta'; + +/******************************************/ +/* 表名称 = config_info_tag */ +/******************************************/ +DROP TABLE IF EXISTS `config_info_tag`; +CREATE TABLE `config_info_tag` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', + `data_id` varchar(255) NOT NULL COMMENT 'data_id', + `group_id` varchar(128) NOT NULL COMMENT 'group_id', + `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id', + `tag_id` varchar(128) NOT NULL COMMENT 'tag_id', + `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name', + `content` longtext NOT NULL COMMENT 'content', + `md5` varchar(32) DEFAULT NULL COMMENT 'md5', + `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', + `src_user` text COMMENT 'source user', + `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_configinfotag_datagrouptenanttag` (`data_id`,`group_id`,`tenant_id`,`tag_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_tag'; + +/******************************************/ +/* 表名称 = config_tags_relation */ +/******************************************/ +DROP TABLE IF EXISTS `config_tags_relation`; +CREATE TABLE `config_tags_relation` ( + `id` bigint(20) NOT NULL COMMENT 'id', + `tag_name` varchar(128) NOT NULL COMMENT 'tag_name', + `tag_type` varchar(64) DEFAULT NULL COMMENT 'tag_type', + `data_id` varchar(255) NOT NULL COMMENT 'data_id', + `group_id` varchar(128) NOT NULL COMMENT 'group_id', + `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id', + `nid` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'nid, 自增长标识', + PRIMARY KEY (`nid`), + UNIQUE KEY `uk_configtagrelation_configidtag` (`id`,`tag_name`,`tag_type`), + KEY `idx_tenant_id` (`tenant_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_tag_relation'; + +/******************************************/ +/* 表名称 = group_capacity */ +/******************************************/ +DROP TABLE IF EXISTS `group_capacity`; +CREATE TABLE `group_capacity` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `group_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Group ID,空字符表示整个集群', + `quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值', + `usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量', + `max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值', + `max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数,,0表示使用默认值', + `max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值', + `max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量', + `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_group_id` (`group_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='集群、各Group容量信息表'; + +/******************************************/ +/* 表名称 = his_config_info */ +/******************************************/ +DROP TABLE IF EXISTS `his_config_info`; +CREATE TABLE `his_config_info` ( + `id` bigint(20) unsigned NOT NULL COMMENT 'id', + `nid` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'nid, 自增标识', + `data_id` varchar(255) NOT NULL COMMENT 'data_id', + `group_id` varchar(128) NOT NULL COMMENT 'group_id', + `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name', + `content` longtext NOT NULL COMMENT 'content', + `md5` varchar(32) DEFAULT NULL COMMENT 'md5', + `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', + `src_user` text COMMENT 'source user', + `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip', + `op_type` char(10) DEFAULT NULL COMMENT 'operation type', + `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段', + `encrypted_data_key` text NOT NULL COMMENT '密钥', + PRIMARY KEY (`nid`), + KEY `idx_gmt_create` (`gmt_create`), + KEY `idx_gmt_modified` (`gmt_modified`), + KEY `idx_did` (`data_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='多租户改造'; + + +/******************************************/ +/* 表名称 = tenant_capacity */ +/******************************************/ +DROP TABLE IF EXISTS `tenant_capacity`; +CREATE TABLE `tenant_capacity` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `tenant_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Tenant ID', + `quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值', + `usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量', + `max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值', + `max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数', + `max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值', + `max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量', + `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_tenant_id` (`tenant_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='租户容量信息表'; + +DROP TABLE IF EXISTS `tenant_info`; +CREATE TABLE `tenant_info` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', + `kp` varchar(128) NOT NULL COMMENT 'kp', + `tenant_id` varchar(128) default '' COMMENT 'tenant_id', + `tenant_name` varchar(128) default '' COMMENT 'tenant_name', + `tenant_desc` varchar(256) DEFAULT NULL COMMENT 'tenant_desc', + `create_source` varchar(32) DEFAULT NULL COMMENT 'create_source', + `gmt_create` bigint(20) NOT NULL COMMENT '创建时间', + `gmt_modified` bigint(20) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_tenant_info_kptenantid` (`kp`,`tenant_id`), + KEY `idx_tenant_id` (`tenant_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='tenant_info'; + +DROP TABLE IF EXISTS `users`; +CREATE TABLE `users` ( + `username` varchar(50) NOT NULL PRIMARY KEY COMMENT 'username', + `password` varchar(500) NOT NULL COMMENT 'password', + `enabled` boolean NOT NULL COMMENT 'enabled' +); + +DROP TABLE IF EXISTS `roles`; +CREATE TABLE `roles` ( + `username` varchar(50) NOT NULL COMMENT 'username', + `role` varchar(50) NOT NULL COMMENT 'role', + UNIQUE INDEX `idx_user_role` (`username` ASC, `role` ASC) USING BTREE +); + +DROP TABLE IF EXISTS `permissions`; +CREATE TABLE `permissions` ( + `role` varchar(50) NOT NULL COMMENT 'role', + `resource` varchar(128) NOT NULL COMMENT 'resource', + `action` varchar(8) NOT NULL COMMENT 'action', + UNIQUE INDEX `uk_role_permission` (`role`,`resource`,`action`) USING BTREE +); + +INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE); + +INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN'); diff --git a/nacosplugin-datasource-sqlscript/resources/sql/opengauss/create-schema.sql b/nacosplugin-datasource-sqlscript/resources/sql/opengauss/create-schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..15640f509da2b1915c8d626e16828799c9a3803e --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/opengauss/create-schema.sql @@ -0,0 +1,2 @@ +DROP schema if EXISTS nacos CASCADE; +CREATE SCHEMA nacos; \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/opengauss/create-tables.sql b/nacosplugin-datasource-sqlscript/resources/sql/opengauss/create-tables.sql new file mode 100644 index 0000000000000000000000000000000000000000..9b439cccd036ebdfb564079ffdb991b7eac69436 --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/opengauss/create-tables.sql @@ -0,0 +1,456 @@ +SET search_path TO nacos; + + +-- ---------------------------- +-- Table structure for config_info +-- ---------------------------- +DROP TABLE IF EXISTS "config_info"; +CREATE TABLE "config_info" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "app_name" varchar(128) , + "tenant_id" varchar(128) , + "c_desc" varchar(256) , + "c_use" varchar(64) , + "effect" varchar(64) , + "type" varchar(64) , + "c_schema" text , + "encrypted_data_key" text +) +; + +COMMENT ON COLUMN "config_info"."id" IS 'id'; +COMMENT ON COLUMN "config_info"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info"."content" IS 'content'; +COMMENT ON COLUMN "config_info"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info"."src_ip" IS 'source ip'; +COMMENT ON COLUMN "config_info"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "config_info"."effect" IS '配置生效描述'; +COMMENT ON COLUMN "config_info"."type" IS '配置的类型'; +COMMENT ON COLUMN "config_info"."c_schema" IS '配置的模式'; +COMMENT ON COLUMN "config_info"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "config_info" IS 'config_info'; + +-- ---------------------------- +-- Indexes structure for table config_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfo_datagrouptenant" ON "config_info" ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info +-- ---------------------------- +ALTER TABLE "config_info" ADD CONSTRAINT "config_info_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_aggr +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_aggr"; +CREATE TABLE "config_info_aggr" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) NOT NULL, + "datum_id" varchar(255) NOT NULL, + "content" text NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "app_name" varchar(128) , + "tenant_id" varchar(128) +) +; +COMMENT ON COLUMN "config_info_aggr"."id" IS 'id'; +COMMENT ON COLUMN "config_info_aggr"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_aggr"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_aggr"."datum_id" IS 'datum_id'; +COMMENT ON COLUMN "config_info_aggr"."content" IS '内容'; +COMMENT ON COLUMN "config_info_aggr"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_aggr"."tenant_id" IS '租户字段'; +COMMENT ON TABLE "config_info_aggr" IS '增加租户字段'; + + +-- ---------------------------- +-- Indexes structure for table config_info_aggr +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfoaggr_datagrouptenantdatum" ON "config_info_aggr" USING btree ("data_id","group_id","tenant_id","datum_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_aggr +-- ---------------------------- +ALTER TABLE "config_info_aggr" ADD CONSTRAINT "config_info_aggr_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_beta +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_beta"; +CREATE TABLE "config_info_beta" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "beta_ips" varchar(1024) , + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "tenant_id" varchar(128) , + "encrypted_data_key" text +); +COMMENT ON COLUMN "config_info_beta"."id" IS 'id'; +COMMENT ON COLUMN "config_info_beta"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_beta"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_beta"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info_beta"."content" IS 'content'; +COMMENT ON COLUMN "config_info_beta"."beta_ips" IS 'betaIps'; +COMMENT ON COLUMN "config_info_beta"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info_beta"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info_beta"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_beta"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info_beta"."src_ip" IS 'source ip'; +COMMENT ON COLUMN "config_info_beta"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "config_info_beta"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "config_info_beta" IS 'config_info_beta'; + + +-- ---------------------------- +-- Indexes structure for table config_info_beta +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfobeta_datagrouptenant" ON "config_info_beta" USING btree ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_beta +-- ---------------------------- +ALTER TABLE "config_info_beta" ADD CONSTRAINT "config_info_beta_pkey" PRIMARY KEY ("id"); + + +-- ---------------------------- +-- Table structure for config_info_tag +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_tag"; +CREATE TABLE "config_info_tag" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tag_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) +) +; +COMMENT ON COLUMN "config_info_tag"."id" IS 'id'; +COMMENT ON COLUMN "config_info_tag"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_tag"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_tag"."tenant_id" IS 'tenant_id'; +COMMENT ON COLUMN "config_info_tag"."tag_id" IS 'tag_id'; +COMMENT ON COLUMN "config_info_tag"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info_tag"."content" IS 'content'; +COMMENT ON COLUMN "config_info_tag"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info_tag"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info_tag"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_tag"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info_tag"."src_ip" IS 'source ip'; +COMMENT ON TABLE "config_info_tag" IS 'config_info_tag'; + + +-- ---------------------------- +-- Indexes structure for table config_info_tag +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfotag_datagrouptenanttag" ON "config_info_tag" USING btree ("data_id","group_id","tenant_id","tag_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_tag +-- ---------------------------- +ALTER TABLE "config_info_tag" ADD CONSTRAINT "config_info_tag_pkey" PRIMARY KEY ("id"); + +-- ---------------------------- +-- Table structure for config_tags_relation +-- ---------------------------- +DROP TABLE IF EXISTS "config_tags_relation"; +CREATE TABLE "config_tags_relation" ( + "id" bigint NOT NULL, + "tag_name" varchar(128) NOT NULL, + "tag_type" varchar(64) , + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "nid" bigserial NOT NULL +); +COMMENT ON COLUMN "config_tags_relation"."id" IS 'id'; +COMMENT ON COLUMN "config_tags_relation"."tag_name" IS 'tag_name'; +COMMENT ON COLUMN "config_tags_relation"."tag_type" IS 'tag_type'; +COMMENT ON COLUMN "config_tags_relation"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_tags_relation"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_tags_relation"."tenant_id" IS 'tenant_id'; +COMMENT ON TABLE "config_tags_relation" IS 'config_tag_relation'; + + + +-- ---------------------------- +-- Indexes structure for table config_tags_relation +-- ---------------------------- +CREATE INDEX "idx_tenant_id" ON "config_tags_relation" USING btree ( + "tenant_id" + ); +CREATE UNIQUE INDEX "uk_configtagrelation_configidtag" ON "config_tags_relation" USING btree ( + "id", + "tag_name", + "tag_type" + ); + +-- ---------------------------- +-- Primary Key structure for table config_tags_relation +-- ---------------------------- +ALTER TABLE "config_tags_relation" ADD CONSTRAINT "config_tags_relation_pkey" PRIMARY KEY ("nid"); + + + + +-- ---------------------------- +-- Table structure for group_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "group_capacity"; +CREATE TABLE "group_capacity" ( + "id" bigserial NOT NULL, + "group_id" varchar(128) NOT NULL, + "quota" int4 NOT NULL, + "usage" int4 NOT NULL, + "max_size" int4 NOT NULL, + "max_aggr_count" int4 NOT NULL, + "max_aggr_size" int4 NOT NULL, + "max_history_count" int4 NOT NULL, + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL +); +COMMENT ON COLUMN "group_capacity"."id" IS '主键ID'; +COMMENT ON COLUMN "group_capacity"."group_id" IS 'Group ID,空字符表示整个集群'; +COMMENT ON COLUMN "group_capacity"."quota" IS '配额,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."usage" IS '使用量'; +COMMENT ON COLUMN "group_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_aggr_count" IS '聚合子配置最大个数,,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_history_count" IS '最大变更历史数量'; +COMMENT ON COLUMN "group_capacity"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "group_capacity"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "group_capacity" IS '集群、各Group容量信息表'; + + + +-- ---------------------------- +-- Indexes structure for table group_capacity +-- ---------------------------- +CREATE UNIQUE INDEX "uk_group_id" ON "group_capacity" USING btree ( + "group_id" + ); + +-- ---------------------------- +-- Primary Key structure for table group_capacity +-- ---------------------------- +ALTER TABLE "group_capacity" ADD CONSTRAINT "group_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for his_config_info +-- ---------------------------- +DROP TABLE IF EXISTS "his_config_info"; +CREATE TABLE "his_config_info" ( + "id" int8 NOT NULL, + "nid" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL DEFAULT '2010-05-05 00:00:00', + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "op_type" char(10) , + "tenant_id" varchar(128) , + "encrypted_data_key" text +); +COMMENT ON COLUMN "his_config_info"."app_name" IS 'app_name'; +COMMENT ON COLUMN "his_config_info"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "his_config_info"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "his_config_info" IS '多租户改造'; + + +-- ---------------------------- +-- Indexes structure for table his_config_info +-- ---------------------------- +CREATE INDEX "idx_did" ON "his_config_info" USING btree ( + "data_id" + ); +CREATE INDEX "idx_gmt_create" ON "his_config_info" USING btree ( + "gmt_create" + ); +CREATE INDEX "idx_gmt_modified" ON "his_config_info" USING btree ( + "gmt_modified" + ); + +-- ---------------------------- +-- Primary Key structure for table his_config_info +-- ---------------------------- +ALTER TABLE "his_config_info" ADD CONSTRAINT "his_config_info_pkey" PRIMARY KEY ("nid"); + + +-- ---------------------------- +-- Table structure for tenant_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_capacity"; +CREATE TABLE "tenant_capacity" ( + "id" bigserial NOT NULL, + "tenant_id" varchar(128) NOT NULL, + "quota" int4 NOT NULL, + "usage" int4 NOT NULL, + "max_size" int4 NOT NULL, + "max_aggr_count" int4 NOT NULL, + "max_aggr_size" int4 NOT NULL, + "max_history_count" int4 NOT NULL, + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL +); +COMMENT ON COLUMN "tenant_capacity"."id" IS '主键ID'; +COMMENT ON COLUMN "tenant_capacity"."tenant_id" IS 'Tenant ID'; +COMMENT ON COLUMN "tenant_capacity"."quota" IS '配额,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."usage" IS '使用量'; +COMMENT ON COLUMN "tenant_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."max_aggr_count" IS '聚合子配置最大个数'; +COMMENT ON COLUMN "tenant_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."max_history_count" IS '最大变更历史数量'; +COMMENT ON COLUMN "tenant_capacity"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "tenant_capacity"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "tenant_capacity" IS '租户容量信息表'; + + +-- ---------------------------- +-- Indexes structure for table tenant_capacity +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_id" ON "tenant_capacity" USING btree ( + "tenant_id" + ); + +-- ---------------------------- +-- Primary Key structure for table tenant_capacity +-- ---------------------------- +ALTER TABLE "tenant_capacity" ADD CONSTRAINT "tenant_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for tenant_info +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_info"; +CREATE TABLE "tenant_info" ( + "id" bigserial NOT NULL, + "kp" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tenant_name" varchar(128) , + "tenant_desc" varchar(256) , + "create_source" varchar(32) , + "gmt_create" int8 NOT NULL, + "gmt_modified" int8 NOT NULL +); +COMMENT ON COLUMN "tenant_info"."id" IS 'id'; +COMMENT ON COLUMN "tenant_info"."kp" IS 'kp'; +COMMENT ON COLUMN "tenant_info"."tenant_id" IS 'tenant_id'; +COMMENT ON COLUMN "tenant_info"."tenant_name" IS 'tenant_name'; +COMMENT ON COLUMN "tenant_info"."tenant_desc" IS 'tenant_desc'; +COMMENT ON COLUMN "tenant_info"."create_source" IS 'create_source'; +COMMENT ON COLUMN "tenant_info"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "tenant_info"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "tenant_info" IS 'tenant_info'; + +-- ---------------------------- +-- Indexes structure for table tenant_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_info_kptenantid" ON "tenant_info" USING btree ( + "kp", + "tenant_id" + ); + + + +-- ---------------------------- +-- Table structure for users +-- ---------------------------- +DROP TABLE IF EXISTS "users"; +CREATE TABLE "users" ( + "username" varchar(50) NOT NULL, + "password" varchar(500) NOT NULL, + "enabled" boolean NOT NULL +); + + +-- ---------------------------- +-- Table structure for roles +-- ---------------------------- +DROP TABLE IF EXISTS "roles"; +CREATE TABLE "roles" ( + "username" varchar(50) NOT NULL, + "role" varchar(50) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table roles +-- ---------------------------- +CREATE UNIQUE INDEX "uk_username_role" ON "roles" USING btree ( + "username", + "role" + ); + +-- ---------------------------- +-- Table structure for permissions +-- ---------------------------- +DROP TABLE IF EXISTS "permissions"; +CREATE TABLE "permissions" ( + "role" varchar(50) NOT NULL, + "resource" varchar(512) NOT NULL, + "action" varchar(8) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table permissions +-- ---------------------------- +CREATE UNIQUE INDEX "uk_role_permission" ON "permissions" USING btree ( + "role", + "resource", + "action" + ); + + +-- ---------------------------- +-- Records of users +-- ---------------------------- +INSERT INTO "users" VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE); + + +-- ---------------------------- +-- Records of roles +-- ---------------------------- + +INSERT INTO "roles" VALUES ('nacos', 'ROLE_ADMIN'); + + +COMMIT; \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/oracle/create-schema.sql b/nacosplugin-datasource-sqlscript/resources/sql/oracle/create-schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..66fda0ba72632025729f283f5067bccae3883d2e --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/oracle/create-schema.sql @@ -0,0 +1,9 @@ +-- execute this scripts using sqlplus + +-- create schema +DROP USER IF EXISTS C##NACOS CASCADE; +CREATE USER IF NOT EXISTS C##NACOS IDENTIFIED BY NACOS_PASSWORD; +GRANT ALL PRIVILEGES TO C##NACOS; + + +exit \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/oracle/create-tables.sql b/nacosplugin-datasource-sqlscript/resources/sql/oracle/create-tables.sql new file mode 100644 index 0000000000000000000000000000000000000000..c402b3a23cd412b5d20b60bb66f5d8da599a0acb --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/oracle/create-tables.sql @@ -0,0 +1,407 @@ +SET ECHO ON; +SET FEEDBACK ON; + +ALTER SESSION SET CURRENT_SCHEMA=C##NACOS; + +DROP TABLE IF EXISTS config_info; +CREATE TABLE config_info ( + id int NOT NULL, + data_id varchar2(255) NOT NULL, + group_id varchar2(255) , + content CLOB NOT NULL, + md5 varchar2(32) , + gmt_create timestamp(6) NOT NULL, + gmt_modified timestamp(6) NOT NULL, + src_user CLOB , + src_ip varchar2(20) , + app_name varchar2(128) , + tenant_id varchar2(128) DEFAULT 'public', + c_desc varchar2(256) , + c_use varchar2(64) , + effect varchar2(64) , + type varchar2(64) , + c_schema CLOB , + encrypted_data_key CLOB DEFAULT '' +); + +COMMENT ON COLUMN config_info.id IS 'id'; +COMMENT ON COLUMN config_info.data_id IS 'data_id'; +COMMENT ON COLUMN config_info.content IS 'content'; +COMMENT ON COLUMN config_info.md5 IS 'md5'; +COMMENT ON COLUMN config_info.gmt_create IS '创建时间'; +COMMENT ON COLUMN config_info.gmt_modified IS '修改时间'; +COMMENT ON COLUMN config_info.src_user IS 'source user'; +COMMENT ON COLUMN config_info.src_ip IS 'source ip'; +COMMENT ON COLUMN config_info.tenant_id IS '租户字段'; +COMMENT ON COLUMN config_info.encrypted_data_key IS '秘钥'; +COMMENT ON TABLE config_info IS 'config_info'; + +DROP SEQUENCE IF EXISTS config_info_id_seq; +create sequence config_info_id_seq + minvalue 1 + increment by 1 + start with 1; + +create or replace trigger config_info_id_inc +before insert on config_info for each row +begin +select config_info_id_seq.nextval into:new.id from dual; +end; +/ + +DROP TABLE IF EXISTS config_info_aggr; +CREATE TABLE config_info_aggr ( + id int NOT NULL, + data_id varchar2(255) NOT NULL, + group_id varchar2(255) NOT NULL, + datum_id varchar2(255) NOT NULL, + content CLOB NOT NULL, + gmt_modified timestamp(6) NOT NULL, + app_name varchar2(128) , + tenant_id varchar2(128) DEFAULT 'public' +); +COMMENT ON COLUMN config_info_aggr.id IS 'id'; +COMMENT ON COLUMN config_info_aggr.data_id IS 'data_id'; +COMMENT ON COLUMN config_info_aggr.group_id IS 'group_id'; +COMMENT ON COLUMN config_info_aggr.datum_id IS 'datum_id'; +COMMENT ON COLUMN config_info_aggr.content IS '内容'; +COMMENT ON COLUMN config_info_aggr.gmt_modified IS '修改时间'; +COMMENT ON COLUMN config_info_aggr.tenant_id IS '租户字段'; +COMMENT ON TABLE config_info_aggr IS '增加租户字段'; + + +DROP SEQUENCE IF EXISTS config_info_aggr_id_seq; +create sequence config_info_aggr_id_seq + minvalue 1 + increment by 1 + start with 1; + +create or replace trigger config_info_aggr_id_inc +before insert on config_info_aggr for each row +begin +select config_info_aggr_id_seq.nextval into:new.id from dual; +end; +/ + +DROP TABLE IF EXISTS config_info_beta; +CREATE TABLE config_info_beta ( + id int NOT NULL, + data_id varchar2(255) NOT NULL, + group_id varchar2(128) NOT NULL, + app_name varchar2(128) , + content CLOB NOT NULL, + beta_ips varchar2(1024) , + md5 varchar2(32) , + gmt_create timestamp(6) NOT NULL, + gmt_modified timestamp(6) NOT NULL, + src_user CLOB , + src_ip varchar2(20) , + tenant_id varchar2(128) DEFAULT 'public', + encrypted_data_key CLOB NOT NULL +); +COMMENT ON COLUMN config_info_beta.id IS 'id'; +COMMENT ON COLUMN config_info_beta.data_id IS 'data_id'; +COMMENT ON COLUMN config_info_beta.group_id IS 'group_id'; +COMMENT ON COLUMN config_info_beta.app_name IS 'app_name'; +COMMENT ON COLUMN config_info_beta.content IS 'content'; +COMMENT ON COLUMN config_info_beta.beta_ips IS 'betaIps'; +COMMENT ON COLUMN config_info_beta.md5 IS 'md5'; +COMMENT ON COLUMN config_info_beta.gmt_create IS '创建时间'; +COMMENT ON COLUMN config_info_beta.gmt_modified IS '修改时间'; +COMMENT ON COLUMN config_info_beta.src_user IS 'source user'; +COMMENT ON COLUMN config_info_beta.src_ip IS 'source ip'; +COMMENT ON COLUMN config_info_beta.tenant_id IS '租户字段'; +COMMENT ON COLUMN config_info_beta.encrypted_data_key IS '秘钥'; +COMMENT ON TABLE config_info_beta IS 'config_info_beta'; + + +DROP SEQUENCE IF EXISTS config_info_beta_id_seq; +create sequence config_info_beta_id_seq + minvalue 1 + increment by 1 + start with 1; + + +create or replace trigger config_info_beta_id_inc +before insert on config_info_beta for each row +begin +select config_info_beta_id_seq.nextval into:new.id from dual; +end; +/ + +DROP TABLE IF EXISTS config_info_tag; +CREATE TABLE config_info_tag ( + id int NOT NULL, + data_id varchar2(255) NOT NULL, + group_id varchar2(128) NOT NULL, + tenant_id varchar2(128) DEFAULT 'public', + tag_id varchar2(128) NOT NULL, + app_name varchar2(128) , + content CLOB NOT NULL, + md5 varchar2(32) , + gmt_create timestamp(6) NOT NULL, + gmt_modified timestamp(6) NOT NULL, + src_user CLOB , + src_ip varchar2(20) +); +COMMENT ON COLUMN config_info_tag.id IS 'id'; +COMMENT ON COLUMN config_info_tag.data_id IS 'data_id'; +COMMENT ON COLUMN config_info_tag.group_id IS 'group_id'; +COMMENT ON COLUMN config_info_tag.tenant_id IS 'tenant_id'; +COMMENT ON COLUMN config_info_tag.tag_id IS 'tag_id'; +COMMENT ON COLUMN config_info_tag.app_name IS 'app_name'; +COMMENT ON COLUMN config_info_tag.content IS 'content'; +COMMENT ON COLUMN config_info_tag.md5 IS 'md5'; +COMMENT ON COLUMN config_info_tag.gmt_create IS '创建时间'; +COMMENT ON COLUMN config_info_tag.gmt_modified IS '修改时间'; +COMMENT ON COLUMN config_info_tag.src_user IS 'source user'; +COMMENT ON COLUMN config_info_tag.src_ip IS 'source ip'; +COMMENT ON TABLE config_info_tag IS 'config_info_tag'; + + +DROP SEQUENCE IF EXISTS config_info_tag_id_seq; +create sequence config_info_tag_id_seq + minvalue 1 + increment by 1 + start with 1; + +create or replace trigger config_info_tag_id_inc +before insert on config_info_tag for each row +begin +select config_info_tag_id_seq.nextval into:new.id from dual; +end; +/ + +DROP TABLE IF EXISTS config_tags_relation; +CREATE TABLE config_tags_relation ( + id int NOT NULL, + tag_name varchar2(128) NOT NULL, + tag_type varchar2(64) , + data_id varchar2(255) NOT NULL, + group_id varchar2(128) NOT NULL, + tenant_id varchar2(128) DEFAULT 'public', + nid int NOT NULL +); +COMMENT ON COLUMN config_tags_relation.id IS 'id'; +COMMENT ON COLUMN config_tags_relation.tag_name IS 'tag_name'; +COMMENT ON COLUMN config_tags_relation.tag_type IS 'tag_type'; +COMMENT ON COLUMN config_tags_relation.data_id IS 'data_id'; +COMMENT ON COLUMN config_tags_relation.group_id IS 'group_id'; +COMMENT ON COLUMN config_tags_relation.tenant_id IS 'tenant_id'; +COMMENT ON TABLE config_tags_relation IS 'config_tag_relation'; + + +DROP SEQUENCE IF EXISTS config_tags_relation_id_seq; +create sequence config_tags_relation_id_seq + minvalue 1 + increment by 1 + start with 1; + +create or replace trigger config_tags_relation_id_inc +before insert on config_tags_relation for each row +begin +select config_tags_relation_id_seq.nextval into:new.id from dual; +end; +/ + +DROP TABLE IF EXISTS group_capacity; +CREATE TABLE group_capacity ( + id int NOT NULL, + group_id varchar2(128) NOT NULL, + quota int NOT NULL, + usage int NOT NULL, + max_size int NOT NULL, + max_aggr_count int NOT NULL, + max_aggr_size int NOT NULL, + max_history_count int NOT NULL, + gmt_create timestamp(6) NOT NULL, + gmt_modified timestamp(6) NOT NULL +); +COMMENT ON COLUMN group_capacity.id IS '主键ID'; +COMMENT ON COLUMN group_capacity.group_id IS 'Group ID,空字符表示整个集群'; +COMMENT ON COLUMN group_capacity.quota IS '配额,0表示使用默认值'; +COMMENT ON COLUMN group_capacity.usage IS '使用量'; +COMMENT ON COLUMN group_capacity.max_size IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN group_capacity.max_aggr_count IS '聚合子配置最大个数,,0表示使用默认值'; +COMMENT ON COLUMN group_capacity.max_aggr_size IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN group_capacity.max_history_count IS '最大变更历史数量'; +COMMENT ON COLUMN group_capacity.gmt_create IS '创建时间'; +COMMENT ON COLUMN group_capacity.gmt_modified IS '修改时间'; +COMMENT ON TABLE group_capacity IS '集群、各Group容量信息表'; + + + +DROP SEQUENCE IF EXISTS group_capacity_id_seq; +create sequence group_capacity_id_seq + minvalue 1 + increment by 1 + start with 1; + +create or replace trigger group_capacity_id_inc +before insert on group_capacity for each row +begin +select group_capacity_id_seq.nextval into:new.id from dual; +end; +/ + +DROP TABLE IF EXISTS his_config_info; +CREATE TABLE his_config_info ( + id int NOT NULL, + nid int NOT NULL, + data_id varchar2(255) NOT NULL, + group_id varchar2(128) NOT NULL, + app_name varchar2(128) , + content CLOB NOT NULL, + md5 varchar2(32) , + gmt_create timestamp(6) DEFAULT CURRENT_TIMESTAMP, + gmt_modified timestamp(6) NOT NULL, + src_user CLOB , + src_ip varchar2(20) , + op_type char(10) , + tenant_id varchar2(128) DEFAULT 'public', + encrypted_data_key CLOB DEFAULT '' +); +COMMENT ON COLUMN his_config_info.app_name IS 'app_name'; +COMMENT ON COLUMN his_config_info.tenant_id IS '租户字段'; +COMMENT ON COLUMN his_config_info.encrypted_data_key IS '秘钥'; +COMMENT ON TABLE his_config_info IS '多租户改造'; + + +DROP SEQUENCE IF EXISTS his_config_info_nid_seq; +create sequence his_config_info_nid_seq + minvalue 1 + increment by 1 + start with 1; + +create or replace trigger his_config_info_nid_inc +before insert on his_config_info for each row +begin +select his_config_info_nid_seq.nextval into:new.nid from dual; +end; +/ + +DROP TABLE IF EXISTS permissions; +CREATE TABLE permissions ( + "ROLE" varchar2(50) NOT NULL, + "RESOURCE" varchar2(512) NOT NULL, + "ACTION" varchar2(8) NOT NULL +); + + +DROP TABLE IF EXISTS roles; +CREATE TABLE roles ( + USERNAME varchar2(50) NOT NULL, + ROLE varchar2(50) NOT NULL +); + + +DROP TABLE IF EXISTS tenant_capacity; +CREATE TABLE tenant_capacity ( + id int NOT NULL, + tenant_id varchar2(128) NOT NULL, + quota int NOT NULL, + usage int NOT NULL, + max_size int NOT NULL, + max_aggr_count int NOT NULL, + max_aggr_size int NOT NULL, + max_history_count int NOT NULL, + gmt_create timestamp(6) NOT NULL, + gmt_modified timestamp(6) NOT NULL +); +COMMENT ON COLUMN tenant_capacity.id IS '主键ID'; +COMMENT ON COLUMN tenant_capacity.tenant_id IS 'Tenant ID'; +COMMENT ON COLUMN tenant_capacity.quota IS '配额,0表示使用默认值'; +COMMENT ON COLUMN tenant_capacity.usage IS '使用量'; +COMMENT ON COLUMN tenant_capacity.max_size IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN tenant_capacity.max_aggr_count IS '聚合子配置最大个数'; +COMMENT ON COLUMN tenant_capacity.max_aggr_size IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN tenant_capacity.max_history_count IS '最大变更历史数量'; +COMMENT ON COLUMN tenant_capacity.gmt_create IS '创建时间'; +COMMENT ON COLUMN tenant_capacity.gmt_modified IS '修改时间'; +COMMENT ON TABLE tenant_capacity IS '租户容量信息表'; + + +DROP SEQUENCE IF EXISTS tenant_capacity_id_seq; +create sequence tenant_capacity_id_seq + minvalue 1 + increment by 1 + start with 1; + + +create or replace trigger tenant_capacity_id_inc +before insert on tenant_capacity for each row +begin +select tenant_capacity_id_seq.nextval into:new.id from dual; +end; +/ + +DROP TABLE IF EXISTS tenant_info; +CREATE TABLE tenant_info ( + id int NOT NULL, + kp varchar2(128) NOT NULL, + tenant_id varchar2(128) DEFAULT 'public', + tenant_name varchar2(128) , + tenant_desc varchar2(256) , + create_source varchar2(32) , + gmt_create int NOT NULL, + gmt_modified int NOT NULL +); +COMMENT ON COLUMN tenant_info.id IS 'id'; +COMMENT ON COLUMN tenant_info.kp IS 'kp'; +COMMENT ON COLUMN tenant_info.tenant_id IS 'tenant_id'; +COMMENT ON COLUMN tenant_info.tenant_name IS 'tenant_name'; +COMMENT ON COLUMN tenant_info.tenant_desc IS 'tenant_desc'; +COMMENT ON COLUMN tenant_info.create_source IS 'create_source'; +COMMENT ON COLUMN tenant_info.gmt_create IS '创建时间'; +COMMENT ON COLUMN tenant_info.gmt_modified IS '修改时间'; +COMMENT ON TABLE tenant_info IS 'tenant_info'; + +DROP SEQUENCE IF EXISTS tenant_info_id_seq; +create sequence tenant_info_id_seq + minvalue 1 + increment by 1 + start with 1; + +create or replace trigger tenant_info_id_inc +before insert on tenant_info for each row +begin +select tenant_info_id_seq.nextval into:new.id from dual; +end; +/ + +DROP TABLE IF EXISTS users; +CREATE TABLE users ( + username varchar2(50) NOT NULL, + password varchar2(500) NOT NULL, + enabled NUMBER(1) NOT NULL +); + +CREATE UNIQUE INDEX IF NOT EXISTS uk_configinfo_datagrouptenant ON config_info (data_id,group_id,tenant_id); +ALTER TABLE config_info ADD CONSTRAINT config_info_pkey PRIMARY KEY (id); +CREATE UNIQUE INDEX IF NOT EXISTS uk_configinfoaggr_datagrouptenantdatum ON config_info_aggr (data_id,group_id,tenant_id,datum_id); +ALTER TABLE config_info_aggr ADD CONSTRAINT config_info_aggr_pkey PRIMARY KEY (id); +CREATE UNIQUE INDEX IF NOT EXISTS uk_configinfobeta_datagrouptenant ON config_info_beta (data_id,group_id,tenant_id); +ALTER TABLE config_info_beta ADD CONSTRAINT config_info_beta_pkey PRIMARY KEY (id); +CREATE UNIQUE INDEX IF NOT EXISTS uk_configinfotag_datagrouptenanttag ON config_info_tag (data_id,group_id,tenant_id,tag_id); +ALTER TABLE config_info_tag ADD CONSTRAINT config_info_tag_pkey PRIMARY KEY (id); +CREATE INDEX IF NOT EXISTS idx_tenant_id ON config_tags_relation (tenant_id); +CREATE UNIQUE INDEX IF NOT EXISTS uk_configtagrelation_configidtag ON config_tags_relation (id,tag_name,tag_type); +ALTER TABLE config_tags_relation ADD CONSTRAINT config_tags_relation_pkey PRIMARY KEY (nid); +CREATE UNIQUE INDEX IF NOT EXISTS uk_group_id ON group_capacity (group_id); +ALTER TABLE group_capacity ADD CONSTRAINT group_capacity_pkey PRIMARY KEY (id); +CREATE INDEX IF NOT EXISTS idx_did ON his_config_info (data_id); +CREATE INDEX IF NOT EXISTS idx_gmt_create ON his_config_info (gmt_create); +CREATE INDEX IF NOT EXISTS idx_gmt_modified ON his_config_info (gmt_modified); +ALTER TABLE his_config_info ADD CONSTRAINT his_config_info_pkey PRIMARY KEY (nid); +CREATE UNIQUE INDEX IF NOT EXISTS uk_role_permission ON permissions ("ROLE","RESOURCE","ACTION"); +CREATE UNIQUE INDEX IF NOT EXISTS uk_username_role ON roles ("USERNAME", "ROLE"); +CREATE UNIQUE INDEX IF NOT EXISTS uk_tenant_id ON tenant_capacity (tenant_id); +ALTER TABLE tenant_capacity ADD CONSTRAINT tenant_capacity_pkey PRIMARY KEY (id); +CREATE UNIQUE INDEX IF NOT EXISTS uk_tenant_info_kptenantid ON tenant_info (kp, tenant_id); + + +INSERT INTO roles VALUES ('nacos', 'ROLE_ADMIN'); +INSERT INTO users VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1); +COMMIT; + +exit \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/postgresql/create-schema.sql b/nacosplugin-datasource-sqlscript/resources/sql/postgresql/create-schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..15640f509da2b1915c8d626e16828799c9a3803e --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/postgresql/create-schema.sql @@ -0,0 +1,2 @@ +DROP schema if EXISTS nacos CASCADE; +CREATE SCHEMA nacos; \ No newline at end of file diff --git a/nacosplugin-datasource-sqlscript/resources/sql/postgresql/create-tables.sql b/nacosplugin-datasource-sqlscript/resources/sql/postgresql/create-tables.sql new file mode 100644 index 0000000000000000000000000000000000000000..9b439cccd036ebdfb564079ffdb991b7eac69436 --- /dev/null +++ b/nacosplugin-datasource-sqlscript/resources/sql/postgresql/create-tables.sql @@ -0,0 +1,456 @@ +SET search_path TO nacos; + + +-- ---------------------------- +-- Table structure for config_info +-- ---------------------------- +DROP TABLE IF EXISTS "config_info"; +CREATE TABLE "config_info" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "app_name" varchar(128) , + "tenant_id" varchar(128) , + "c_desc" varchar(256) , + "c_use" varchar(64) , + "effect" varchar(64) , + "type" varchar(64) , + "c_schema" text , + "encrypted_data_key" text +) +; + +COMMENT ON COLUMN "config_info"."id" IS 'id'; +COMMENT ON COLUMN "config_info"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info"."content" IS 'content'; +COMMENT ON COLUMN "config_info"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info"."src_ip" IS 'source ip'; +COMMENT ON COLUMN "config_info"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "config_info"."effect" IS '配置生效描述'; +COMMENT ON COLUMN "config_info"."type" IS '配置的类型'; +COMMENT ON COLUMN "config_info"."c_schema" IS '配置的模式'; +COMMENT ON COLUMN "config_info"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "config_info" IS 'config_info'; + +-- ---------------------------- +-- Indexes structure for table config_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfo_datagrouptenant" ON "config_info" ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info +-- ---------------------------- +ALTER TABLE "config_info" ADD CONSTRAINT "config_info_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_aggr +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_aggr"; +CREATE TABLE "config_info_aggr" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(255) NOT NULL, + "datum_id" varchar(255) NOT NULL, + "content" text NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "app_name" varchar(128) , + "tenant_id" varchar(128) +) +; +COMMENT ON COLUMN "config_info_aggr"."id" IS 'id'; +COMMENT ON COLUMN "config_info_aggr"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_aggr"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_aggr"."datum_id" IS 'datum_id'; +COMMENT ON COLUMN "config_info_aggr"."content" IS '内容'; +COMMENT ON COLUMN "config_info_aggr"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_aggr"."tenant_id" IS '租户字段'; +COMMENT ON TABLE "config_info_aggr" IS '增加租户字段'; + + +-- ---------------------------- +-- Indexes structure for table config_info_aggr +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfoaggr_datagrouptenantdatum" ON "config_info_aggr" USING btree ("data_id","group_id","tenant_id","datum_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_aggr +-- ---------------------------- +ALTER TABLE "config_info_aggr" ADD CONSTRAINT "config_info_aggr_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for config_info_beta +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_beta"; +CREATE TABLE "config_info_beta" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "beta_ips" varchar(1024) , + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "tenant_id" varchar(128) , + "encrypted_data_key" text +); +COMMENT ON COLUMN "config_info_beta"."id" IS 'id'; +COMMENT ON COLUMN "config_info_beta"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_beta"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_beta"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info_beta"."content" IS 'content'; +COMMENT ON COLUMN "config_info_beta"."beta_ips" IS 'betaIps'; +COMMENT ON COLUMN "config_info_beta"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info_beta"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info_beta"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_beta"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info_beta"."src_ip" IS 'source ip'; +COMMENT ON COLUMN "config_info_beta"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "config_info_beta"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "config_info_beta" IS 'config_info_beta'; + + +-- ---------------------------- +-- Indexes structure for table config_info_beta +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfobeta_datagrouptenant" ON "config_info_beta" USING btree ("data_id","group_id","tenant_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_beta +-- ---------------------------- +ALTER TABLE "config_info_beta" ADD CONSTRAINT "config_info_beta_pkey" PRIMARY KEY ("id"); + + +-- ---------------------------- +-- Table structure for config_info_tag +-- ---------------------------- +DROP TABLE IF EXISTS "config_info_tag"; +CREATE TABLE "config_info_tag" ( + "id" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tag_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) +) +; +COMMENT ON COLUMN "config_info_tag"."id" IS 'id'; +COMMENT ON COLUMN "config_info_tag"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_info_tag"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_info_tag"."tenant_id" IS 'tenant_id'; +COMMENT ON COLUMN "config_info_tag"."tag_id" IS 'tag_id'; +COMMENT ON COLUMN "config_info_tag"."app_name" IS 'app_name'; +COMMENT ON COLUMN "config_info_tag"."content" IS 'content'; +COMMENT ON COLUMN "config_info_tag"."md5" IS 'md5'; +COMMENT ON COLUMN "config_info_tag"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "config_info_tag"."gmt_modified" IS '修改时间'; +COMMENT ON COLUMN "config_info_tag"."src_user" IS 'source user'; +COMMENT ON COLUMN "config_info_tag"."src_ip" IS 'source ip'; +COMMENT ON TABLE "config_info_tag" IS 'config_info_tag'; + + +-- ---------------------------- +-- Indexes structure for table config_info_tag +-- ---------------------------- +CREATE UNIQUE INDEX "uk_configinfotag_datagrouptenanttag" ON "config_info_tag" USING btree ("data_id","group_id","tenant_id","tag_id"); + +-- ---------------------------- +-- Primary Key structure for table config_info_tag +-- ---------------------------- +ALTER TABLE "config_info_tag" ADD CONSTRAINT "config_info_tag_pkey" PRIMARY KEY ("id"); + +-- ---------------------------- +-- Table structure for config_tags_relation +-- ---------------------------- +DROP TABLE IF EXISTS "config_tags_relation"; +CREATE TABLE "config_tags_relation" ( + "id" bigint NOT NULL, + "tag_name" varchar(128) NOT NULL, + "tag_type" varchar(64) , + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "nid" bigserial NOT NULL +); +COMMENT ON COLUMN "config_tags_relation"."id" IS 'id'; +COMMENT ON COLUMN "config_tags_relation"."tag_name" IS 'tag_name'; +COMMENT ON COLUMN "config_tags_relation"."tag_type" IS 'tag_type'; +COMMENT ON COLUMN "config_tags_relation"."data_id" IS 'data_id'; +COMMENT ON COLUMN "config_tags_relation"."group_id" IS 'group_id'; +COMMENT ON COLUMN "config_tags_relation"."tenant_id" IS 'tenant_id'; +COMMENT ON TABLE "config_tags_relation" IS 'config_tag_relation'; + + + +-- ---------------------------- +-- Indexes structure for table config_tags_relation +-- ---------------------------- +CREATE INDEX "idx_tenant_id" ON "config_tags_relation" USING btree ( + "tenant_id" + ); +CREATE UNIQUE INDEX "uk_configtagrelation_configidtag" ON "config_tags_relation" USING btree ( + "id", + "tag_name", + "tag_type" + ); + +-- ---------------------------- +-- Primary Key structure for table config_tags_relation +-- ---------------------------- +ALTER TABLE "config_tags_relation" ADD CONSTRAINT "config_tags_relation_pkey" PRIMARY KEY ("nid"); + + + + +-- ---------------------------- +-- Table structure for group_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "group_capacity"; +CREATE TABLE "group_capacity" ( + "id" bigserial NOT NULL, + "group_id" varchar(128) NOT NULL, + "quota" int4 NOT NULL, + "usage" int4 NOT NULL, + "max_size" int4 NOT NULL, + "max_aggr_count" int4 NOT NULL, + "max_aggr_size" int4 NOT NULL, + "max_history_count" int4 NOT NULL, + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL +); +COMMENT ON COLUMN "group_capacity"."id" IS '主键ID'; +COMMENT ON COLUMN "group_capacity"."group_id" IS 'Group ID,空字符表示整个集群'; +COMMENT ON COLUMN "group_capacity"."quota" IS '配额,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."usage" IS '使用量'; +COMMENT ON COLUMN "group_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_aggr_count" IS '聚合子配置最大个数,,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "group_capacity"."max_history_count" IS '最大变更历史数量'; +COMMENT ON COLUMN "group_capacity"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "group_capacity"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "group_capacity" IS '集群、各Group容量信息表'; + + + +-- ---------------------------- +-- Indexes structure for table group_capacity +-- ---------------------------- +CREATE UNIQUE INDEX "uk_group_id" ON "group_capacity" USING btree ( + "group_id" + ); + +-- ---------------------------- +-- Primary Key structure for table group_capacity +-- ---------------------------- +ALTER TABLE "group_capacity" ADD CONSTRAINT "group_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for his_config_info +-- ---------------------------- +DROP TABLE IF EXISTS "his_config_info"; +CREATE TABLE "his_config_info" ( + "id" int8 NOT NULL, + "nid" bigserial NOT NULL, + "data_id" varchar(255) NOT NULL, + "group_id" varchar(128) NOT NULL, + "app_name" varchar(128) , + "content" text NOT NULL, + "md5" varchar(32) , + "gmt_create" timestamp(3) without time zone NOT NULL DEFAULT '2010-05-05 00:00:00', + "gmt_modified" timestamp(3) without time zone NOT NULL, + "src_user" text , + "src_ip" varchar(20) , + "op_type" char(10) , + "tenant_id" varchar(128) , + "encrypted_data_key" text +); +COMMENT ON COLUMN "his_config_info"."app_name" IS 'app_name'; +COMMENT ON COLUMN "his_config_info"."tenant_id" IS '租户字段'; +COMMENT ON COLUMN "his_config_info"."encrypted_data_key" IS '密钥'; +COMMENT ON TABLE "his_config_info" IS '多租户改造'; + + +-- ---------------------------- +-- Indexes structure for table his_config_info +-- ---------------------------- +CREATE INDEX "idx_did" ON "his_config_info" USING btree ( + "data_id" + ); +CREATE INDEX "idx_gmt_create" ON "his_config_info" USING btree ( + "gmt_create" + ); +CREATE INDEX "idx_gmt_modified" ON "his_config_info" USING btree ( + "gmt_modified" + ); + +-- ---------------------------- +-- Primary Key structure for table his_config_info +-- ---------------------------- +ALTER TABLE "his_config_info" ADD CONSTRAINT "his_config_info_pkey" PRIMARY KEY ("nid"); + + +-- ---------------------------- +-- Table structure for tenant_capacity +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_capacity"; +CREATE TABLE "tenant_capacity" ( + "id" bigserial NOT NULL, + "tenant_id" varchar(128) NOT NULL, + "quota" int4 NOT NULL, + "usage" int4 NOT NULL, + "max_size" int4 NOT NULL, + "max_aggr_count" int4 NOT NULL, + "max_aggr_size" int4 NOT NULL, + "max_history_count" int4 NOT NULL, + "gmt_create" timestamp(3) without time zone NOT NULL, + "gmt_modified" timestamp(3) without time zone NOT NULL +); +COMMENT ON COLUMN "tenant_capacity"."id" IS '主键ID'; +COMMENT ON COLUMN "tenant_capacity"."tenant_id" IS 'Tenant ID'; +COMMENT ON COLUMN "tenant_capacity"."quota" IS '配额,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."usage" IS '使用量'; +COMMENT ON COLUMN "tenant_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."max_aggr_count" IS '聚合子配置最大个数'; +COMMENT ON COLUMN "tenant_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值'; +COMMENT ON COLUMN "tenant_capacity"."max_history_count" IS '最大变更历史数量'; +COMMENT ON COLUMN "tenant_capacity"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "tenant_capacity"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "tenant_capacity" IS '租户容量信息表'; + + +-- ---------------------------- +-- Indexes structure for table tenant_capacity +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_id" ON "tenant_capacity" USING btree ( + "tenant_id" + ); + +-- ---------------------------- +-- Primary Key structure for table tenant_capacity +-- ---------------------------- +ALTER TABLE "tenant_capacity" ADD CONSTRAINT "tenant_capacity_pkey" PRIMARY KEY ("id"); + + + +-- ---------------------------- +-- Table structure for tenant_info +-- ---------------------------- +DROP TABLE IF EXISTS "tenant_info"; +CREATE TABLE "tenant_info" ( + "id" bigserial NOT NULL, + "kp" varchar(128) NOT NULL, + "tenant_id" varchar(128) , + "tenant_name" varchar(128) , + "tenant_desc" varchar(256) , + "create_source" varchar(32) , + "gmt_create" int8 NOT NULL, + "gmt_modified" int8 NOT NULL +); +COMMENT ON COLUMN "tenant_info"."id" IS 'id'; +COMMENT ON COLUMN "tenant_info"."kp" IS 'kp'; +COMMENT ON COLUMN "tenant_info"."tenant_id" IS 'tenant_id'; +COMMENT ON COLUMN "tenant_info"."tenant_name" IS 'tenant_name'; +COMMENT ON COLUMN "tenant_info"."tenant_desc" IS 'tenant_desc'; +COMMENT ON COLUMN "tenant_info"."create_source" IS 'create_source'; +COMMENT ON COLUMN "tenant_info"."gmt_create" IS '创建时间'; +COMMENT ON COLUMN "tenant_info"."gmt_modified" IS '修改时间'; +COMMENT ON TABLE "tenant_info" IS 'tenant_info'; + +-- ---------------------------- +-- Indexes structure for table tenant_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_info_kptenantid" ON "tenant_info" USING btree ( + "kp", + "tenant_id" + ); + + + +-- ---------------------------- +-- Table structure for users +-- ---------------------------- +DROP TABLE IF EXISTS "users"; +CREATE TABLE "users" ( + "username" varchar(50) NOT NULL, + "password" varchar(500) NOT NULL, + "enabled" boolean NOT NULL +); + + +-- ---------------------------- +-- Table structure for roles +-- ---------------------------- +DROP TABLE IF EXISTS "roles"; +CREATE TABLE "roles" ( + "username" varchar(50) NOT NULL, + "role" varchar(50) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table roles +-- ---------------------------- +CREATE UNIQUE INDEX "uk_username_role" ON "roles" USING btree ( + "username", + "role" + ); + +-- ---------------------------- +-- Table structure for permissions +-- ---------------------------- +DROP TABLE IF EXISTS "permissions"; +CREATE TABLE "permissions" ( + "role" varchar(50) NOT NULL, + "resource" varchar(512) NOT NULL, + "action" varchar(8) NOT NULL +); + + +-- ---------------------------- +-- Indexes structure for table permissions +-- ---------------------------- +CREATE UNIQUE INDEX "uk_role_permission" ON "permissions" USING btree ( + "role", + "resource", + "action" + ); + + +-- ---------------------------- +-- Records of users +-- ---------------------------- +INSERT INTO "users" VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE); + + +-- ---------------------------- +-- Records of roles +-- ---------------------------- + +INSERT INTO "roles" VALUES ('nacos', 'ROLE_ADMIN'); + + +COMMIT; \ No newline at end of file diff --git a/nacosplugin-datasource/installation.MD b/nacosplugin-datasource/installation.MD new file mode 100644 index 0000000000000000000000000000000000000000..2a963d3a7b6d7da0640091c9e47757fc498a0b52 --- /dev/null +++ b/nacosplugin-datasource/installation.MD @@ -0,0 +1,171 @@ +## datasource 插件安装 +1. 将插件、数据库驱动 放到 `nacos/plugins` 目录 +```text +io.github.bes2008.solution.nacosplugins:nacosplugin-all:jar:VERSION +``` + +2. 在application.properties中配置数据库 + +以postgresql 数据库为例,修改 `nacos/conf/application.properties` : +```properties +# PostgreSQL +spring.sql.init.platform=postgresql +db.num=1 +db.url.0=jdbc:postgresql://localhost:5432/db1?currentSchema=nacos +db.user.0=postgresql +db.password.0=postgresql +db.pool.config.driverClassName=org.postgresql.Driver +``` + +3. 初始数据库schema + +使用DBeaver 等工具,连接到数据库,执行相关schema初始化。脚本位置: +```text +nacosplugin-datasource-sqlscripts/resources/sql/ 目录下 +``` +4. 启动nacos访问 + +--- + +## 支持PostgreSQL +1. postgresql 相关依赖要放全,且要与服务端兼容,建议 >= 42.2.0 版本。 +2. 使用Oracle JDK 8,使用 OpenJDK 8可能会遇到 PostgreSQL SCRAM 认证相关问题 +3. 驱动[下载地址](https://mvnrepository.com/artifact/org.postgresql/postgresql) +4. JDBC 配置 +```properties +# PostgreSQL +spring.sql.init.platform=postgresql +db.num=1 +db.url.0=jdbc:postgresql://localhost:5432/db1?currentSchema=nacos +db.user.0=postgresql +db.password.0=postgresql +db.pool.config.driverClassName=org.postgresql.Driver +``` + +## 支持DM +1. jdbc驱动选择: +```markdown ++ 在JDK8上运行时,选择:com.dameng:DmJdbcDriver18:8.1.3.140 ++ 在JDK7上运行时,选择:com.dameng:DmJdbcDriver17:8.1.3.140 ++ 在JDK6上运行时,选择:com.dameng:DmJdbcDriver16:8.1.3.140 +``` +2. SQL脚本的执行 + +使用 DBeaver 连接到达梦数据库上时,一次只能执行一条SQL语句。 + +想要执行SQL脚本文件,需要提供的命令行工具:${dmdbms}/disql + +```shell +./disql SYSDBA/dameng777@localhost:5236 \`./create-schema.sql +./disql SYSDBA/dameng777@localhost:5236 \`./create-tables.sql +``` +3. JDBC 配置 +```properties + +# DM +spring.sql.init.platform=dm +db.num=1 +db.url.0=jdbc:dm://localhost:5236?schema=nacos +db.user.0=SYSDBA +db.password.0=dameng777 +db.pool.config.driverClassName=dm.jdbc.driver.DmDriver + +``` + +4. 注意事项 +```markdown +1) 要指定数据库忽略大小写 +``` + + +## 支持Kingbase +1. jdbc配置 +```properties +spring.sql.init.platform=kingbase +db.num=1 +db.url.0=jdbc:kingbase8://localhost:5432/theDb?currentSchema=nacos&clientEncoding=utf8 +db.user.0=username +db.password.0=thePassword +db.pool.config.driverClassName=com.kingbase8.Driver +``` + +## 支持magicdata + +1. jdbc配置 +```properties +spring.sql.init.platform=magicdata +db.num=1 +db.url.0=jdbc:magicdata://localhost:3660/theDb?currentSchema=nacos&clientEncoding=utf8 +db.user.0=username +db.password.0=thePassword +db.pool.config.driverClassName=com.bes.magicdata.Driver +``` + + +## 支持SqlServer +1. jdbc 驱动选择: +参考[微软官方说明](https://learn.microsoft.com/zh-cn/sql/connect/jdbc/microsoft-jdbc-driver-for-sql-server-support-matrix?view=sql-server-ver16),建议选择`12.4.1`版本 +2. 使用database而不是schema +```markdown +在SqlServer中,每个Database都会默认创建一堆固定的schema,执行sql时,默认就会使用一个名为 dbo的schema。 +虽然也可以通过SQL方式创建 自定义的schema,但无法在session中指定默认schema的,所以不要使用schema,而是使用database。 +``` + +3. jdbc 配置 +```properties +# SqlServer +spring.sql.init.platform=sqlserver +db.num=1 +db.url.0=jdbc:sqlserver://localhost:1433;databaseName=nacos;encrypt=false +db.user.0=sa +db.password.0=SA123456Pswd +db.pool.config.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver +``` + +## 支持MySQL + +1. schema初始化 +```shell +mysql --password=root_password --host=localhost --port=3306 --user root < create_schema.sql +mysql --password=root_password --host=localhost --port=3306 --user root < create_tables.sql +``` +2. JDBC配置 +```properties +# MySQL +spring.sql.init.platform=mysql +db.num=1 +db.url.0=jdbc:mysql://localhost:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=30000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&useServerPrepStmts=true +db.user.0=root +db.password.0=root_password +db.pool.config.driverClassName=com.mysql.cj.jdbc.Driver +``` + + + +## 支持Oracle +1. 脚本执行 +```shell +# 先用 system 创建 C##NACOS用户 +sqlplus system/Oracle123_Pswd@localhost:1521/FREE @./create-schema.sql +# 再用 C##NACOS用户创建表 +sqlplus C##NACOS/NACOS_PASSWORD@localhost:1521/FREE @./create-tables.sql +``` +2. jdbc配置 +```properties + +# Oracle +spring.sql.init.platform=oracle +db.num=1 +# 在oracle中,schema就是用户名,所以不需要另外指定schema +db.url.0=jdbc:oracle:thin:@//localhost:1521/FREE +db.user.0=C##NACOS +db.password.0=NACOS_PASSWORD +db.pool.config.driverClassName=oracle.jdbc.OracleDriver +``` + +3. 目前使用Oracle的问题 + + 目前nacos 适配Oracle已完毕,但在启动过程中,nacos.log中会有报错。 + + 问题原因:是 nacos 启动是会判定 config_info_tag, config_info_beta表是否存在。 这个方法是直接定死的使用了limit 1,没有通过插件的方式。 + + 问题归属:这个属于 nacos 的Bug,已在 [github 上提交了相关问题](https://github.com/alibaba/nacos/issues/12569)。 + + 问题版本:<=2.4.1 + + 影响范围:只会影响到dump接口,功能不受影响 \ No newline at end of file diff --git a/nacosplugin-datasource/pom.xml b/nacosplugin-datasource/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..f6f4a9260e21608664edfa2b2d06c952f6eeef19 --- /dev/null +++ b/nacosplugin-datasource/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + io.github.bes2008.solution.nacosplugins + nacos-plugins + 2.0.6 + + + nacosplugin-datasource + ${project.groupId}:${project.artifactId}:${project.version} + + 8 + 8 + UTF-8 + + + + + + com.alibaba.nacos + nacos-datasource-plugin + + + io.github.bes2008.solution.sqlhelper + sqlhelper-dialect + + + io.github.bes2008.solution.langx + langx-java-el + + + + + com.alibaba.nacos + nacos-sys + + + org.springframework + spring-core + + + + junit + junit + 4.11 + test + + + + + \ No newline at end of file diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/DatabaseNames.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/DatabaseNames.java new file mode 100644 index 0000000000000000000000000000000000000000..7c30b4dcb2e22f4e0491ef6ee7dbc5955bcb6185 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/DatabaseNames.java @@ -0,0 +1,25 @@ +package com.jn.nacos.plugin.datasource; + + +public class DatabaseNames { + public static final String MYSQL = "mysql"; + + public static final String DERBY = "derby"; + public static final String OPENGAUSS = "opengauss"; + public static final String KINGBASE = "kingbase"; + public static final String MAGICDATA = "magicdata"; + public static final String ORACLE = "oracle"; + public static final String DAMENG = "dm"; + public static final String MSSQL = "sqlserver"; + public static final String POSTGRESQL = "postgresql"; + public static final String OSCAR = "oscar"; + + /** + * 当 spring.sql.init.platform 配置没有配置,或者配置了 derby, mysql 时,都会将 自定义的插件设置为 undefined + */ + public static final String UNDEFINED = "undefined"; + /** + * 当spring.sql.init.platform 配置了一个没有支持的数据库时,则会被命名为 unsupported + */ + public static final String UNSUPPORTED = "unsupported"; +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/DefaultNacosDatabaseDialect.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/DefaultNacosDatabaseDialect.java new file mode 100644 index 0000000000000000000000000000000000000000..9c7d37a00aa95edca36daf9cd5ac55b174167aff --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/DefaultNacosDatabaseDialect.java @@ -0,0 +1,7 @@ +package com.jn.nacos.plugin.datasource; + +class DefaultNacosDatabaseDialect extends NacosDatabaseDialect{ + public DefaultNacosDatabaseDialect(String name) { + super(name); + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/IdentifierQuotedMode.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/IdentifierQuotedMode.java new file mode 100644 index 0000000000000000000000000000000000000000..8be919ba018912c683c4f76f4b5085cf12defbf0 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/IdentifierQuotedMode.java @@ -0,0 +1,17 @@ +package com.jn.nacos.plugin.datasource; + +/** + * 表名、字段名是否有使用过引号 + */ +public enum IdentifierQuotedMode { + /** + * 全部使用引号 + */ + QUOTED, + /** + * 全部不使用引号 + */ + UNQUOTED, + // 混合模式 + MIXED +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/NacosDatabaseDialect.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/NacosDatabaseDialect.java new file mode 100644 index 0000000000000000000000000000000000000000..e1cd3bf7fe6ac8c9e151788aefb06b5aa45ea173 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/NacosDatabaseDialect.java @@ -0,0 +1,145 @@ +package com.jn.nacos.plugin.datasource; + +import com.jn.langx.annotation.Nullable; +import com.jn.langx.text.StringTemplates; +import com.jn.langx.util.Objs; +import com.jn.langx.util.Preconditions; +import com.jn.langx.util.Strings; +import com.jn.langx.util.collection.Maps; +import com.jn.langx.util.reflect.Reflects; +import com.jn.sqlhelper.dialect.Dialect; +import com.jn.sqlhelper.dialect.DialectRegistry; +import com.jn.sqlhelper.dialect.pagination.RowSelection; + +import java.util.List; +import java.util.Map; + +public abstract class NacosDatabaseDialect { + + private String name; + private Dialect delegate; + private Map functionMap; + + /** + * 插件中提供在 schema DDL 文件中, identifier 的默认模式 + */ + protected IdentifierQuotedMode identifierQuotedMode; + + protected NacosDatabaseDialect(String name){ + Preconditions.checkNotEmpty(name, "invalid dialect in class {}", Reflects.getFQNClassName(this.getClass())); + this.name = name; + String sqlhelperDialect = getCustomizedDialect(this.name); + this.delegate = DialectRegistry.getInstance().gaussDialect(sqlhelperDialect); + this.functionMap = initFunctionMap(); + this.identifierQuotedMode = IdentifierQuotedMode.QUOTED; + } + + public IdentifierQuotedMode getPluginProvidedDDLIdentifierQuotedMode(){ + return identifierQuotedMode; + } + + private static String getCustomizedDialect(String dialect){ + String customizedDialectKey = "nacos.database.dialect."+dialect; + String customizedDialect = System.getProperty(customizedDialectKey); + if(Strings.isEmpty(customizedDialect)){ + String customizedDialectEnvKey = Strings.replaceChars(customizedDialectKey, '.', '_'); + customizedDialectEnvKey = Strings.upperCase(customizedDialectEnvKey); + customizedDialect = System.getenv(customizedDialectEnvKey); + } + if(Strings.isEmpty(customizedDialect)){ + customizedDialect = dialect; + } + return customizedDialect; + } + + private static Map COMMON_FUNCTIONS = defineCommonFunctionMap(); + + /** + *
+     *  -----------------------定义公有函数-------------------------
+     *  在这里定义的是公有函数,没有必要必须在所有的数据库中存在,只保证在大部分数据库即可;
+     *  并且这里要将所有需要的函数全部定义上
+     *  
+ * @return 公有函数 + */ + private static Map defineCommonFunctionMap(){ + Map map = Maps.newHashMap(); + // 需要获取到毫秒 + map.put("NOW()", "CURRENT_TIMESTAMP(3)"); + + return map; + } + + private Map initFunctionMap(){ + Map map = Maps.newHashMap(); + map.putAll(COMMON_FUNCTIONS); + + // 使用自定义的函数进行重写 + Map specifiedFunctions = specifiedFunctions(); + if(specifiedFunctions!=null){ + for (Map.Entry entry : specifiedFunctions.entrySet()){ + if(COMMON_FUNCTIONS.containsKey(entry.getKey())){ + map.put(entry.getKey(), entry.getValue()); + } + } + } + return map; + } + + /** + * -----------------------定义特定函数------------------------- + * 对于特定的数据库,如果一个函数,与公有函数定义的有所不同时,需要在这里定义 + * @return 特定函数集 + */ + protected Map specifiedFunctions(){ + return null; + } + public String getFunction(String functionName){ + String func = this.functionMap.get(functionName); + if(Objs.isEmpty(func)){ + throw new RuntimeException(StringTemplates.formatWithPlaceholder("function {} in {} database dialect is not supported", functionName, this.getName())); + } + return func; + } + + public String getLimitSql(String sql, RowSelection rowSelection){ + return this.delegate.getLimitSql(sql, rowSelection); + } + + public String getLimitSql(String sql, boolean subQuery, boolean useLimitVariable, RowSelection rowSelection){ + return this.delegate.getLimitSql(sql,useLimitVariable, subQuery, rowSelection); + } + + public List rebuildParameters(List queryParams, RowSelection selection){ + return rebuildParameters(false, true, queryParams, selection); + } + + public List rebuildParameters(boolean subquery, boolean useLimitVariable, List queryParams, RowSelection selection){ + return this.delegate.rebuildParameters(subquery,useLimitVariable, selection, queryParams); + } + + + public String wrapQuote(String identifier, Dialect.IdentifierCase identifierCase){ + // 数据库表名、列名的大小写,由 dialect 内部实现 + return this.delegate.getQuotedIdentifier(identifier, identifierCase); + } + + public String unwrapQuote(String identifier){ + return this.delegate.getUnquoteIdentifier(identifier); + } + + public boolean isAutoCastEmptyStringToNull(){ + return false; + } + + /** + * 为了应对存入 "" 字符串时,被当作 null 处理的情况 + */ + public String genCastNullToDefaultExpression(String expressionOrIdentifier,@Nullable String defaultValue){ + return expressionOrIdentifier; + } + + public String getName() { + return name; + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/NacosDatabaseDialectManager.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/NacosDatabaseDialectManager.java new file mode 100644 index 0000000000000000000000000000000000000000..491aaf0b41fda1d466a716b0e9421ceb7545b6f1 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/NacosDatabaseDialectManager.java @@ -0,0 +1,38 @@ +package com.jn.nacos.plugin.datasource; + +import com.alibaba.nacos.common.spi.NacosServiceLoader; +import com.jn.langx.util.collection.Maps; + +import java.util.Collection; +import java.util.Map; + +public class NacosDatabaseDialectManager { + + private Map dialectMap; + + private NacosDatabaseDialectManager(){ + init(); + } + private void init(){ + Collection dialects = NacosServiceLoader.load(NacosDatabaseDialect.class); + Map map = Maps.newHashMap(); + for (NacosDatabaseDialect dialect : dialects){ + map.put(dialect.getName(), dialect); + } + this.dialectMap = map; + } + + public NacosDatabaseDialect getDialect(String databaseType){ + NacosDatabaseDialect dialect = this.dialectMap.get(databaseType); + if(dialect==null){ + dialect = new DefaultNacosDatabaseDialect(databaseType); + } + return dialect; + } + + private static final NacosDatabaseDialectManager INSTANCE = new NacosDatabaseDialectManager(); + + public static NacosDatabaseDialectManager getInstance(){ + return INSTANCE; + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/derby/DerbyDatabaseDialect.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/derby/DerbyDatabaseDialect.java new file mode 100644 index 0000000000000000000000000000000000000000..3e519eecb3d9153457f3d91c6014c1ef7fb4c4d5 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/derby/DerbyDatabaseDialect.java @@ -0,0 +1,16 @@ +package com.jn.nacos.plugin.datasource.db.derby; + +import com.alibaba.nacos.plugin.datasource.enums.derby.TrustedDerbylFunctionEnum; +import com.jn.nacos.plugin.datasource.DatabaseNames; +import com.jn.nacos.plugin.datasource.NacosDatabaseDialect; + +public class DerbyDatabaseDialect extends NacosDatabaseDialect { + public DerbyDatabaseDialect() { + super(DatabaseNames.DERBY); + } + + @Override + public String getFunction(String functionName) { + return TrustedDerbylFunctionEnum.getFunctionByName(functionName); + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/gauss/OpenGaussDatabaseDialect.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/gauss/OpenGaussDatabaseDialect.java new file mode 100644 index 0000000000000000000000000000000000000000..23d2363ef5b7aa6545e093873463ad6e56d76e4c --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/gauss/OpenGaussDatabaseDialect.java @@ -0,0 +1,20 @@ +package com.jn.nacos.plugin.datasource.db.gauss; + +import com.jn.nacos.plugin.datasource.DatabaseNames; +import com.jn.nacos.plugin.datasource.NacosDatabaseDialect; + +public class OpenGaussDatabaseDialect extends NacosDatabaseDialect { + public OpenGaussDatabaseDialect() { + super(DatabaseNames.OPENGAUSS); + } + + @Override + public boolean isAutoCastEmptyStringToNull() { + return true; + } + + @Override + public String genCastNullToDefaultExpression(String expressionOrIdentifier, String defaultValue) { + return " COALESCE("+expressionOrIdentifier+", '"+defaultValue+"') "; + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/kingbase/KingbaseDatabaseDialect.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/kingbase/KingbaseDatabaseDialect.java new file mode 100644 index 0000000000000000000000000000000000000000..79fe934e9850ec1de20209ea01c2f34f9c1a959b --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/kingbase/KingbaseDatabaseDialect.java @@ -0,0 +1,15 @@ +package com.jn.nacos.plugin.datasource.db.kingbase; + +import com.jn.nacos.plugin.datasource.DatabaseNames; +import com.jn.nacos.plugin.datasource.NacosDatabaseDialect; + +public class KingbaseDatabaseDialect extends NacosDatabaseDialect { + public KingbaseDatabaseDialect() { + super(DatabaseNames.KINGBASE); + } + + @Override + public String genCastNullToDefaultExpression(String expressionOrIdentifier, String defaultValue) { + return " NVL("+expressionOrIdentifier+", '"+defaultValue+"') "; + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/magicdata/MagicDatabaseDialect.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/magicdata/MagicDatabaseDialect.java new file mode 100644 index 0000000000000000000000000000000000000000..779a914265d11d99ddc7ef08d17f6f72c0077d66 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/magicdata/MagicDatabaseDialect.java @@ -0,0 +1,20 @@ +package com.jn.nacos.plugin.datasource.db.magicdata; + +import com.jn.nacos.plugin.datasource.DatabaseNames; +import com.jn.nacos.plugin.datasource.NacosDatabaseDialect; + +public class MagicDatabaseDialect extends NacosDatabaseDialect { + public MagicDatabaseDialect() { + super(DatabaseNames.MAGICDATA); + } + + @Override + public boolean isAutoCastEmptyStringToNull() { + return true; + } + + @Override + public String genCastNullToDefaultExpression(String expressionOrIdentifier, String defaultValue) { + return " COALESCE("+expressionOrIdentifier+", '"+defaultValue+"') "; + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/mssql/MssqlDatabaseDialect.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/mssql/MssqlDatabaseDialect.java new file mode 100644 index 0000000000000000000000000000000000000000..84661d061710e1fa98b954e0a2b8fb810a1b199e --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/mssql/MssqlDatabaseDialect.java @@ -0,0 +1,20 @@ +package com.jn.nacos.plugin.datasource.db.mssql; + +import com.jn.langx.util.collection.Maps; +import com.jn.nacos.plugin.datasource.DatabaseNames; +import com.jn.nacos.plugin.datasource.NacosDatabaseDialect; + +import java.util.Map; + +public class MssqlDatabaseDialect extends NacosDatabaseDialect { + public MssqlDatabaseDialect() { + super(DatabaseNames.MSSQL); + } + + @Override + protected Map specifiedFunctions() { + Map map = Maps.newHashMap(); + map.put("NOW()", "CURRENT_TIMESTAMP"); + return map; + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/mysql/MysqlDatabaseDialect.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/mysql/MysqlDatabaseDialect.java new file mode 100644 index 0000000000000000000000000000000000000000..17cd3455ac06d8a08108a4537be9223cc9560fd1 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/mysql/MysqlDatabaseDialect.java @@ -0,0 +1,17 @@ +package com.jn.nacos.plugin.datasource.db.mysql; + +import com.alibaba.nacos.plugin.datasource.enums.mysql.TrustedMysqlFunctionEnum; +import com.jn.nacos.plugin.datasource.DatabaseNames; +import com.jn.nacos.plugin.datasource.NacosDatabaseDialect; + + +public class MysqlDatabaseDialect extends NacosDatabaseDialect { + public MysqlDatabaseDialect() { + super(DatabaseNames.MYSQL); + } + + @Override + public String getFunction(String functionName) { + return TrustedMysqlFunctionEnum.getFunctionByName(functionName); + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/oracle/OracleDatabaseDialect.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/oracle/OracleDatabaseDialect.java new file mode 100644 index 0000000000000000000000000000000000000000..6221c46fbb05c30d674c30c158ff6d7d6d095e50 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/oracle/OracleDatabaseDialect.java @@ -0,0 +1,22 @@ +package com.jn.nacos.plugin.datasource.db.oracle; + +import com.jn.nacos.plugin.datasource.DatabaseNames; +import com.jn.nacos.plugin.datasource.IdentifierQuotedMode; +import com.jn.nacos.plugin.datasource.NacosDatabaseDialect; + +public class OracleDatabaseDialect extends NacosDatabaseDialect { + public OracleDatabaseDialect(){ + super(DatabaseNames.ORACLE); + this.identifierQuotedMode = IdentifierQuotedMode.UNQUOTED; + } + + @Override + public boolean isAutoCastEmptyStringToNull() { + return true; + } + + @Override + public String genCastNullToDefaultExpression(String expressionOrIdentifier, String defaultValue) { + return " NVL("+expressionOrIdentifier+", '"+defaultValue+"') "; + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/postgresql/PostgresDatabaseDialect.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/postgresql/PostgresDatabaseDialect.java new file mode 100644 index 0000000000000000000000000000000000000000..21ae63ac50800988acc3a99d7beca7d0f80989ab --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/db/postgresql/PostgresDatabaseDialect.java @@ -0,0 +1,16 @@ +package com.jn.nacos.plugin.datasource.db.postgresql; + +import com.jn.nacos.plugin.datasource.DatabaseNames; +import com.jn.nacos.plugin.datasource.NacosDatabaseDialect; + +public class PostgresDatabaseDialect extends NacosDatabaseDialect { + public PostgresDatabaseDialect() { + super(DatabaseNames.POSTGRESQL); + } + + @Override + public boolean isAutoCastEmptyStringToNull() { + // 此测试结果基于 postgresql 15 + return false; + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/BaseMapper.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/BaseMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..2d8645b5b70189d56f860145ee39318bbeb7e5f0 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/BaseMapper.java @@ -0,0 +1,304 @@ +package com.jn.nacos.plugin.datasource.mapper; + +import com.alibaba.nacos.common.utils.NamespaceUtil; +import com.alibaba.nacos.common.utils.VersionUtils; +import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.sys.env.EnvUtil; +import com.jn.langx.util.Objs; +import com.jn.langx.util.Preconditions; +import com.jn.langx.util.Strings; +import com.jn.langx.util.collection.Pipeline; +import com.jn.langx.util.enums.Enums; +import com.jn.nacos.plugin.datasource.DatabaseNames; +import com.jn.nacos.plugin.datasource.IdentifierQuotedMode; +import com.jn.nacos.plugin.datasource.NacosDatabaseDialect; +import com.jn.nacos.plugin.datasource.NacosDatabaseDialectManager; +import com.jn.sqlhelper.dialect.Dialect; +import com.jn.sqlhelper.dialect.DialectRegistry; + +import java.util.List; + +public abstract class BaseMapper extends AbstractMapper { + private final String databaseName; + protected NacosDatabaseDialect dialect; + private IdentifierQuotedMode identifierQuotedModeInDDL; + + protected BaseMapper() { + this.databaseName = getConfiguredDatabaseName(); + Preconditions.checkTrue(!Objs.equals(DatabaseNames.UNSUPPORTED, this.databaseName), "database {} is unsupported", this.databaseName); + this.dialect = NacosDatabaseDialectManager.getInstance().getDialect(this.databaseName); + this.identifierQuotedModeInDDL = getConfiguredIdentifierQuotedMode(); + } + + /** + * 当使用的 create-schema.sql, create-tables.sql 不是插件提供的,需要指定该配置。 + */ + private IdentifierQuotedMode getConfiguredIdentifierQuotedMode(){ + String modeString = EnvUtil.getProperty("db.sql.identifier.quoted.mode"); + IdentifierQuotedMode mode = null; + if(Strings.isNotBlank(modeString)){ + mode = Enums.ofName(IdentifierQuotedMode.class, modeString); + } + if(mode==null){ + mode = this.dialect.getPluginProvidedDDLIdentifierQuotedMode(); + } + if(mode==null){ + mode = IdentifierQuotedMode.QUOTED; + } + return mode; + } + + private String getConfiguredDatabaseName(){ + String databaseName = EnvUtil.getProperty("spring.sql.init.platform"); + if(Strings.isBlank(databaseName)){ + // 这个是 nacos 中更早的配置 datasource 类型的方式 + databaseName = EnvUtil.getProperty("spring.datasource.platform"); + } + if(Strings.isBlank(databaseName)){ + // 内嵌数据库 derby + if (EnvUtil.getStandaloneMode()){ + databaseName = DatabaseNames.DERBY; + } + else{ // 默认数据库 MySQL + databaseName = DatabaseNames.MSSQL; + } + }else{ + Dialect dialect = DialectRegistry.getInstance().gaussDialect(databaseName); + if(dialect==null){ + databaseName = DatabaseNames.UNSUPPORTED; + } + } + + // 因为 mysql 不支持 在子查询中 的limit,所以 不使用自定义的SQL,而使用官方的插件 + if(Strings.isBlank(databaseName) || Objs.equals(DatabaseNames.DERBY, databaseName) || Objs.equals(DatabaseNames.MYSQL, databaseName)){ + databaseName = DatabaseNames.UNDEFINED; + } + return databaseName; + } + + + @Override + public String getDataSource() { + return databaseName; + } + + public NacosDatabaseDialect getDialect() { + return dialect; + } + + public String getIdentifierInDb(String identifier){ + String string; + switch (identifierQuotedModeInDDL){ + case QUOTED: + // 这个要求 DDL文件中,所有的表名、列名使用小写形式 + string = dialect.wrapQuote(identifier, Dialect.IdentifierCase.LOWER_CASE); + break; + case UNQUOTED: + // 去掉引号 + string = dialect.unwrapQuote(identifier); + break; + case MIXED: + default: + // 按照数据库对未加引号的默认行为来处理 + string = dialect.wrapQuote(identifier, null); + break; + } + return string; + } + + @Override + public String getFunction(String functionName) { + return this.dialect.getFunction(functionName); + } + + /*************************************************************************** + * 接下来是重写的父类的函数 + ***************************************************************************/ + + /** + * + * @param columns The columns + * @param where The where params + */ + @Override + public String select(List columns, List where) { + StringBuilder sql = new StringBuilder(); + String method = "SELECT "; + sql.append(method); + for (int i = 0; i < columns.size(); i++) { + sql.append(getIdentifierInDb(columns.get(i))); + if (i == columns.size() - 1) { + sql.append(" "); + } else { + sql.append(","); + } + } + sql.append("FROM "); + sql.append(getTableName()); + sql.append(" "); + + where = Pipeline.of(where).clearEmptys().asList(); + + if (Objs.isEmpty(where)) { + return sql.toString(); + } + + sql.append(genWhereClause(where)); + return sql.toString(); + } + + @Override + public String insert(List columns) { + StringBuilder sql = new StringBuilder(); + String method = "INSERT INTO "; + sql.append(method); + sql.append(getTableName()); + + + int tenantIdColumnIndex = -1; + int size = columns.size(); + sql.append("("); + for (int i = 0; i < size; i++) { + String columnName = getDialect().unwrapQuote(columns.get(i).split("@")[0]); + if(Strings.equalsIgnoreCase(columnName, "tenant_id")){ + tenantIdColumnIndex = i; + } + sql.append(getIdentifierInDb(columnName)); + if (i != columns.size() - 1) { + sql.append(", "); + } + } + sql.append(") "); + + sql.append("VALUES"); + sql.append("("); + for (int i = 0; i < size; i++) { + String[] parts = columns.get(i).split("@"); + if (parts.length == 2) { + sql.append(getFunction(parts[1])); + } else { + if(i==tenantIdColumnIndex){ + sql.append(getDialect().genCastNullToDefaultExpression("?", getDefaultTenantId())); + }else { + sql.append("?"); + } + } + if (i != columns.size() - 1) { + sql.append(","); + } + } + sql.append(")"); + return sql.toString(); + } + + @Override + public String update(List columns, List where) { + StringBuilder sql = new StringBuilder(); + String method = "UPDATE "; + sql.append(method); + sql.append(getTableName()).append(" ").append("SET "); + + for (int i = 0; i < columns.size(); i++) { + String[] parts = columns.get(i).split("@"); + String column = getDialect().unwrapQuote(parts[0]); + if (parts.length == 2) { + sql.append(getIdentifierInDb(column)).append(" = ").append(getFunction(parts[1])); + } else { + sql.append(getIdentifierInDb(column)).append(" = ").append("?"); + } + if (i != columns.size() - 1) { + sql.append(","); + } + } + + where = Pipeline.of(where).clearEmptys().asList(); + if (Objs.isEmpty(where)) { + return sql.toString(); + } + + sql.append(" "); + sql.append(genWhereClause(where)); + + return sql.toString(); + } + + + @Override + public String delete(List where) { + StringBuilder sql = new StringBuilder(); + String method = "DELETE "; + sql.append(method).append("FROM ").append(getTableName()).append(" "); + where = Pipeline.of(where).clearEmptys().asList(); + if (Objs.isEmpty(where)) { + return sql.toString(); + } + sql.append(genWhereClause(where)); + return sql.toString(); + } + + + @Override + public String count(List where) { + StringBuilder sql = new StringBuilder(); + String method = "SELECT "; + sql.append(method); + sql.append("COUNT(*) FROM "); + sql.append(getTableName()); + sql.append(" "); + + where = Pipeline.of(where).clearEmptys().asList(); + if (Objs.isEmpty(where)) { + return sql.toString(); + } + + sql.append(genWhereClause(where)); + return sql.toString(); + } + + protected final String genWhereClause(List where) { + StringBuilder sql = new StringBuilder(" WHERE "); + for (int i = 0; i < where.size(); i++) { + String condition = getDialect().unwrapQuote(where.get(i)); + + if(Strings.equalsIgnoreCase(condition, "tenant_id") && getDialect().isAutoCastEmptyStringToNull()){ + String castNullToDefaultExpression = getDialect().genCastNullToDefaultExpression("?", getDefaultTenantId()); + sql.append(getIdentifierInDb(condition)).append(" = ").append(castNullToDefaultExpression); + }else{ + sql.append(getIdentifierInDb(condition)).append(" = ").append("?"); + } + + if (i != where.size() - 1) { + sql.append(" AND "); + } + } + return sql.toString(); + } + + protected boolean hasEncryptedDataKeyColumn(){ + String currentVersion = VersionUtils.version; + String[] segments = Strings.split(currentVersion, "."); + String nacosVersion = Strings.join(".", segments, 0, 3); + return VersionUtils.compareVersion(nacosVersion, "2.1.0")>=0; + } + private static final String NAMESPACE_PUBLIC_KEY = "public"; + protected final String getDefaultTenantId(){ + if(getDialect().isAutoCastEmptyStringToNull()){ + return NAMESPACE_PUBLIC_KEY; + } + return NamespaceUtil.getNamespaceDefaultId(); + } + protected final String useDefaultTenantIdIfBlank(String tenantId){ + return Strings.useValueIfBlank(tenantId, getDefaultTenantId()); + } + + protected final void useDefaultTenantIdWithWhereParameter(MapperContext context){ + Object tenantIdObj= context.getWhereParameter(FieldConstant.TENANT_ID); + String tenantId=null; + if(tenantIdObj!=null){ + tenantId = (String)tenantIdObj; + } + context.putWhereParameter(FieldConstant.TENANT_ID, useDefaultTenantIdIfBlank(tenantId)); + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoAggrMapper.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoAggrMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..951d451df0743b963519d770c23e25eb12ab5815 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoAggrMapper.java @@ -0,0 +1,53 @@ +package com.jn.nacos.plugin.datasource.mapper; + +import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import com.jn.langx.util.collection.Lists; +import com.jn.sqlhelper.dialect.pagination.RowSelection; + +import java.util.List; + +public class CommonConfigInfoAggrMapper extends BaseMapper implements ConfigInfoAggrMapper { + + @Override + public MapperResult findConfigInfoAggrByPageFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + final int startRow = context.getStartRow(); + final int pageSize = context.getPageSize(); + final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID); + final String groupId = (String) context.getWhereParameter(FieldConstant.GROUP_ID); + final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID); + + RowSelection rowSelection = new RowSelection(startRow, pageSize); + List columns = Lists.newArrayList("data_id","group_id","tenant_id","datum_id","app_name","content"); + List where = Lists.newArrayList("data_id", "group_id", "tenant_id"); + String sql = select(columns, where) + " ORDER BY datum_id "; + List paramList = Lists.newArrayList(dataId, groupId, tenantId); + + sql = getDialect().getLimitSql(sql, false, true, rowSelection); + + List pagedParams = getDialect().rebuildParameters(false, true, paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + @Override + public MapperResult batchRemoveAggr(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoAggrMapper.super.batchRemoveAggr(context); + } + + @Override + public MapperResult aggrConfigInfoCount(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoAggrMapper.super.aggrConfigInfoCount(context); + } + + @Override + public MapperResult findConfigInfoAggrIsOrdered(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoAggrMapper.super.findConfigInfoAggrIsOrdered(context); + } + +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoBetaMapper.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoBetaMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..3140d54a8f1b238f2d4b5ea7a6bbbd6880f96cd9 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoBetaMapper.java @@ -0,0 +1,38 @@ +package com.jn.nacos.plugin.datasource.mapper; + +import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import com.jn.langx.util.collection.Lists; +import com.jn.sqlhelper.dialect.pagination.RowSelection; + +import java.util.List; + +public class CommonConfigInfoBetaMapper extends BaseMapper implements ConfigInfoBetaMapper { + + /** + * 当前nacos版本,不能使用 ? 用作 limit, offset 参数 + */ + @Override + public MapperResult findAllConfigInfoBetaForDumpAllFetchRows(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + + RowSelection rowSelection = new RowSelection(startRow, pageSize); + String subquery = "SELECT id FROM config_info_beta ORDER BY id "; + subquery = getDialect().getLimitSql(subquery, true, false, rowSelection); + String sql = "SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips " + (hasEncryptedDataKeyColumn() ? ", encrypted_data_key ":"") + + " FROM ( " + subquery + " )" + " g, config_info_beta t WHERE g.id = t.id"; + + List paramList = Lists.newArrayList(); + List pagedParams = getDialect().rebuildParameters(true, false, paramList, rowSelection); + + return new MapperResult(sql, pagedParams); + } + + @Override + public MapperResult updateConfigInfo4BetaCas(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoBetaMapper.super.updateConfigInfo4BetaCas(context); + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoMapper.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..9f7cd07b0ae2c5abe7a8b72358d06fae87fbd7e0 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoMapper.java @@ -0,0 +1,405 @@ +package com.jn.nacos.plugin.datasource.mapper; + +import com.alibaba.nacos.plugin.datasource.constants.ContextConstant; +import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import com.jn.langx.util.Strings; +import com.jn.langx.util.collection.Collects; +import com.jn.langx.util.collection.Lists; +import com.jn.sqlhelper.dialect.pagination.RowSelection; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; + +public class CommonConfigInfoMapper extends BaseMapper implements ConfigInfoMapper { + + + + @Override + public MapperResult findChangeConfig(MapperContext context) { + RowSelection rowSelection = new RowSelection(0, context.getPageSize()); + String sql = "SELECT id, data_id, group_id, tenant_id, app_name, content, gmt_modified, encrypted_data_key FROM config_info WHERE " + + "gmt_modified >= ? and id > ? order by id "; + + sql = getDialect().getLimitSql(sql, rowSelection); + + List paramList = Lists.newArrayList(context.getWhereParameter(FieldConstant.START_TIME), + context.getWhereParameter(FieldConstant.LAST_MAX_ID), + context.getWhereParameter(FieldConstant.PAGE_SIZE)); + + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + @Override + public MapperResult findConfigInfoByAppCountRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoMapper.super.findConfigInfoByAppCountRows(context); + } + + @Override + public MapperResult configInfoLikeTenantCount(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoMapper.super.configInfoLikeTenantCount(context); + } + + @Override + public MapperResult findAllConfigInfo4Export(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoMapper.super.findAllConfigInfo4Export(context); + } + + @Override + public MapperResult findConfigInfoBaseLikeCountRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoMapper.super.findConfigInfoBaseLikeCountRows(context); + } + + @Override + public MapperResult findConfigInfo4PageCountRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoMapper.super.findConfigInfo4PageCountRows(context); + } + + @Override + public MapperResult findConfigInfoLike4PageCountRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoMapper.super.findConfigInfoLike4PageCountRows(context); + } + + @Override + public MapperResult updateConfigInfoAtomicCas(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoMapper.super.updateConfigInfoAtomicCas(context); + } + + /** + * 该方法没有被调用 + */ + @Override + public MapperResult findConfigInfoByAppFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + + final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME); + final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID); + + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + + List paramList = Lists.newArrayList(); + + String sql= "SELECT ID,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE tenant_id LIKE ? AND app_name = ? order by id asc"; + paramList.add(tenantId); + paramList.add(appName); + sql = getDialect().getLimitSql(sql, rowSelection); + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + + + @Override + public MapperResult getTenantIdList(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID); + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + String sql = "SELECT tenant_id FROM config_info WHERE tenant_id != ? GROUP BY tenant_id "; + sql = getDialect().getLimitSql(sql, rowSelection); + List pagedParams = getDialect().rebuildParameters(Lists.newArrayList(tenantId), rowSelection); + return new MapperResult(sql, pagedParams); + } + + + @Override + public MapperResult getGroupIdList(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID); + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + String sql = "SELECT group_id FROM config_info WHERE tenant_id = ? GROUP BY group_id "; + sql = getDialect().getLimitSql(sql, rowSelection); + List pagedParams = getDialect().rebuildParameters(Lists.newArrayList(tenantId), rowSelection); + return new MapperResult(sql, pagedParams); + } + + /** + * 该方法没有被调用 + */ + @Override + public MapperResult findAllConfigKey(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + + String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID); + List paramList = Lists.newArrayList(); + + String subquery = "SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id "; + paramList.add(tenantId); + String pagedSubquery = getDialect().getLimitSql(subquery, true,true, rowSelection); + String sql = " SELECT data_id,group_id,app_name FROM ( " + pagedSubquery + " ) g, config_info t WHERE g.id = t.id "; + + List pagedParams = getDialect().rebuildParameters(true, true, paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + + /** + * 该方法没有被调用 + */ + @Override + public MapperResult findAllConfigInfoBaseFetchRows(MapperContext context) { + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + String subquery = "SELECT id FROM config_info ORDER BY id "; + String pagedSubquery = getDialect().getLimitSql(subquery,true,true, rowSelection); + String sql = "SELECT t.id,data_id,group_id,content,md5 " + " FROM ( " + pagedSubquery + " ) g, config_info t WHERE g.id = t.id "; + List pagedParams = getDialect().rebuildParameters(true, true, Collects.emptyArrayList(), rowSelection); + return new MapperResult(sql, pagedParams); + } + + + + @Override + public MapperResult findAllConfigInfoFragment(MapperContext context) { + String contextParameter = context.getContextParameter(ContextConstant.NEED_CONTENT); + boolean needContent = contextParameter != null && Boolean.parseBoolean(contextParameter); + + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + String sql = "SELECT id,data_id,group_id,tenant_id,app_name," + (needContent ? "content," : "") + + "md5,gmt_modified,type "+ (hasEncryptedDataKeyColumn()? ",encrypted_data_key":"") + +" FROM config_info WHERE id > ? " + "ORDER BY id ASC "; + sql = getDialect().getLimitSql(sql, rowSelection); + List queryParams = Lists.newArrayList(context.getWhereParameter(FieldConstant.ID)); + List pagedParams = getDialect().rebuildParameters(queryParams, rowSelection); + return new MapperResult(sql, pagedParams); + } + + + /** + * 该方法没有被调用 + */ + @Override + public MapperResult findChangeConfigFetchRows(MapperContext context) { + final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT); + final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID); + final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID); + final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME); + + final Timestamp startTime = (Timestamp) context.getWhereParameter(FieldConstant.START_TIME); + final Timestamp endTime = (Timestamp) context.getWhereParameter(FieldConstant.END_TIME); + + List paramList = new ArrayList<>(); + + final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified FROM" + + " config_info WHERE "; + String where = " 1=1 "; + + if (!Strings.isBlank(dataId)) { + where += " AND data_id LIKE ? "; + paramList.add(dataId); + } + if (!Strings.isBlank(group)) { + where += " AND group_id LIKE ? "; + paramList.add(group); + } + + if (!Strings.isBlank(tenant)) { + where += " AND tenant_id = ? "; + paramList.add(tenant); + } + + if (!Strings.isBlank(appName)) { + where += " AND app_name = ? "; + paramList.add(appName); + } + if (startTime != null) { + where += " AND gmt_modified >=? "; + paramList.add(startTime); + } + if (endTime != null) { + where += " AND gmt_modified <=? "; + paramList.add(endTime); + } + String sql = sqlFetchRows + where +" order by id asc"; + + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + sql = getDialect().getLimitSql(sql, rowSelection); + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + /** + * 该方法没有被调用 + */ + @Override + public MapperResult listGroupKeyMd5ByPageFetchRows(MapperContext context) { + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + String subquery = "SELECT id FROM config_info ORDER BY id "; + String pagedSubquery = getDialect().getLimitSql(subquery,true,true, rowSelection); + String sql = "SELECT t.id,data_id,group_id,tenant_id,app_name,type,md5,gmt_modified FROM ( " + pagedSubquery + " ) g, config_info t WHERE g.id = t.id"; + + List pagedParams = getDialect().rebuildParameters(true, true, Collects.emptyArrayList(), rowSelection); + return new MapperResult(sql, pagedParams); + } + + + /** + * 该方法没有被调用 + */ + @Override + public MapperResult findConfigInfoBaseLikeFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + + final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT); + final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID); + final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID); + + List paramList = new ArrayList<>(); + final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE "; + String where = " tenant_id= ? "; + paramList.add(tenant); + if (!Strings.isBlank(dataId)) { + where += " AND data_id LIKE ? "; + paramList.add(dataId); + } + if (!Strings.isBlank(group)) { + where += " AND group_id LIKE ? "; + paramList.add(group); + } + if (!Strings.isBlank(tenant)) { + where += " AND content LIKE ? "; + paramList.add(tenant); + } + String sql = sqlFetchRows + where + " order by id asc"; + + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + sql = getDialect().getLimitSql(sql, rowSelection); + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + + @Override + public MapperResult findConfigInfo4PageFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID); + final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID); + final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID); + final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME); + final String content = (String) context.getWhereParameter(FieldConstant.CONTENT); + + List paramList = new ArrayList<>(); + + String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type FROM config_info"; + StringBuilder where = new StringBuilder(" WHERE "); + where.append(" tenant_id= ?" ); + paramList.add(tenantId); + if (Strings.isNotBlank(dataId)) { + where.append(" AND data_id=? "); + paramList.add(dataId); + } + if (Strings.isNotBlank(group)) { + where.append(" AND group_id=? "); + paramList.add(group); + } + + if (Strings.isNotBlank(appName)) { + where.append(" AND app_name=? "); + paramList.add(appName); + } + if (!Strings.isBlank(content)) { + where.append(" AND content LIKE ? "); + paramList.add(content); + } + + sql = sql + where + " order by id asc"; + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + sql = getDialect().getLimitSql(sql, rowSelection); + + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + + + /** + * 该方法没有被调用 + */ + @Override + public MapperResult findConfigInfoBaseByGroupFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID); + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=? order by id asc"; + + List paramList = Lists.newArrayList(context.getWhereParameter(FieldConstant.GROUP_ID), + context.getWhereParameter(FieldConstant.TENANT_ID), tenantId); + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + + @Override + public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID); + final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID); + final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID); + final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME); + final String content = (String) context.getWhereParameter(FieldConstant.CONTENT); + + List paramList = Lists.newArrayList(); + + final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info"; + StringBuilder where = new StringBuilder(" WHERE "); + + where.append(" tenant_id LIKE ? "); + paramList.add(tenantId); + if (!Strings.isBlank(dataId)) { + where.append(" AND data_id LIKE ? "); + paramList.add(dataId); + } + if (!Strings.isBlank(group)) { + where.append(" AND group_id LIKE ? "); + paramList.add(group); + } + if (!Strings.isBlank(appName)) { + where.append(" AND app_name = ? "); + paramList.add(appName); + } + if (!Strings.isBlank(content)) { + where.append(" AND content LIKE ? "); + paramList.add(content); + } + + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + String sql = sqlFetchRows + where +" order by id asc"; + sql = getDialect().getLimitSql(sql, rowSelection); + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + + /** + * 该方法没有被调用 + */ + @Override + public MapperResult findAllConfigInfoFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + + String tenantId =(String) context.getWhereParameter(FieldConstant.TENANT_ID); + + List paramList = Lists.newArrayList(); + String subquery = "SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id "; + + String pagedSubquery = getDialect().getLimitSql(subquery,true,true, rowSelection); + paramList.add(tenantId); + + List pagedParams = getDialect().rebuildParameters(true,true, paramList, rowSelection); + + String sql = " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 FROM ( " + pagedSubquery + " ) g, config_info t WHERE g.id = t.id "; + return new MapperResult(sql, pagedParams); + } + +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoTagMapper.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoTagMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..5dedf0948e06be67da8457fb09c6446fba04b35f --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigInfoTagMapper.java @@ -0,0 +1,32 @@ +package com.jn.nacos.plugin.datasource.mapper; + +import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import com.jn.langx.util.collection.Collects; +import com.jn.sqlhelper.dialect.pagination.RowSelection; + +import java.util.List; + +public class CommonConfigInfoTagMapper extends BaseMapper implements ConfigInfoTagMapper { + + /** + * 当前nacos版本,不能使用 ? 用作 limit, offset 参数 + */ + @Override + public MapperResult findAllConfigInfoTagForDumpAllFetchRows(MapperContext context) { + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + String subquery = " SELECT id FROM config_info_tag ORDER BY id "; + String pagedSubquery = getDialect().getLimitSql(subquery, true,false, rowSelection); + String sql = "SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified FROM ( " + pagedSubquery + " ) g, config_info_tag t WHERE g.id = t.id"; + List pagedParams = getDialect().rebuildParameters(true, false,Collects.emptyArrayList(), rowSelection); + + return new MapperResult(sql, pagedParams); + } + + @Override + public MapperResult updateConfigInfo4TagCas(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigInfoTagMapper.super.updateConfigInfo4TagCas(context); + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigTagRelationMapper.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigTagRelationMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..2bf087b76080293302083211e9e27edcb7e67b62 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonConfigTagRelationMapper.java @@ -0,0 +1,143 @@ +package com.jn.nacos.plugin.datasource.mapper; + +import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import com.jn.langx.util.Objs; +import com.jn.langx.util.Strings; +import com.jn.sqlhelper.dialect.pagination.RowSelection; + +import java.util.ArrayList; +import java.util.List; + +public class CommonConfigTagRelationMapper extends BaseMapper implements ConfigTagsRelationMapper { + + @Override + public MapperResult findConfigInfo4PageCountRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigTagsRelationMapper.super.findConfigInfo4PageCountRows(context); + } + + @Override + public MapperResult findConfigInfoLike4PageCountRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return ConfigTagsRelationMapper.super.findConfigInfoLike4PageCountRows(context); + } + + @Override + public MapperResult findConfigInfo4PageFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME); + final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID); + final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID); + final String content = (String) context.getWhereParameter(FieldConstant.CONTENT); + final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID); + final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR); + + List paramList = new ArrayList<>(); + + final String baseSql = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content " + +" FROM config_info a LEFT JOIN " + + "config_tags_relation b ON a.id=b.id"; + StringBuilder where = new StringBuilder(" WHERE "); + + where.append(" a.tenant_id=? "); + paramList.add(tenantId); + + if (Strings.isNotBlank(dataId)) { + where.append(" AND a.data_id=? "); + paramList.add(dataId); + } + if (Strings.isNotBlank(group)) { + where.append(" AND a.group_id=? "); + paramList.add(group); + } + if (Strings.isNotBlank(appName)) { + where.append(" AND a.app_name=? "); + paramList.add(appName); + } + if (Strings.isNotBlank(content)) { + where.append(" AND a.content LIKE ? "); + paramList.add(content); + } + + if(!Objs.isEmpty(tagArr)) { + where.append(" AND b.tag_name IN ("); + for (int i = 0; i < tagArr.length; i++) { + if (i != 0) { + where.append(", "); + } + where.append('?'); + paramList.add(tagArr[i]); + } + where.append(") "); + } + + String sql = baseSql + where + " order by id asc"; + + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + sql = getDialect().getLimitSql(sql, rowSelection); + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + @Override + public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME); + final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID); + final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID); + final String content = (String) context.getWhereParameter(FieldConstant.CONTENT); + final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID); + final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR); + + List paramList = new ArrayList<>(); + StringBuilder where = new StringBuilder(" WHERE "); + final String baseSql = + "SELECT a.ID,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN " + + "config_tags_relation b ON a.id=b.id "; + + where.append(" a.tenant_id LIKE ? "); + paramList.add(tenantId); + + if (!Strings.isBlank(dataId)) { + where.append(" AND a.data_id LIKE ? "); + paramList.add(dataId); + } + if (!Strings.isBlank(group)) { + where.append(" AND a.group_id LIKE ? "); + paramList.add(group); + } + if (!Strings.isBlank(appName)) { + where.append(" AND a.app_name = ? "); + paramList.add(appName); + } + if (!Strings.isBlank(content)) { + where.append(" AND a.content LIKE ? "); + paramList.add(content); + } + + if(!Objs.isEmpty(tagArr)) { + where.append(" AND b.tag_name IN ("); + for (int i = 0; i < tagArr.length; i++) { + if (i != 0) { + where.append(", "); + } + where.append('?'); + paramList.add(tagArr[i]); + } + where.append(") "); + } + + String sql = baseSql + where + " order by id asc"; + + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + + sql = getDialect().getLimitSql(sql, rowSelection); + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonGroupCapacityMapper.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonGroupCapacityMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..2feaddefa3d811b19895f8cc9da9de280b34cfa1 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonGroupCapacityMapper.java @@ -0,0 +1,24 @@ +package com.jn.nacos.plugin.datasource.mapper; + +import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.mapper.GroupCapacityMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import com.jn.langx.util.collection.Lists; +import com.jn.sqlhelper.dialect.pagination.RowSelection; + +import java.util.List; + +@SuppressWarnings("all") +public class CommonGroupCapacityMapper extends BaseMapper implements GroupCapacityMapper { + + @Override + public MapperResult selectGroupInfoBySize(MapperContext context) { + RowSelection rowSelection = new RowSelection(0, context.getPageSize()); + String sql = "SELECT id, group_id FROM group_capacity WHERE id > ? order by id asc"; + sql = getDialect().getLimitSql(sql, rowSelection); + List paramList = Lists.newArrayList(context.getWhereParameter(FieldConstant.ID)); + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonHistoryConfigInfoMapper.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonHistoryConfigInfoMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..0e5244c1057b7ddd333f600affa17e5019a5855a --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonHistoryConfigInfoMapper.java @@ -0,0 +1,70 @@ +package com.jn.nacos.plugin.datasource.mapper; + +import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import com.jn.langx.util.collection.Lists; +import com.jn.sqlhelper.dialect.pagination.RowSelection; + +import java.util.List; + +public class CommonHistoryConfigInfoMapper extends BaseMapper implements HistoryConfigInfoMapper { + + @Override + public MapperResult removeConfigHistory(MapperContext context) { + + int pageSize = Integer.parseInt(context.getWhereParameter(FieldConstant.LIMIT_SIZE).toString()); + + RowSelection rowSelection = new RowSelection(0, pageSize); + String sql = "DELETE FROM his_config_info WHERE gmt_modified < ? "; + sql = getDialect().getLimitSql(sql, rowSelection); + List paramList = Lists.newArrayList(context.getWhereParameter(FieldConstant.START_TIME), pageSize); + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + /** + * 当前nacos版本,不能使用 ? 用作 limit, offset 参数 + */ + @Override + public MapperResult pageFindConfigHistoryFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + RowSelection rowSelection = new RowSelection(context.getStartRow(), context.getPageSize()); + + List selectedColumns = Lists.newArrayList("nid","data_id","group_id","tenant_id","app_name","src_ip","src_user","op_type","gmt_create","gmt_modified"); + List where = Lists.newArrayList("data_id", "group_id", "tenant_id"); + String sql = select(selectedColumns, where)+ " ORDER BY nid DESC "; + + sql = getDialect().getLimitSql(sql, false, false, rowSelection); + + List paramList = Lists.newArrayList(context.getWhereParameter(FieldConstant.DATA_ID), + context.getWhereParameter(FieldConstant.GROUP_ID), context.getWhereParameter(FieldConstant.TENANT_ID)); + + List pagedParams = getDialect().rebuildParameters(false, false,paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + @Override + public MapperResult findDeletedConfig(MapperContext context) { + + int pageSize = Integer.parseInt(context.getWhereParameter(FieldConstant.PAGE_SIZE).toString()); + RowSelection rowSelection = new RowSelection(0, pageSize); + + String sql = "SELECT data_id, group_id, tenant_id,gmt_modified,nid FROM his_config_info WHERE op_type = 'D' AND " + + "gmt_modified >= ? and nid > ? order by nid "; + sql = getDialect().getLimitSql(sql, rowSelection); + + List paramList = Lists.newArrayList(context.getWhereParameter(FieldConstant.START_TIME), + context.getWhereParameter(FieldConstant.LAST_MAX_ID)); + + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + @Override + public MapperResult findConfigHistoryFetchRows(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return HistoryConfigInfoMapper.super.findConfigHistoryFetchRows(context); + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonTenantCapacityMapper.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonTenantCapacityMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..829ac5938fa06cdccfb3cc332b92b8fce054c04d --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonTenantCapacityMapper.java @@ -0,0 +1,62 @@ +package com.jn.nacos.plugin.datasource.mapper; + +import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.mapper.TenantCapacityMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import com.jn.langx.util.collection.Lists; +import com.jn.sqlhelper.dialect.pagination.RowSelection; + +import java.util.List; + +public class CommonTenantCapacityMapper extends BaseMapper implements TenantCapacityMapper { + + @Override + public MapperResult getCapacityList4CorrectUsage(MapperContext context) { + int pageSize = Integer.parseInt(context.getWhereParameter(FieldConstant.LIMIT_SIZE).toString()); + RowSelection rowSelection = new RowSelection(0, pageSize); + + String sql = "SELECT id, tenant_id FROM tenant_capacity WHERE id>? order by id asc"; + sql = getDialect().getLimitSql(sql, rowSelection); + + List paramList = Lists.newArrayList(context.getWhereParameter(FieldConstant.ID)); + List pagedParams = getDialect().rebuildParameters(paramList, rowSelection); + return new MapperResult(sql, pagedParams); + } + + @Override + public MapperResult incrementUsageWithDefaultQuotaLimit(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return TenantCapacityMapper.super.incrementUsageWithDefaultQuotaLimit(context); + } + + @Override + public MapperResult incrementUsageWithQuotaLimit(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return TenantCapacityMapper.super.incrementUsageWithQuotaLimit(context); + } + + @Override + public MapperResult incrementUsage(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return TenantCapacityMapper.super.incrementUsage(context); + } + + @Override + public MapperResult decrementUsage(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return TenantCapacityMapper.super.decrementUsage(context); + } + + @Override + public MapperResult insertTenantCapacity(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return TenantCapacityMapper.super.insertTenantCapacity(context); + } + + @Override + public MapperResult correctUsage(MapperContext context) { + useDefaultTenantIdWithWhereParameter(context); + return TenantCapacityMapper.super.correctUsage(context); + } +} diff --git a/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonTenantInfoMapper.java b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonTenantInfoMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..bb8906e621d8754e335eb5da464c861b6d163e38 --- /dev/null +++ b/nacosplugin-datasource/src/main/java/com/jn/nacos/plugin/datasource/mapper/CommonTenantInfoMapper.java @@ -0,0 +1,6 @@ +package com.jn.nacos.plugin.datasource.mapper; + +import com.alibaba.nacos.plugin.datasource.mapper.TenantInfoMapper; + +public class CommonTenantInfoMapper extends BaseMapper implements TenantInfoMapper { +} diff --git a/nacosplugin-datasource/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper b/nacosplugin-datasource/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper new file mode 100644 index 0000000000000000000000000000000000000000..81db9c08000f492ff7c8faccf94b92378df55aab --- /dev/null +++ b/nacosplugin-datasource/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper @@ -0,0 +1,9 @@ +com.jn.nacos.plugin.datasource.mapper.CommonConfigInfoAggrMapper +com.jn.nacos.plugin.datasource.mapper.CommonConfigInfoBetaMapper +com.jn.nacos.plugin.datasource.mapper.CommonConfigInfoMapper +com.jn.nacos.plugin.datasource.mapper.CommonConfigInfoTagMapper +com.jn.nacos.plugin.datasource.mapper.CommonConfigTagRelationMapper +com.jn.nacos.plugin.datasource.mapper.CommonGroupCapacityMapper +com.jn.nacos.plugin.datasource.mapper.CommonHistoryConfigInfoMapper +com.jn.nacos.plugin.datasource.mapper.CommonTenantCapacityMapper +com.jn.nacos.plugin.datasource.mapper.CommonTenantInfoMapper diff --git a/nacosplugin-datasource/src/main/resources/META-INF/services/com.jn.nacos.plugin.datasource.NacosDatabaseDialect b/nacosplugin-datasource/src/main/resources/META-INF/services/com.jn.nacos.plugin.datasource.NacosDatabaseDialect new file mode 100644 index 0000000000000000000000000000000000000000..5948227bad1f2858a0ad3b00ed1da881f790d3d3 --- /dev/null +++ b/nacosplugin-datasource/src/main/resources/META-INF/services/com.jn.nacos.plugin.datasource.NacosDatabaseDialect @@ -0,0 +1,8 @@ +com.jn.nacos.plugin.datasource.db.derby.DerbyDatabaseDialect +com.jn.nacos.plugin.datasource.db.gauss.OpenGaussDatabaseDialect +com.jn.nacos.plugin.datasource.db.kingbase.KingbaseDatabaseDialect +com.jn.nacos.plugin.datasource.db.magicdata.MagicDatabaseDialect +com.jn.nacos.plugin.datasource.db.mssql.MssqlDatabaseDialect +com.jn.nacos.plugin.datasource.db.mysql.MysqlDatabaseDialect +com.jn.nacos.plugin.datasource.db.oracle.OracleDatabaseDialect +com.jn.nacos.plugin.datasource.db.postgresql.PostgresDatabaseDialect \ No newline at end of file diff --git a/nacosplugin-datasource/src/test/java/com/jn/nacos/plugin/datasource/tests/VersionTest.java b/nacosplugin-datasource/src/test/java/com/jn/nacos/plugin/datasource/tests/VersionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..475bd62f0c4e1af32226787877b8fed98f4f9668 --- /dev/null +++ b/nacosplugin-datasource/src/test/java/com/jn/nacos/plugin/datasource/tests/VersionTest.java @@ -0,0 +1,19 @@ +package com.jn.nacos.plugin.datasource.tests; + +import com.alibaba.nacos.common.utils.VersionUtils; +import com.jn.langx.util.Strings; +import org.junit.Test; + +public class VersionTest { + + @Test + public void test(){ + String currentVersion = "2.4.1.1"; + String[] segments = Strings.split(currentVersion, "."); + String nacosVersion = Strings.join(".", segments, 0, 3); + boolean gte= VersionUtils.compareVersion(nacosVersion, "2.1.0")>=0; + System.out.println(gte); + } + + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..6a9f01cbb45a9ebdadd1d1b7d1fed47b75a6db4b --- /dev/null +++ b/pom.xml @@ -0,0 +1,398 @@ + + + 4.0.0 + + io.github.bes2008.solution.nacosplugins + nacos-plugins + 2.0.6 + pom + ${project.groupId}:${project.artifactId}:${project.version} + + + nacos plugins: datasource plugin (postgresql, oracle, sqlserver etc) + + + nacosplugin-datasource + nacosplugin-datasource-sqlscript + nacosplugin-all + + + + 1.8 + 1.8 + UTF-8 + + 1.23 + 5.4.4 + 1.17.0 + 2.4.1 + 5.3.34 + 5.0.5 + + + https://gitee.com/coderjn/nacos-plugins + + + coderjn + coderjn + + + + + sonatype_oss + https://oss.sonatype.org/content/repositories/snapshots + + + sonatype_oss + https://oss.sonatype.org/service/local/staging/deploy/maven2 + + + + ${project.version} + scm:git:https://gitee.com/coderjn/nacos-plugins.git + https://gitee.com/coderjn/nacos-plugins.git + https://gitee.com/coderjn/nacos-plugins.git + + + + MulanPSL2 + https://gitee.com/coderjn/nacos-plugins/blob/master/LICENSE + manual + + + + + + + io.github.bes2008.solution.nacosplugins + nacosplugin-datasource + ${project.version} + + + + + org.openjdk.jmh + jmh-core + ${jmh.version} + test + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + test + + + io.github.bes2008.solution.langx + langx-java + ${langx-java.version} + + + com.alibaba.nacos + nacos-datasource-plugin + ${nacos.version} + provided + + + + com.google.guava + guava + + + commons-codec + commons-codec + + + + + com.alibaba.nacos + nacos-common + ${nacos.version} + provided + + + + com.google.guava + guava + + + commons-codec + commons-codec + + + + + com.alibaba.nacos + nacos-sys + 2.2.4.3.alpha-4 + provided + + + org.springframework.boot + spring-boot-starter + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-test + + + com.alibaba.nacos + nacos-common + + + org.codehaus.jackson + jackson-core-asl + + + com.alibaba.nacos + nacos-custom-environment-plugin + + + + + commons-codec + commons-codec + ${commons-codec.version} + provided + + + io.github.bes2008.solution.sqlhelper + sqlhelper-dialect + ${sqlhelper.version} + + + org.springframework + spring-core + ${spring.version} + provided + + + + + + + Volcengine + Volcengine( used for nacos-sys ) + https://artifact.bytedance.com/repository/Volcengine/ + + true + + + + + + + org.openjdk.jmh + jmh-core + + + org.openjdk.jmh + jmh-generator-annprocess + + + io.github.bes2008.solution.langx + langx-java + + + com.alibaba.nacos + nacos-common + + + + + + + ${basedir}/src/main/java + ${project.build.outputDirectory} + + **/*.java + + + + ${basedir}/src/main/resources + false + + **/* + + + + + + ${basedir}/src/test/java + ${project.build.testOutputDirectory} + + **/*.java + + + **/*.json + **/*.txt + **/*.log + + + + ${basedir}/src/test/resources + ${project.build.testOutputDirectory} + false + + **/* + + + + + + + + envHome + + D:/Program Files (x86)/GnuPG/bin/gpg + C:/Users/Administrator/AppData/Roaming/gnupg + + + + + + envCompany + + D:/Program Files (x86)/GNU/GnuPG/gpg2.exe + C:/Users/Administrator/AppData/Roaming/gnupg + + + + + + deploy + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + + deploy + deploy + + deploy + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + true + + sonatype_oss + https://s01.oss.sonatype.org + true + true + 5 + 5 + false + true + true + + + + org.apache.maven.plugins + maven-scm-plugin + 1.10.0 + + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + false + false + true + false + + + + org.apache.maven.plugins + maven-scm-plugin + 1.10.0 + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.1.0 + + + attach-sources + verify + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + true + UTF-8 + UTF-8 + UTF-8 + -Xdoclint:none + false + + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + + + + + \ No newline at end of file