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 index bf6768f..644a09f 100644 --- 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 @@ -25,6 +25,7 @@ public class DatabaseTypeConstant { public static final String POSTGRESQL = "postgresql"; + public static final String GUASSDB = "gaussdb"; public static final String MYSQL = "mysql"; diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/pom.xml b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/pom.xml new file mode 100644 index 0000000..75812d6 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/pom.xml @@ -0,0 +1,85 @@ + + + + nacos-datasource-plugin-ext + com.alibaba.nacos + ${revision} + + 4.0.0 + + nacos-opengauss-datasource-plugin-ext + 1.0.0 + + + 8 + 8 + 42.2.19 + + + + + + org.opengauss + opengauss-jdbc + 5.1.0-og + + + com.alibaba.nacos + nacos-datasource-plugin-ext-base + ${revision} + compile + + + com.alibaba.nacos + nacos-aes-encryption-plugin + 1.0.0-SNAPSHOT + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + false + + + + package + + shade + + + + + + + + *:* + + module-info.class + META-INF/NOTICE.txt + META-INF/LICENSE + META-INF/NOTICE + META-INF/DEPENDENCIES + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + META-INF/*.MF + + + + + + + + + + + + \ No newline at end of file diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/GaussdbDatabaseDialect.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/GaussdbDatabaseDialect.java new file mode 100644 index 0000000..a9ddcf5 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/GaussdbDatabaseDialect.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 GaussdbDatabaseDialect extends AbstractDatabaseDialect { + + @Override + public String getType() { + return DatabaseTypeConstant.GUASSDB; + } + + @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-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/enums/GaussdbFunctionEnum.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/enums/GaussdbFunctionEnum.java new file mode 100644 index 0000000..abd7448 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/enums/GaussdbFunctionEnum.java @@ -0,0 +1,66 @@ +/* + * 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. + */ + +package com.alibaba.nacos.plugin.datasource.impl.enums; + +import java.util.HashMap; +import java.util.Map; + +/** + * The TrustedSqlFunctionEnum enum class is used to enumerate and manage a list of trusted built-in SQL functions. + * By using this enum, you can verify whether a given SQL function is part of the trusted functions list + * to avoid potential SQL injection risks. + * + * @author blake.qiu + */ +public enum GaussdbFunctionEnum { + + /** + * NOW(). + */ + NOW("NOW()", "NOW()"); + + private static final Map LOOKUP_MAP = new HashMap<>(); + + static { + for (GaussdbFunctionEnum entry : GaussdbFunctionEnum.values()) { + LOOKUP_MAP.put(entry.functionName, entry); + } + } + + private final String functionName; + + private final String function; + + GaussdbFunctionEnum(String functionName, String function) { + this.functionName = functionName; + this.function = function; + } + + /** + * Get the function name. + * + * @param functionName function name + * @return function + */ + public static String getFunctionByName(String functionName) { + GaussdbFunctionEnum entry = LOOKUP_MAP.get(functionName); + if (entry != null) { + return entry.function; + } + throw new IllegalArgumentException(String.format("Invalid function name: %s", functionName)); + } +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/AbstractMapperByGaussdb.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/AbstractMapperByGaussdb.java new file mode 100644 index 0000000..89f8277 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/AbstractMapperByGaussdb.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.impl.opengauss; + +import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect; +import com.alibaba.nacos.plugin.datasource.impl.enums.GaussdbFunctionEnum; +import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager; +import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; + +/** + * The base implementation of ConfigTagsRelationMapper. + * + * @author Long Yu + **/ +public abstract class AbstractMapperByGaussdb extends AbstractMapper { + + private DatabaseDialect databaseDialect; + + public DatabaseDialect getDatabaseDialect() { + return databaseDialect; + } + + public AbstractMapperByGaussdb() { + databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource()); + } + + @Override + public String getDataSource() { + return DatabaseTypeConstant.GUASSDB; + } + + @Override + public String getFunction(String functionName) { + return GaussdbFunctionEnum.getFunctionByName(functionName); + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoAggrMapper.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoAggrMapper.java new file mode 100644 index 0000000..38c1e0e --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoAggrMapper.java @@ -0,0 +1,56 @@ +/* + * 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.opengauss; + + +import java.util.List; + +import com.alibaba.nacos.common.utils.CollectionUtils; +import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; + +/** + * The base implementation of ConfigInfoBetaMapper. + * + * @author Long Yu + **/ +public class OpenGaussConfigInfoAggrMapper extends AbstractMapperByGaussdb implements ConfigInfoAggrMapper { + + @Override + public String getTableName() { + return TableConstant.CONFIG_INFO_AGGR; + } + + @Override + public MapperResult findConfigInfoAggrByPageFetchRows(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID); + String groupId = (String) context.getWhereParameter(FieldConstant.GROUP_ID); + String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID); + String sql = getDatabaseDialect().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); + List paramList = CollectionUtils.list(dataId, groupId, tenantId); + return new MapperResult(sql, paramList); + } + + +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoBetaMapper.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoBetaMapper.java new file mode 100644 index 0000000..d9fe13c --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoBetaMapper.java @@ -0,0 +1,56 @@ +/* + * 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.opengauss; + + +import java.util.Collections; + +import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; + +/** + * The base implementation of ConfigInfoBetaMapper. + * + * @author Long Yu + **/ +public class OpenGaussConfigInfoBetaMapper extends AbstractMapperByGaussdb implements ConfigInfoBetaMapper { + + @Override + public String getTableName() { + return TableConstant.CONFIG_INFO_BETA; + } + + public String getLimitPageSqlWithOffset(String sql, int startRow, int pageSize) { + return getDatabaseDialect().getLimitPageSqlWithOffset(sql, startRow, pageSize); + } + + @Override + public MapperResult findAllConfigInfoBetaForDumpAllFetchRows(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String sqlInner = getLimitPageSqlWithOffset("SELECT id FROM config_info_beta ORDER BY id ", startRow, + pageSize); + String sql = + " 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 "; + return new MapperResult(sql, Collections.emptyList()); + } + + +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoMapper.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoMapper.java new file mode 100644 index 0000000..161463a --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoMapper.java @@ -0,0 +1,281 @@ +/* + * 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.opengauss; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.alibaba.nacos.common.utils.CollectionUtils; +import com.alibaba.nacos.common.utils.StringUtils; +import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; + +/** + * The base implementation of ConfigInfoMapper. + * + * @author Long Yu + **/ +public class OpenGaussConfigInfoMapper extends AbstractMapperByGaussdb implements ConfigInfoMapper { + + + public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize) { + return getDatabaseDialect().getLimitPageSqlWithOffset(sql, startOffset, pageSize); + } + + public String getLimitPageSqlWithMark(String sql) { + return getDatabaseDialect().getLimitPageSqlWithMark(sql); + } + + @Override + public MapperResult findConfigInfoByAppFetchRows(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME); + final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID); + String sql = getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info" + + " WHERE tenant_id LIKE ? AND app_name= ?", startRow, pageSize); + return new MapperResult(sql, CollectionUtils.list(tenantId, appName)); + } + + @Override + public MapperResult getTenantIdList(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String sql = getLimitPageSqlWithOffset( + "SELECT tenant_id FROM config_info WHERE tenant_id != '' GROUP BY tenant_id ", startRow, pageSize); + return new MapperResult(sql, Collections.emptyList()); + } + + @Override + public MapperResult getGroupIdList(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String sql = getLimitPageSqlWithOffset( + "SELECT group_id FROM config_info WHERE tenant_id ='' GROUP BY group_id ", +startRow, pageSize); + return new MapperResult(sql, Collections.emptyList()); + } + + @Override + public MapperResult findAllConfigKey(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String innerSql = getLimitPageSqlWithOffset(" SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id ", + startRow, pageSize); + String sql = " SELECT data_id,group_id,app_name FROM ( " + innerSql + " g, config_info t WHERE g.id = t.id "; + return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.TENANT_ID))); + } + + @Override + public MapperResult findAllConfigInfoBaseFetchRows(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String innerSql = getLimitPageSqlWithMark(" SELECT id FROM config_info ORDER BY id "); + String sql = " SELECT t.id,data_id,group_id,content,md5" + " FROM ( " + innerSql + " ) " + + " g, config_info t WHERE g.id = t.id "; + return new MapperResult(sql, CollectionUtils.list(startRow, pageSize)); + } + + @Override + public MapperResult findAllConfigInfoFragment(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String sql = 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); + return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID))); + } + + @Override + public MapperResult findChangeConfigFetchRows(MapperContext context) { + final String tenant = (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 tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; + final Timestamp startTime = (Timestamp) context.getWhereParameter(FieldConstant.START_TIME); + final Timestamp endTime = (Timestamp) context.getWhereParameter(FieldConstant.END_TIME); + final long lastMaxId = (long) context.getWhereParameter(FieldConstant.LAST_MAX_ID); + final int pageSize = context.getPageSize(); + 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 (!StringUtils.isBlank(dataId)) { + where += " AND data_id LIKE ? "; + paramList.add(dataId); + } + if (!StringUtils.isBlank(group)) { + where += " AND group_id LIKE ? "; + paramList.add(group); + } + if (!StringUtils.isBlank(tenantTmp)) { + where += " AND tenant_id = ? "; + paramList.add(tenantTmp); + } + if (!StringUtils.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 originSql = sqlFetchRows + where + " AND id > " + lastMaxId + " ORDER BY id ASC"; + String sql = getLimitPageSqlWithOffset(originSql, 0, pageSize); + return new MapperResult(sql, paramList); + } + + @Override + public MapperResult listGroupKeyMd5ByPageFetchRows(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String innerSql = getLimitPageSqlWithOffset(" SELECT id FROM config_info ORDER BY id ", startRow, pageSize); + String sql = + " 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"; + return new MapperResult(sql, Collections.emptyList()); + } + + @Override + public MapperResult findConfigInfoBaseLikeFetchRows(MapperContext context) { + 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 sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE "; + String where = " 1=1 AND tenant_id='' "; + List paramList = new ArrayList<>(); + if (!StringUtils.isBlank(dataId)) { + where += " AND data_id LIKE ? "; + paramList.add(dataId); + } + if (!StringUtils.isBlank(group)) { + where += " AND group_id LIKE "; + paramList.add(group); + } + if (!StringUtils.isBlank(content)) { + where += " AND content LIKE ? "; + paramList.add(content); + } + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String sql = getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize); + return new MapperResult(sql, paramList); + } + + @Override + public MapperResult findConfigInfo4PageFetchRows(MapperContext context) { + final String tenant = (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<>(); + 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=? "); + paramList.add(tenant); + if (StringUtils.isNotBlank(dataId)) { + where.append(" AND data_id=? "); + paramList.add(dataId); + } + if (StringUtils.isNotBlank(group)) { + where.append(" AND group_id=? "); + paramList.add(group); + } + if (StringUtils.isNotBlank(appName)) { + where.append(" AND app_name=? "); + paramList.add(appName); + } + if (!StringUtils.isBlank(content)) { + where.append(" AND content LIKE ? "); + paramList.add(content); + } + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String resultSql = getLimitPageSqlWithOffset(sql + where, startRow, pageSize); + return new MapperResult(resultSql, paramList); + } + + @Override + public MapperResult findConfigInfoBaseByGroupFetchRows(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=? "; + String resultSql = getLimitPageSqlWithOffset(sql, startRow, pageSize); + return new MapperResult(resultSql, CollectionUtils.list(context.getWhereParameter(FieldConstant.GROUP_ID), + context.getWhereParameter(FieldConstant.TENANT_ID))); + } + + @Override + public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) { + final String tenant = (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); + 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 ? "); + List paramList = new ArrayList<>(); + paramList.add(tenant); + if (!StringUtils.isBlank(dataId)) { + where.append(" AND data_id LIKE ? "); + paramList.add(dataId); + } + if (!StringUtils.isBlank(group)) { + where.append(" AND group_id LIKE ? "); + paramList.add(group); + } + if (!StringUtils.isBlank(appName)) { + where.append(" AND app_name = ? "); + paramList.add(appName); + } + if (!StringUtils.isBlank(content)) { + where.append(" AND content LIKE ? "); + paramList.add(content); + } + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String sql = getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize); + return new MapperResult(sql, paramList); + } + + @Override + public MapperResult findAllConfigInfoFetchRows(MapperContext context) { + String innerSql = getLimitPageSqlWithMark("SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id "); + String sql = " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 " + " FROM ( " + innerSql + " )" + + " g, config_info t WHERE g.id = t.id "; + return new MapperResult(sql, CollectionUtils + .list(context.getWhereParameter(FieldConstant.TENANT_ID), context.getStartRow(), + context.getPageSize())); + } + + @Override + public String getTableName() { + return TableConstant.CONFIG_INFO; + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoTagMapper.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoTagMapper.java new file mode 100644 index 0000000..e86e034 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigInfoTagMapper.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.opengauss; + +import java.util.Collections; + +import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; + +/** + * The base implementation of ConfigTagsRelationMapper. + * + * @author Long Yu + **/ +public class OpenGaussConfigInfoTagMapper extends AbstractMapperByGaussdb implements ConfigInfoTagMapper { + + @Override + public String getTableName() { + return TableConstant.CONFIG_INFO_TAG; + } + + @Override + public MapperResult findAllConfigInfoTagForDumpAllFetchRows(MapperContext context) { + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String innerSql = getDatabaseDialect() + .getLimitPageSqlWithOffset("SELECT id FROM config_info_tag ORDER BY id ", startRow, pageSize); + String sql = " 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 "; + return new MapperResult(sql, Collections.emptyList()); + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigTagsRelationMapper.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigTagsRelationMapper.java new file mode 100644 index 0000000..4762e2b --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussConfigTagsRelationMapper.java @@ -0,0 +1,140 @@ +/* + * 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.opengauss; + + +import java.util.ArrayList; +import java.util.List; + +import com.alibaba.nacos.common.utils.StringUtils; +import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper; +import com.alibaba.nacos.plugin.datasource.model.MapperContext; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; + +/** + * The postgresql implementation of ConfigTagsRelationMapper. + * + * @author Long Yu + **/ +public class OpenGaussConfigTagsRelationMapper extends AbstractMapperByGaussdb implements ConfigTagsRelationMapper { + + public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize) { + return getDatabaseDialect().getLimitPageSqlWithOffset(sql, startOffset, pageSize); + } + + @Override + public String getTableName() { + return TableConstant.CONFIG_TAGS_RELATION; + } + + @Override + public MapperResult findConfigInfo4PageFetchRows(MapperContext context) { + final String tenant = (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); + final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR); + List paramList = new ArrayList<>(); + 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=? "); + paramList.add(tenant); + if (StringUtils.isNotBlank(dataId)) { + where.append(" AND a.data_id=? "); + paramList.add(dataId); + } + if (StringUtils.isNotBlank(group)) { + where.append(" AND a.group_id=? "); + paramList.add(group); + } + if (StringUtils.isNotBlank(appName)) { + where.append(" AND a.app_name=? "); + paramList.add(appName); + } + if (!StringUtils.isBlank(content)) { + where.append(" AND a.content LIKE ? "); + paramList.add(content); + } + + 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(") "); + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String resultSql = getLimitPageSqlWithOffset(sql + where, startRow, pageSize); + return new MapperResult(resultSql, paramList); + } + + @Override + public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) { + final String tenant = (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); + final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR); + List paramList = new ArrayList<>(); + 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 ? "); + paramList.add(tenant); + if (!StringUtils.isBlank(dataId)) { + where.append(" AND a.data_id LIKE ? "); + paramList.add(dataId); + } + if (!StringUtils.isBlank(group)) { + where.append(" AND a.group_id LIKE ? "); + paramList.add(group); + } + if (!StringUtils.isBlank(appName)) { + where.append(" AND a.app_name = ? "); + paramList.add(appName); + } + if (!StringUtils.isBlank(content)) { + where.append(" AND a.content LIKE ? "); + paramList.add(content); + } + 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(") "); + int startRow = context.getStartRow(); + int pageSize = context.getPageSize(); + String sql = getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize); + return new MapperResult(sql, paramList); + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussGroupCapacityMapper.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussGroupCapacityMapper.java new file mode 100644 index 0000000..783a781 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussGroupCapacityMapper.java @@ -0,0 +1,39 @@ +/* + * 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.opengauss; + +import com.alibaba.nacos.common.utils.CollectionUtils; +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; + +/** + * The base implementation of GroupCapacityMapper. + * + * @author Long Yu + **/ +public class OpenGaussGroupCapacityMapper extends AbstractMapperByGaussdb implements GroupCapacityMapper { + + @Override + public MapperResult selectGroupInfoBySize(MapperContext context) { + String sql = getDatabaseDialect().getLimitTopSqlWithMark("SELECT id, group_id FROM group_capacity WHERE id > ?"); + return new MapperResult(sql, + CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), context.getPageSize())); + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussHistoryConfigInfoMapper.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussHistoryConfigInfoMapper.java new file mode 100644 index 0000000..5a0677b --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussHistoryConfigInfoMapper.java @@ -0,0 +1,50 @@ +/* + * 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.opengauss; + +import com.alibaba.nacos.common.utils.CollectionUtils; +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; + +/** + * The postgresql implementation of HistoryConfigInfoMapper. + * + * @author Long Yu + **/ +public class OpenGaussHistoryConfigInfoMapper extends AbstractMapperByGaussdb implements HistoryConfigInfoMapper { + + @Override + public MapperResult removeConfigHistory(MapperContext context) { + 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 new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.START_TIME), + context.getWhereParameter(FieldConstant.LIMIT_SIZE))); + } + + @Override + public MapperResult pageFindConfigHistoryFetchRows(MapperContext context) { + String sql = + "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info " + + "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC LIMIT " + + context.getStartRow() + "," + context.getPageSize(); + return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.DATA_ID), + context.getWhereParameter(FieldConstant.GROUP_ID), context.getWhereParameter(FieldConstant.TENANT_ID))); + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussTenantCapacityMapper.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussTenantCapacityMapper.java new file mode 100644 index 0000000..b10fd6e --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussTenantCapacityMapper.java @@ -0,0 +1,39 @@ +/* + * 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.opengauss; + +import com.alibaba.nacos.common.utils.CollectionUtils; +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; + +/** + * The base implementation of TenantCapacityMapper. + * + * @author Long Yu + **/ +public class OpenGaussTenantCapacityMapper extends AbstractMapperByGaussdb implements TenantCapacityMapper { + + @Override + public MapperResult getCapacityList4CorrectUsage(MapperContext context) { + String sql = getDatabaseDialect().getLimitTopSqlWithMark("SELECT id, tenant_id FROM tenant_capacity WHERE id>?"); + return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), + context.getWhereParameter(FieldConstant.LIMIT_SIZE))); + } + +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussTenantInfoMapper.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussTenantInfoMapper.java new file mode 100644 index 0000000..bffcc46 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/impl/opengauss/OpenGaussTenantInfoMapper.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.opengauss; + +import com.alibaba.nacos.plugin.datasource.mapper.TenantInfoMapper; + +/** + * The base implementation of TenantInfo. + * + * @author Long Yu + **/ +public class OpenGaussTenantInfoMapper extends AbstractMapperByGaussdb implements TenantInfoMapper { + +} diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect new file mode 100644 index 0000000..494bb34 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-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.GaussdbDatabaseDialect + + diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper new file mode 100644 index 0000000..e095d9b --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-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.opengauss.OpenGaussConfigInfoAggrMapper +com.alibaba.nacos.plugin.datasource.impl.opengauss.OpenGaussConfigInfoBetaMapper +com.alibaba.nacos.plugin.datasource.impl.opengauss.OpenGaussConfigInfoMapper +com.alibaba.nacos.plugin.datasource.impl.opengauss.OpenGaussConfigInfoTagMapper +com.alibaba.nacos.plugin.datasource.impl.opengauss.OpenGaussConfigTagsRelationMapper +com.alibaba.nacos.plugin.datasource.impl.opengauss.OpenGaussGroupCapacityMapper +com.alibaba.nacos.plugin.datasource.impl.opengauss.OpenGaussHistoryConfigInfoMapper +com.alibaba.nacos.plugin.datasource.impl.opengauss.OpenGaussTenantCapacityMapper +com.alibaba.nacos.plugin.datasource.impl.opengauss.OpenGaussTenantInfoMapper + diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/resources/schema/nacos-openguass-compatible-mysql.sql b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/resources/schema/nacos-openguass-compatible-mysql.sql new file mode 100644 index 0000000..5ec6fbf --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/resources/schema/nacos-openguass-compatible-mysql.sql @@ -0,0 +1,498 @@ +/* + * 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. + */ + +create database com_mysql_nacos dbcompatibility = 'B'; +CREATE SCHEMA 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 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/nacos-opengauss-datasource-plugin-ext/src/main/resources/schema/nacos-openguass-compatible-oracle.sql b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/resources/schema/nacos-openguass-compatible-oracle.sql new file mode 100644 index 0000000..a4192f6 --- /dev/null +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/resources/schema/nacos-openguass-compatible-oracle.sql @@ -0,0 +1,499 @@ +/* + * 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. + */ + + +create database com_oracle_nacos dbcompatibility = 'A'; +CREATE SCHEMA 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) NOT NULL, + "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) NOT NULL, + "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) NOT NULL +) +; +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) NOT NULL, + "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) NOT NULL, + "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) NOT NULL, + "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) NOT NULL, + "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) NOT NULL, + "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 index 1f6b50d..1cf5108 100644 --- a/nacos-datasource-plugin-ext/pom.xml +++ b/nacos-datasource-plugin-ext/pom.xml @@ -15,6 +15,7 @@ nacos-datasource-plugin-ext-base nacos-postgresql-datasource-plugin-ext + nacos-opengauss-datasource-plugin-ext nacos-oracle-datasource-plugin-ext nacos-dm-datasource-plugin-ext nacos-mssql-datasource-plugin-ext diff --git a/pom.xml b/pom.xml index 9fef647..28d3dc2 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ UTF-8 1.8 1.8 - 2.3.0-SNAPSHOT + 2.4.3 1.1.0 3.2.4 4.12