diff --git a/nacos-datasource-plugin-ext/README.md b/nacos-datasource-plugin-ext/README.md new file mode 100644 index 0000000..f439a92 --- /dev/null +++ b/nacos-datasource-plugin-ext/README.md @@ -0,0 +1,59 @@ +# Nacos数据库适配插件 + +## 一、插件概述 + +### 1.1、简介 + +从Nacos2.2版本开始,Nacos提供了数据源扩展插件,以便让需要进行其他数据库适配的用户自己编写插件来保存数据。当前项目插件目前已简单适配Postgresql。 + +如需Nacos2.1支持,请移步个人的如下这个仓库: + +https://github.com/wuchubuzai2018/nacos-multidatasource + +当前项目基于Nacos2.2版本的扩展插件口进行开发。 + +### 2.2、插件工程结构说明 + +nacos-datasource-plugin-ext-base工程为数据库插件操作的适配抽象。 + +nacos-all-datasource-plugin-ext工程可打包所有适配的数据库插件 + +nacos-postgresql-datasource-plugin-ext工程可打包适配Postgresql的数据库插件 + +## 二、下载和使用 + +### 2.1、插件引入 + +方式一:使用postgresql作为依赖引入到Nacos主分支源码中,例如: + +```xml + + com.alibaba.nacos + nacos-postgresql-datasource-plugin-ext + 1.0.0-SNAPSHOT + +``` + +方式二:下载当前插件项目源码,打包为jar包,将该文件的路径配置到startup.sh文件中,使用Nacos的loader.path机制指定该插件的路径,可修改startup.sh中的loader.path参数的位置进行指定。 + +### 2.2、修改数据库配置文件 + +在application.properties文件中声明postgresql的配置信息: + +```java +spring.datasource.platform=postgresql +db.url.0=jdbc:postgresql://127.0.0.1:5432/nacos?tcpKeepAlive=true&reWriteBatchedInserts=true&ApplicationName=nacos_java +db.user=nacos +db.password=nacos +db.pool.config.driverClassName=org.postgresql.Driver +``` + +### 2.3、导入Postgresql的数据库脚本文件 + +导入nacos-postgresql的脚本文件,脚本文件在nacos-postgresql-datasource-plugin-ext/src/main/resources/schema文件夹下面. + +上面操作完成后,启动Nacos即可。 + +## 三、其他数据库插件开发 + +可参考nacos-postgresql-datasource-plugin-ext工程,新创建Maven项目,实现AbstractDatabaseDialect类,重写相关的分页操作逻辑与方法,并创建相应的mapper实现。 \ No newline at end of file diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/pom.xml b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/pom.xml new file mode 100644 index 0000000..de0b99b --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/pom.xml @@ -0,0 +1,27 @@ + + + + nacos-datasource-plugin-ext + com.alibaba.nacos + ${revision} + + 4.0.0 + + com.alibaba.nacos + nacos-datasource-plugin-ext-base + + + 8 + 8 + + + + + + + + + + \ No newline at end of file diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/constants/DatabaseTypeConstant.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/constants/DatabaseTypeConstant.java new file mode 100644 index 0000000..a0c0295 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/constants/DatabaseTypeConstant.java @@ -0,0 +1,30 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.constants; + +/** + * DatabaseType Constant. + * + * @author Long Yu + **/ +public class DatabaseTypeConstant { + + public static final String POSTGRESQL = "postgresql"; + + public static final String MYSQL = "mysql"; + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/constants/PrimaryKeyConstant.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/constants/PrimaryKeyConstant.java new file mode 100644 index 0000000..7812531 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/constants/PrimaryKeyConstant.java @@ -0,0 +1,37 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.constants; + +/** + * PrimaryKeyConstant. + * + * @author Long Yu + */ +public class PrimaryKeyConstant { + + /** + * replace lower Statement.RETURN_GENERATED_KEYS into id key. + */ + public static final String[] LOWER_RETURN_PRIMARY_KEYS = new String[]{"id"}; + + /** + * upper replace Statement.RETURN_GENERATED_KEYS into id key. + * using dameng database. + */ + public static final String[] UPPER_RETURN_PRIMARY_KEYS = new String[]{"ID"}; + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/AbstractDatabaseDialect.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/AbstractDatabaseDialect.java new file mode 100644 index 0000000..f8a4035 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/AbstractDatabaseDialect.java @@ -0,0 +1,63 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.dialect; + +import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant; + +/** + * Abstract DatabaseDialect. + * Default limit for mysql,postgresql + * @author Long Yu + */ +public abstract class AbstractDatabaseDialect implements DatabaseDialect { + + @Override + public int getPagePrevNum(int page, int pageSize) { + return (page - 1) * pageSize; + } + + @Override + public int getPageLastNum(int page, int pageSize) { + return pageSize; + } + + @Override + public String getLimitTopSqlWithMark(String sql) { + return sql + " LIMIT ? "; + } + + @Override + public String getLimitPageSqlWithMark(String sql) { + return sql + " LIMIT ?,? "; + } + + @Override + public String getLimitPageSql(String sql, int pageNo, int pageSize) { + return sql + " LIMIT " + getPagePrevNum(pageNo, pageSize) + " , " + pageSize; + } + + @Override + public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize){ + return sql + " LIMIT " + startOffset + " , " + pageSize; + } + + @Override + public String[] getReturnPrimaryKeys() { + return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/DatabaseDialect.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/DatabaseDialect.java new file mode 100644 index 0000000..4cea905 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/DatabaseDialect.java @@ -0,0 +1,85 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.dialect; + +/** + * DatabaseDialect interface. + * @author Long Yu + */ +public interface DatabaseDialect { + + /** + * get database type. + * @return return database type name + */ + public String getType(); + + /** + * get frist index page param. + * @param page current pageNo + * @param pageSize current pageSize + * @return offset val or maxRange + */ + public int getPagePrevNum(int page, int pageSize); + + /** + * get second index page param. + * @param page current pageNo + * @param pageSize current pageSize + * @return limit val or minRange + */ + public int getPageLastNum(int page, int pageSize); + + /** + * get page limit top data sql,contain placeholder. + * @param sql orign sql + * @return append limit sql + */ + public String getLimitTopSqlWithMark(String sql); + + /** + * get page limit page data sql,contain placeholder. + * @param sql orign sql + * @return append limit sql + */ + public String getLimitPageSqlWithMark(String sql); + + /** + * get page limit page data sql,using number. + * @param sql orign sql + * @param pageNo current pageNo + * @param pageSize current pageSize + * @return contain page number param sql + */ + public String getLimitPageSql(String sql, int pageNo, int pageSize); + + /** + * get page limit page data sql,using offset. + * @param sql orign sql + * @param startOffset current offset row + * @param pageSize current pageSize + * @return contain page number param sql + */ + public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize); + + /** + * get database return primary keys. + * @return + */ + public String[] getReturnPrimaryKeys(); + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/DefaultDatabaseDialect.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/DefaultDatabaseDialect.java new file mode 100644 index 0000000..e711fd8 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/DefaultDatabaseDialect.java @@ -0,0 +1,32 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.dialect; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; + +/** + * defauLT database dialect. + * @author Long Yu + */ +public class DefaultDatabaseDialect extends AbstractDatabaseDialect { + + @Override + public String getType() { + return DatabaseTypeConstant.MYSQL; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoAggrMapper.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoAggrMapper.java new file mode 100644 index 0000000..71163eb --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoAggrMapper.java @@ -0,0 +1,49 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.base; + +import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect; +import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql; +import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager; + +/** + * The base implementation of ConfigTagsRelationMapper. + * + * @author Long Yu + **/ +public class BaseConfigInfoAggrMapper extends ConfigInfoAggrMapperByMySql { + + private DatabaseDialect databaseDialect; + + public BaseConfigInfoAggrMapper() { + databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource()); + } + + @Override + public String getTableName() { + return TableConstant.CONFIG_INFO_AGGR; + } + + @Override + public String findConfigInfoAggrByPageFetchRows(int startRow, int pageSize) { + return databaseDialect.getLimitPageSqlWithOffset( + "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id= ? AND " + + "group_id= ? AND tenant_id= ? ORDER BY datum_id ", startRow, pageSize); + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoBetaMapper.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoBetaMapper.java new file mode 100644 index 0000000..4b6df2c --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoBetaMapper.java @@ -0,0 +1,57 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.base; + + +import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect; +import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql; +import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager; + +/** + * The base implementation of ConfigInfoBetaMapper. + * + * @author Long Yu + **/ +public class BaseConfigInfoBetaMapper extends ConfigInfoBetaMapperByMySql { + + private DatabaseDialect databaseDialect; + + public BaseConfigInfoBetaMapper() { + databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource()); + } + + @Override + public String getTableName() { + return TableConstant.CONFIG_INFO_BETA; + } + + public String getLimitPageSqlWithOffset(String sql,int startRow, int pageSize) { + return databaseDialect.getLimitPageSqlWithOffset(sql, startRow, pageSize); + } + + @Override + public String findAllConfigInfoBetaForDumpAllFetchRows(int startRow, int pageSize) { + String sqlInner = getLimitPageSqlWithOffset("SELECT id FROM config_info_beta ORDER BY id ",startRow, pageSize); + return " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key " + + " FROM ( " + sqlInner + " )" + + " g, config_info_beta t WHERE g.id = t.id "; + } + + + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoMapper.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoMapper.java new file mode 100644 index 0000000..44f2a86 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoMapper.java @@ -0,0 +1,217 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.base; + +import com.alibaba.nacos.common.utils.StringUtils; +import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect; +import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql; +import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager; + +import java.sql.Timestamp; +import java.util.Map; + +/** + * The base implementation of ConfigInfoMapper. + * + * @author Long Yu + **/ +public class BaseConfigInfoMapper extends ConfigInfoMapperByMySql { + + private static final String DATA_ID = "dataId"; + + private static final String GROUP = "group"; + + private static final String APP_NAME = "appName"; + + private static final String CONTENT = "content"; + + private static final String TENANT = "tenant"; + + private DatabaseDialect databaseDialect; + + public BaseConfigInfoMapper() { + databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource()); + } + + public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize) { + return databaseDialect.getLimitPageSqlWithOffset(sql, startOffset, pageSize); + } + + public String getLimitPageSqlWithMark(String sql) { + return databaseDialect.getLimitPageSqlWithMark(sql); + } + + @Override + public String findConfigInfoByAppFetchRows(int startRow, int pageSize) { + return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info" + + " WHERE tenant_id LIKE ? AND app_name= ?",startRow, pageSize); + } + + @Override + public String getTenantIdList(int startRow, int pageSize) { + return getLimitPageSqlWithOffset("SELECT tenant_id FROM config_info WHERE tenant_id != '' GROUP BY tenant_id ", startRow, pageSize); + } + + @Override + public String getGroupIdList(int startRow, int pageSize) { + return getLimitPageSqlWithOffset("SELECT group_id FROM config_info WHERE tenant_id ='' GROUP BY group_id ", + startRow, pageSize); + } + + @Override + public String findAllConfigKey(int startRow, int pageSize) { + String innerSql = getLimitPageSqlWithOffset(" SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id ", startRow, pageSize); + return " SELECT data_id,group_id,app_name FROM ( " + + innerSql + + " g, config_info t WHERE g.id = t.id "; + } + + @Override + public String findAllConfigInfoBaseFetchRows(int startRow, int pageSize) { + String innerSql = getLimitPageSqlWithMark(" SELECT id FROM config_info ORDER BY id "); + return " SELECT t.id,data_id,group_id,content,md5" + + " FROM ( " + innerSql + " ) " + + " g, config_info t WHERE g.id = t.id "; + } + + @Override + public String findAllConfigInfoFragment(int startRow, int pageSize) { + return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key " + + "FROM config_info WHERE id > ? ORDER BY id ASC ", startRow, pageSize); + } + + @Override + public String findChangeConfigFetchRows(Map params, final Timestamp startTime, + final Timestamp endTime, int startRow, int pageSize, long lastMaxId) { + final String tenant = params.get(TENANT); + final String dataId = params.get(DATA_ID); + final String group = params.get(GROUP); + final String appName = params.get(APP_NAME); + final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; + 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 (!StringUtils.isBlank(dataId)) { + where += " AND data_id LIKE ? "; + } + if (!StringUtils.isBlank(group)) { + where += " AND group_id LIKE ? "; + } + + if (!StringUtils.isBlank(tenantTmp)) { + where += " AND tenant_id = ? "; + } + + if (!StringUtils.isBlank(appName)) { + where += " AND app_name = ? "; + } + if (startTime != null) { + where += " AND gmt_modified >=? "; + } + if (endTime != null) { + where += " AND gmt_modified <=? "; + } + String orignSql = sqlFetchRows + where + " AND id > " + lastMaxId + " ORDER BY id ASC"; + return getLimitPageSqlWithOffset(orignSql,0, pageSize); + } + + @Override + public String listGroupKeyMd5ByPageFetchRows(int startRow, int pageSize) { + String innerSql = getLimitPageSqlWithOffset(" SELECT id FROM config_info ORDER BY id ", startRow, pageSize); + return " SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM " + + "( " + innerSql + " ) g, config_info t WHERE g.id = t.id"; + } + + @Override + public String findConfigInfoBaseLikeFetchRows(Map params, int startRow, int pageSize) { + final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE "; + String where = " 1=1 AND tenant_id='' "; + if (!StringUtils.isBlank(params.get(DATA_ID))) { + where += " AND data_id LIKE ? "; + } + if (!StringUtils.isBlank(params.get(GROUP))) { + where += " AND group_id LIKE "; + } + if (!StringUtils.isBlank(params.get(CONTENT))) { + where += " AND content LIKE ? "; + } + return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize); + } + + @Override + public String findConfigInfo4PageFetchRows(Map params, int startRow, int pageSize) { + final String appName = params.get(APP_NAME); + final String dataId = params.get(DATA_ID); + final String group = params.get(GROUP); + final String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info"; + StringBuilder where = new StringBuilder(" WHERE "); + where.append(" tenant_id=? "); + if (StringUtils.isNotBlank(dataId)) { + where.append(" AND data_id=? "); + } + if (StringUtils.isNotBlank(group)) { + where.append(" AND group_id=? "); + } + if (StringUtils.isNotBlank(appName)) { + where.append(" AND app_name=? "); + } + return getLimitPageSqlWithOffset(sql + where, startRow, pageSize); + } + + @Override + public String findConfigInfoBaseByGroupFetchRows(int startRow, int pageSize) { + String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=? "; + return getLimitPageSqlWithOffset(sql,startRow, pageSize); + } + + @Override + public String findConfigInfoLike4PageFetchRows(Map params, int startRow, int pageSize) { + String dataId = params.get(DATA_ID); + String group = params.get(GROUP); + final String appName = params.get(APP_NAME); + final String content = params.get(CONTENT); + 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 ? "); + if (!StringUtils.isBlank(dataId)) { + where.append(" AND data_id LIKE ? "); + } + if (!StringUtils.isBlank(group)) { + where.append(" AND group_id LIKE ? "); + } + if (!StringUtils.isBlank(appName)) { + where.append(" AND app_name = ? "); + } + if (!StringUtils.isBlank(content)) { + where.append(" AND content LIKE ? "); + } + return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize); + } + + @Override + public String findAllConfigInfoFetchRows(int startRow, int pageSize) { + String innerSql = getLimitPageSqlWithMark("SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id "); + return " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 " + + " FROM ( " + innerSql + " )" + + " g, config_info t WHERE g.id = t.id "; + } + + @Override + public String getTableName() { + return TableConstant.CONFIG_INFO; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoTagMapper.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoTagMapper.java new file mode 100644 index 0000000..eaf0289 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigInfoTagMapper.java @@ -0,0 +1,51 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.base; + +import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect; +import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql; +import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager; + +/** + * The base implementation of ConfigTagsRelationMapper. + * + * @author Long Yu + **/ +public class BaseConfigInfoTagMapper extends ConfigInfoTagMapperByMySql { + + private DatabaseDialect databaseDialect; + + public BaseConfigInfoTagMapper() { + databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource()); + } + + @Override + public String getTableName() { + return TableConstant.CONFIG_INFO_TAG; + } + + @Override + public String findAllConfigInfoTagForDumpAllFetchRows(int startRow, int pageSize) { + String innerSql = databaseDialect.getLimitPageSqlWithOffset("SELECT id FROM config_info_tag ORDER BY id ", + startRow, pageSize); + return " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified " + + " FROM ( " + innerSql + " ) " + + "g, config_info_tag t WHERE g.id = t.id "; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigTagsRelationMapper.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigTagsRelationMapper.java new file mode 100644 index 0000000..3d4c658 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseConfigTagsRelationMapper.java @@ -0,0 +1,117 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.base; + + +import com.alibaba.nacos.common.utils.StringUtils; +import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect; +import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql; +import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager; + +import java.util.Map; + +/** + * The postgresql implementation of ConfigTagsRelationMapper. + * + * @author Long Yu + **/ +public class BaseConfigTagsRelationMapper extends ConfigTagsRelationMapperByMySql { + + private DatabaseDialect databaseDialect; + + public BaseConfigTagsRelationMapper() { + databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource()); + } + + public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize) { + return databaseDialect.getLimitPageSqlWithOffset(sql, startOffset, pageSize); + } + + @Override + public String getTableName() { + return TableConstant.CONFIG_TAGS_RELATION; + } + + @Override + public String findConfigInfo4PageFetchRows(Map params, int tagSize, int startRow, int pageSize) { + final String appName = params.get("appName"); + final String dataId = params.get("dataId"); + final String group = params.get("group"); + StringBuilder where = new StringBuilder(" WHERE "); + final String sql = "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=? "); + + if (StringUtils.isNotBlank(dataId)) { + where.append(" AND a.data_id=? "); + } + if (StringUtils.isNotBlank(group)) { + where.append(" AND a.group_id=? "); + } + if (StringUtils.isNotBlank(appName)) { + where.append(" AND a.app_name=? "); + } + + where.append(" AND b.tag_name IN ("); + for (int i = 0; i < tagSize; i++) { + if (i != 0) { + where.append(", "); + } + where.append('?'); + } + where.append(") "); + return getLimitPageSqlWithOffset(sql + where,startRow,pageSize); + } + + @Override + public String findConfigInfoLike4PageFetchRows(final Map params, int tagSize, int startRow, int pageSize) { + final String appName = params.get("appName"); + final String content = params.get("content"); + final String dataId = params.get("dataId"); + final String group = params.get("group"); + StringBuilder where = new StringBuilder(" WHERE "); + final String sqlFetchRows = "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 ? "); + if (!StringUtils.isBlank(dataId)) { + where.append(" AND a.data_id LIKE ? "); + } + if (!StringUtils.isBlank(group)) { + where.append(" AND a.group_id LIKE ? "); + } + if (!StringUtils.isBlank(appName)) { + where.append(" AND a.app_name = ? "); + } + if (!StringUtils.isBlank(content)) { + where.append(" AND a.content LIKE ? "); + } + + where.append(" AND b.tag_name IN ("); + for (int i = 0; i < tagSize; i++) { + if (i != 0) { + where.append(", "); + } + where.append('?'); + } + where.append(") "); + return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize); + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseGroupCapacityMapper.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseGroupCapacityMapper.java new file mode 100644 index 0000000..6a69f20 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseGroupCapacityMapper.java @@ -0,0 +1,41 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.base; + +import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect; +import com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysql; +import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager; + +/** + * The base implementation of GroupCapacityMapper. + * + * @author Long Yu + **/ +public class BaseGroupCapacityMapper extends GroupCapacityMapperByMysql { + + private DatabaseDialect databaseDialect; + + public BaseGroupCapacityMapper() { + databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource()); + } + + @Override + public String selectGroupInfoBySize() { + return databaseDialect.getLimitTopSqlWithMark("SELECT id, group_id FROM group_capacity WHERE id > ?"); + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseTenantCapacityMapper.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseTenantCapacityMapper.java new file mode 100644 index 0000000..551b998 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseTenantCapacityMapper.java @@ -0,0 +1,41 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.base; + +import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect; +import com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql; +import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager; + +/** + * The base implementation of TenantCapacityMapper. + * + * @author Long Yu + **/ +public class BaseTenantCapacityMapper extends TenantCapacityMapperByMySql { + + private DatabaseDialect databaseDialect; + + public BaseTenantCapacityMapper() { + databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource()); + } + + @Override + public String getCapacityList4CorrectUsage() { + return databaseDialect.getLimitTopSqlWithMark("SELECT id, tenant_id FROM tenant_capacity WHERE id>?"); + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseTenantInfoMapper.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseTenantInfoMapper.java new file mode 100644 index 0000000..68c69f5 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/impl/base/BaseTenantInfoMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.base; + +import com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql; + +/** + * The base implementation of TenantInfo. + * + * @author Long Yu + **/ +public class BaseTenantInfoMapper extends TenantInfoMapperByMySql { + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/manager/DatabaseDialectManager.java b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/manager/DatabaseDialectManager.java new file mode 100644 index 0000000..21a31bc --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/java/com/alibaba/nacos/plugin/datasource/manager/DatabaseDialectManager.java @@ -0,0 +1,73 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.manager; + +import com.alibaba.nacos.common.spi.NacosServiceLoader; +import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect; +import com.alibaba.nacos.plugin.datasource.dialect.DefaultDatabaseDialect; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * DatabaseDialect SPI Manager. + * @author Long Yu + */ +public class DatabaseDialectManager { + + private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseDialectManager.class); + + private static final DatabaseDialectManager INSTANCE = new DatabaseDialectManager(); + + private static final Map SUPPORT_DIALECT_MAP = new ConcurrentHashMap(); + + private DatabaseDialectManager() { + } + + static { + //加载多种数据库方言为映射信息 + Collection dialectList = NacosServiceLoader.load(DatabaseDialect.class); + + for (DatabaseDialect dialect : dialectList) { + SUPPORT_DIALECT_MAP.put(dialect.getType(), dialect); + } + if (SUPPORT_DIALECT_MAP.isEmpty()) { + LOGGER.warn("[DatasourceDialectManager] Load DatabaseDialect fail, No DatabaseDialect implements"); + } + } + + public DatabaseDialect getDialect(String databaseType) { + DatabaseDialect databaseDialect = SUPPORT_DIALECT_MAP.get(databaseType); + if (databaseDialect == null) { + return new DefaultDatabaseDialect(); + } + return databaseDialect; + } + + /** + * Get DatasourceDialectManager instance. + * + * @return DataSourceDialectProvider + */ + public static DatabaseDialectManager getInstance() { + return INSTANCE; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect new file mode 100644 index 0000000..92dc081 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-datasource-plugin-ext-base/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect @@ -0,0 +1,19 @@ +# +# Copyright 1999-2022 Alibaba Group Holding Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +com.alibaba.nacos.plugin.datasource.dialect.DefaultDatabaseDialect + diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/pom.xml b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/pom.xml new file mode 100644 index 0000000..8f3aba7 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/pom.xml @@ -0,0 +1,38 @@ + + + + nacos-datasource-plugin-ext + com.alibaba.nacos + ${revision} + + 4.0.0 + + nacos-postgresql-datasource-plugin-ext + + + 8 + 8 + 42.2.19 + + + + + + org.postgresql + postgresql + ${jdbc.postgresql.version} + + + com.alibaba.nacos + nacos-datasource-plugin-ext-base + ${revision} + compile + + + + + + + \ No newline at end of file diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/PostgresqlDatabaseDialect.java b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/PostgresqlDatabaseDialect.java new file mode 100644 index 0000000..94c9717 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/PostgresqlDatabaseDialect.java @@ -0,0 +1,52 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.dialect; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; + +/** + * PostgreSQL database dialect. + * @author Long Yu + */ +public class PostgresqlDatabaseDialect extends AbstractDatabaseDialect { + + @Override + public String getType() { + return DatabaseTypeConstant.POSTGRESQL; + } + + @Override + public String getLimitTopSqlWithMark(String sql) { + return sql + " LIMIT ? "; + } + + @Override + public String getLimitPageSqlWithMark(String sql) { + return sql + " OFFSET ? LIMIT ? "; + } + + @Override + public String getLimitPageSql(String sql, int pageNo, int pageSize) { + return sql + " OFFSET " + getPagePrevNum(pageNo, pageSize) + " LIMIT " + pageSize; + } + + @Override + public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize){ + return sql + " OFFSET " + startOffset + " LIMIT " + pageSize; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoAggrMapperByPostgresql.java b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoAggrMapperByPostgresql.java new file mode 100644 index 0000000..25a44c5 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoAggrMapperByPostgresql.java @@ -0,0 +1,35 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.postgresql; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoAggrMapper; + +/** + * The postgresql implementation of ConfigInfoAggrMapper. + * + * @author Long Yu + **/ + +public class ConfigInfoAggrMapperByPostgresql extends BaseConfigInfoAggrMapper { + + @Override + public String getDataSource() { + return DatabaseTypeConstant.POSTGRESQL; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoBetaMapperByPostgresql.java b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoBetaMapperByPostgresql.java new file mode 100644 index 0000000..3622979 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoBetaMapperByPostgresql.java @@ -0,0 +1,35 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.postgresql; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoBetaMapper; + +/** + * The postgresql implementation of ConfigInfoBetaMapper. + * + * @author Long Yu + **/ + +public class ConfigInfoBetaMapperByPostgresql extends BaseConfigInfoBetaMapper { + + @Override + public String getDataSource() { + return DatabaseTypeConstant.POSTGRESQL; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoMapperByPostgresql.java b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoMapperByPostgresql.java new file mode 100644 index 0000000..474b5e0 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoMapperByPostgresql.java @@ -0,0 +1,34 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.postgresql; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoMapper; + +/** + * The postgresql implementation of ConfigInfoMapper. + * + * @author Long Yu + **/ +public class ConfigInfoMapperByPostgresql extends BaseConfigInfoMapper { + + @Override + public String getDataSource() { + return DatabaseTypeConstant.POSTGRESQL; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoTagMapperByPostgresql.java b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoTagMapperByPostgresql.java new file mode 100644 index 0000000..9ade83d --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigInfoTagMapperByPostgresql.java @@ -0,0 +1,35 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.postgresql; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoTagMapper; + +/** + * The postgresql implementation of ConfigInfoTagMapper. + * + * @author hyx + **/ + +public class ConfigInfoTagMapperByPostgresql extends BaseConfigInfoTagMapper { + + @Override + public String getDataSource() { + return DatabaseTypeConstant.POSTGRESQL; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigTagsRelationMapperByPostgresql.java b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigTagsRelationMapperByPostgresql.java new file mode 100644 index 0000000..40a88d2 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/ConfigTagsRelationMapperByPostgresql.java @@ -0,0 +1,35 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.postgresql; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigTagsRelationMapper; + +/** + * The postgresql implementation of ConfigTagsRelationMapper. + * + * @author Long Yu + **/ + +public class ConfigTagsRelationMapperByPostgresql extends BaseConfigTagsRelationMapper{ + + @Override + public String getDataSource() { + return DatabaseTypeConstant.POSTGRESQL; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/GroupCapacityMapperByPostgresql.java b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/GroupCapacityMapperByPostgresql.java new file mode 100644 index 0000000..eb2e6eb --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/GroupCapacityMapperByPostgresql.java @@ -0,0 +1,34 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.postgresql; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.impl.base.BaseGroupCapacityMapper; + +/** + * The base implementation of GroupCapacityMapper. + * + * @author Long Yu + **/ +public class GroupCapacityMapperByPostgresql extends BaseGroupCapacityMapper { + + @Override + public String getDataSource() { + return DatabaseTypeConstant.POSTGRESQL; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/HistoryConfigInfoMapperByPostgresql.java b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/HistoryConfigInfoMapperByPostgresql.java new file mode 100644 index 0000000..3147e82 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/HistoryConfigInfoMapperByPostgresql.java @@ -0,0 +1,41 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.postgresql; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql; + +/** + * The postgresql implementation of HistoryConfigInfoMapper. + * + * @author Long Yu + **/ +public class HistoryConfigInfoMapperByPostgresql extends HistoryConfigInfoMapperByMySql { + + @Override + public String removeConfigHistory() { + String sql = "WITH temp_table as (SELECT id FROM his_config_info WHERE gmt_modified < ? LIMIT ? ) " + + "DELETE FROM his_config_info WHERE id in (SELECT id FROM temp_table) "; + return sql; + } + + @Override + public String getDataSource() { + return DatabaseTypeConstant.POSTGRESQL; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/TenantCapacityMapperByPostgresql.java b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/TenantCapacityMapperByPostgresql.java new file mode 100644 index 0000000..241cfda --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/TenantCapacityMapperByPostgresql.java @@ -0,0 +1,35 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.postgresql; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.impl.base.BaseTenantCapacityMapper; + +/** + * The postgresql implementation of TenantCapacityMapper. + * + * @author Long Yu + **/ +public class TenantCapacityMapperByPostgresql extends BaseTenantCapacityMapper { + + @Override + public String getDataSource() { + return DatabaseTypeConstant.POSTGRESQL; + } + + +} diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/TenantInfoMapperByPostgresql.java b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/TenantInfoMapperByPostgresql.java new file mode 100644 index 0000000..0687ec0 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/postgresql/TenantInfoMapperByPostgresql.java @@ -0,0 +1,34 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.plugin.datasource.impl.postgresql; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.impl.base.BaseTenantInfoMapper; + +/** + * The postgresql implementation of ConfigInfoAggrMapper. + * + * @author Long Yu + **/ +public class TenantInfoMapperByPostgresql extends BaseTenantInfoMapper { + + @Override + public String getDataSource() { + return DatabaseTypeConstant.POSTGRESQL; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect new file mode 100644 index 0000000..b0bfee0 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect @@ -0,0 +1,20 @@ +# +# Copyright 1999-2022 Alibaba Group Holding Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +com.alibaba.nacos.plugin.datasource.dialect.PostgresqlDatabaseDialect + + diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper new file mode 100644 index 0000000..5fa725d --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper @@ -0,0 +1,27 @@ +# +# Copyright 1999-2022 Alibaba Group Holding Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoAggrMapperByPostgresql +com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoBetaMapperByPostgresql +com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoMapperByPostgresql +com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoTagMapperByPostgresql +com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigTagsRelationMapperByPostgresql +com.alibaba.nacos.plugin.datasource.impl.postgresql.HistoryConfigInfoMapperByPostgresql +com.alibaba.nacos.plugin.datasource.impl.postgresql.TenantInfoMapperByPostgresql +com.alibaba.nacos.plugin.datasource.impl.postgresql.TenantCapacityMapperByPostgresql +com.alibaba.nacos.plugin.datasource.impl.postgresql.GroupCapacityMapperByPostgresql + + diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/resources/schema/nacos-pg.sql b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/resources/schema/nacos-pg.sql new file mode 100644 index 0000000..bb4d03b --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/src/main/resources/schema/nacos-pg.sql @@ -0,0 +1,495 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +-- ---------------------------- +-- 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 NOT NULL +) +; + +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'; + + +-- ---------------------------- +-- 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 '增加租户字段'; + +-- ---------------------------- +-- Records of config_info_aggr +-- ---------------------------- +BEGIN; +COMMIT; + +-- ---------------------------- +-- 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 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'; + +-- ---------------------------- +-- Records of config_info_beta +-- ---------------------------- +BEGIN; +COMMIT; + +-- ---------------------------- +-- 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'; + +-- ---------------------------- +-- Records of config_info_tag +-- ---------------------------- +BEGIN; +COMMIT; + +-- ---------------------------- +-- Table structure for config_tags_relation +-- ---------------------------- +DROP TABLE IF EXISTS "config_tags_relation"; +CREATE TABLE "config_tags_relation" ( + "id" bigserial 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'; + +-- ---------------------------- +-- Records of config_tags_relation +-- ---------------------------- +BEGIN; +COMMIT; + +-- ---------------------------- +-- 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容量信息表'; + +-- ---------------------------- +-- Records of group_capacity +-- ---------------------------- +BEGIN; +COMMIT; + +-- ---------------------------- +-- 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 NOT NULL +) +; +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 '多租户改造'; + + +-- ---------------------------- +-- 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 +) +; + +-- ---------------------------- +-- Records of permissions +-- ---------------------------- +BEGIN; +COMMIT; + +-- ---------------------------- +-- Table structure for roles +-- ---------------------------- +DROP TABLE IF EXISTS "roles"; +CREATE TABLE "roles" ( + "username" varchar(50) NOT NULL, + "role" varchar(50) NOT NULL +) +; + +-- ---------------------------- +-- Records of roles +-- ---------------------------- +BEGIN; +INSERT INTO "roles" VALUES ('nacos', 'ROLE_ADMIN'); +COMMIT; + +-- ---------------------------- +-- 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 '租户容量信息表'; + +-- ---------------------------- +-- Records of tenant_capacity +-- ---------------------------- +BEGIN; +COMMIT; + +-- ---------------------------- +-- 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'; + +-- ---------------------------- +-- Records of tenant_info +-- ---------------------------- +BEGIN; +COMMIT; + +-- ---------------------------- +-- 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 +) +; + +-- ---------------------------- +-- Records of users +-- ---------------------------- +BEGIN; +INSERT INTO "users" VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE); +COMMIT; + +-- ---------------------------- +-- 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"); + +-- ---------------------------- +-- 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"); + +-- ---------------------------- +-- 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"); + +-- ---------------------------- +-- 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"); + +-- ---------------------------- +-- 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"); + +-- ---------------------------- +-- 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"); + +-- ---------------------------- +-- 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"); + +-- ---------------------------- +-- Indexes structure for table permissions +-- ---------------------------- +CREATE UNIQUE INDEX "uk_role_permission" ON "permissions" USING btree ( + "role", + "resource", + "action" +); + +-- ---------------------------- +-- Indexes structure for table roles +-- ---------------------------- +CREATE UNIQUE INDEX "uk_username_role" ON "roles" USING btree ( + "username", + "role" +); + +-- ---------------------------- +-- 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"); + +-- ---------------------------- +-- Indexes structure for table tenant_info +-- ---------------------------- +CREATE UNIQUE INDEX "uk_tenant_info_kptenantid" ON "tenant_info" USING btree ( + "kp", + "tenant_id" +); diff --git a/nacos-datasource-plugin-ext/pom.xml b/nacos-datasource-plugin-ext/pom.xml new file mode 100644 index 0000000..b5986c8 --- /dev/null +++ b/nacos-datasource-plugin-ext/pom.xml @@ -0,0 +1,36 @@ + + + + nacos-plugin-ext + com.alibaba.nacos + ${revision} + + 4.0.0 + + nacos-datasource-plugin-ext + pom + + + nacos-datasource-plugin-ext-base + nacos-postgresql-datasource-plugin-ext + + + + 8 + 8 + + + + + com.alibaba.nacos + nacos-datasource-plugin + + + com.alibaba.nacos + nacos-common + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index e581509..3e24f9d 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,7 @@ nacos-encryption-plugin-ext nacos-trace-plugin-ext nacos-custom-environment-plugin-ext + nacos-datasource-plugin-ext @@ -41,7 +42,7 @@ UTF-8 1.8 1.8 - 2.2.0-SNAPSHOT + 2.2.0 1.1.0 3.2.4 4.12 @@ -72,6 +73,12 @@ nacos-trace-plugin ${alibaba-nacos.version} + + com.alibaba.nacos + nacos-datasource-plugin + ${alibaba-nacos.version} + provided + com.alibaba.nacos