diff --git a/CHANGES.md b/CHANGES.md index cccd30b1b50..3029a1fa0c4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Apollo 2.3.0 * [Fix circular references on LdapAutoConfiguration](https://github.com/apolloconfig/apollo/pull/5055) * [Add comment for clusters and UI display](https://github.com/apolloconfig/apollo/pull/5072) * [Fix the issue that the length of private namespaces are mis-calculated](https://github.com/apolloconfig/apollo/pull/5078) +* [apollo assembly optimization](https://github.com/apolloconfig/apollo/pull/5035) ------------------ diff --git a/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/AdminServiceApplication.java b/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/AdminServiceApplication.java index 3ed43f44a9f..e62e1901da2 100644 --- a/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/AdminServiceApplication.java +++ b/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/AdminServiceApplication.java @@ -21,6 +21,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; @@ -29,7 +30,9 @@ @EnableAspectJAutoProxy @Configuration @PropertySource(value = {"classpath:adminservice.properties"}) -@EnableAutoConfiguration +@EnableAutoConfiguration(exclude = { + UserDetailsServiceAutoConfiguration.class, +}) @EnableTransactionManagement @ComponentScan(basePackageClasses = {ApolloCommonConfig.class, ApolloBizConfig.class, diff --git a/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/AdminServiceAssemblyConfiguration.java b/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/AdminServiceAssemblyConfiguration.java new file mode 100644 index 00000000000..0c517375183 --- /dev/null +++ b/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/AdminServiceAssemblyConfiguration.java @@ -0,0 +1,39 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.adminservice; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.core.annotation.Order; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Profile("assembly") +@Configuration +public class AdminServiceAssemblyConfiguration { + + @Order(101) + @Configuration + static class AdminServiceSecurityConfigurer extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable(); + http.httpBasic(); + } + } +} diff --git a/apollo-assembly/pom.xml b/apollo-assembly/pom.xml index 635e28733c3..adea3607fea 100644 --- a/apollo-assembly/pom.xml +++ b/apollo-assembly/pom.xml @@ -46,6 +46,34 @@ + + org.apache.maven.plugins + maven-resources-plugin + 3.2.0 + + + copy-resources + validate + + copy-resources + + + ${project.build.directory}/classes/META-INF/sql/profiles + + + ${project.parent.basedir}/scripts/sql/profiles + + h2-default/apolloconfigdb.sql + h2-default/apolloportaldb.sql + mysql-database-not-specified/apolloconfigdb.sql + mysql-database-not-specified/apolloportaldb.sql + + + + + + + org.springframework.boot spring-boot-maven-plugin diff --git a/apollo-assembly/src/main/java/com/ctrip/framework/apollo/assembly/ApolloApplication.java b/apollo-assembly/src/main/java/com/ctrip/framework/apollo/assembly/ApolloApplication.java index 79e3477da8f..bdd6a1c1e51 100644 --- a/apollo-assembly/src/main/java/com/ctrip/framework/apollo/assembly/ApolloApplication.java +++ b/apollo-assembly/src/main/java/com/ctrip/framework/apollo/assembly/ApolloApplication.java @@ -23,16 +23,22 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.context.scope.refresh.RefreshScope; import org.springframework.context.ConfigurableApplicationContext; -@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, - HibernateJpaAutoConfiguration.class, ApolloAuditAutoConfiguration.class}) +@SpringBootApplication(exclude = { + DataSourceAutoConfiguration.class, + DataSourceTransactionManagerAutoConfiguration.class, + HibernateJpaAutoConfiguration.class, + ApolloAuditAutoConfiguration.class, +}) public class ApolloApplication { private static final Logger logger = LoggerFactory.getLogger(ApolloApplication.class); @@ -41,39 +47,46 @@ public static void main(String[] args) throws Exception { /** * Common */ + MDC.put("starting_context", "[starting:common] "); + logger.info("commonContext starting..."); ConfigurableApplicationContext commonContext = new SpringApplicationBuilder(ApolloApplication.class).web(WebApplicationType.NONE).run(args); - logger.info(commonContext.getId() + " isActive: " + commonContext.isActive()); + logger.info("commonContext [{}] isActive: {}", commonContext.getId(), commonContext.isActive()); /** * ConfigService */ - if (commonContext.getEnvironment().containsProperty("configservice")) { - ConfigurableApplicationContext configContext = - new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext) - .sources(RefreshScope.class).run(args); - logger.info(configContext.getId() + " isActive: " + configContext.isActive()); - } + MDC.put("starting_context", "[starting:config] "); + logger.info("configContext starting..."); + ConfigurableApplicationContext configContext = + new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext) + .profiles("assembly") + .sources(RefreshScope.class).run(args); + logger.info("configContext [{}] isActive: {}", configContext.getId(), configContext.isActive()); /** * AdminService */ - if (commonContext.getEnvironment().containsProperty("adminservice")) { - ConfigurableApplicationContext adminContext = - new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext) - .sources(RefreshScope.class).run(args); - logger.info(adminContext.getId() + " isActive: " + adminContext.isActive()); - } + MDC.put("starting_context", "[starting:admin] "); + logger.info("adminContext starting..."); + ConfigurableApplicationContext adminContext = + new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext) + .profiles("assembly") + .sources(RefreshScope.class).run(args); + logger.info("adminContext [{}] isActive: {}", adminContext.getId(), adminContext.isActive()); /** * Portal */ - if (commonContext.getEnvironment().containsProperty("portal")) { - ConfigurableApplicationContext portalContext = - new SpringApplicationBuilder(PortalApplication.class).parent(commonContext) - .sources(RefreshScope.class).run(args); - logger.info(portalContext.getId() + " isActive: " + portalContext.isActive()); - } + MDC.put("starting_context", "[starting:portal] "); + logger.info("portalContext starting..."); + ConfigurableApplicationContext portalContext = + new SpringApplicationBuilder(PortalApplication.class).parent(commonContext) + .profiles("assembly") + .sources(RefreshScope.class).run(args); + logger.info("portalContext [{}] isActive: {}", portalContext.getId(), portalContext.isActive()); + + MDC.clear(); } } diff --git a/apollo-assembly/src/main/resources/application-database-discovery.properties b/apollo-assembly/src/main/resources/application-database-discovery.properties new file mode 100644 index 00000000000..dcdb6f1ab62 --- /dev/null +++ b/apollo-assembly/src/main/resources/application-database-discovery.properties @@ -0,0 +1,26 @@ +# +# Copyright 2024 Apollo Authors +# +# 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. +# +apollo.eureka.server.enabled=false +eureka.client.enabled=false +spring.cloud.discovery.enabled=false + +apollo.service.registry.enabled=true +apollo.service.registry.cluster=default +apollo.service.registry.heartbeatIntervalInSecond=10 + +apollo.service.discovery.enabled=true +# health check by heartbeat, heartbeat time before 61s ago will be seemed as unhealthy +apollo.service.discovery.healthCheckIntervalInSecond = 61 diff --git a/apollo-assembly/src/main/resources/application-github.properties b/apollo-assembly/src/main/resources/application-github.properties new file mode 100644 index 00000000000..fbdcfe0c70c --- /dev/null +++ b/apollo-assembly/src/main/resources/application-github.properties @@ -0,0 +1,47 @@ +# +# Copyright 2024 Apollo Authors +# +# 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. +# +# Config DataSource +spring.config-datasource.url=jdbc:h2:mem:~/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE +#spring.config-datasource.username= +#spring.config-datasource.password= +spring.sql.config-init.schema-locations=@@repository@@/profiles/@@platform@@@@suffix@@/apolloconfigdb.sql +spring.sql.config-init.mode=embedded +# Portal DataSource +spring.portal-datasource.url=jdbc:h2:mem:~/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE +#spring.portal-datasource.username= +#spring.portal-datasource.password= +spring.sql.portal-init.schema-locations=@@repository@@/profiles/@@platform@@@@suffix@@/apolloportaldb.sql +spring.sql.portal-init.mode=embedded + +# Resolve Multi DataSource JMX name conflict +spring.jmx.unique-names=true + +# H2 datasource +spring.jpa.hibernate.ddl-auto=none +spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl +spring.jpa.properties.hibernate.show_sql=false +spring.jpa.properties.hibernate.metadata_builder_contributor=com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor +spring.h2.console.enabled=true +spring.h2.console.settings.web-allow-others=true + +# Sql logging +#logging.level.org.hibernate.SQL=DEBUG + +# Default env +apollo.portal.envs=local + +# Spring session +spring.session.store-type=none diff --git a/apollo-assembly/src/main/resources/logback.xml b/apollo-assembly/src/main/resources/logback.xml index 4f414e65d95..e724e3c8f46 100644 --- a/apollo-assembly/src/main/resources/logback.xml +++ b/apollo-assembly/src/main/resources/logback.xml @@ -16,6 +16,10 @@ ~ --> + + diff --git a/apollo-assembly/src/test/resources/application.properties b/apollo-assembly/src/test/resources/application.properties index 45dc7de7262..56c1e7ae868 100644 --- a/apollo-assembly/src/test/resources/application.properties +++ b/apollo-assembly/src/test/resources/application.properties @@ -13,10 +13,29 @@ # See the License for the specific language governing permissions and # limitations under the License. # -spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1 +# Config DataSource +spring.config-datasource.url=jdbc:h2:mem:~/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE +#spring.config-datasource.username= +#spring.config-datasource.password= +spring.sql.config-init.schema-locations=@@repository@@/profiles/@@platform@@@@suffix@@/apolloconfigdb.sql +spring.sql.config-init.mode=embedded +# Portal DataSource +spring.portal-datasource.url=jdbc:h2:mem:~/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE +#spring.portal-datasource.username= +#spring.portal-datasource.password= +spring.sql.portal-init.schema-locations=@@repository@@/profiles/@@platform@@@@suffix@@/apolloportaldb.sql +spring.sql.portal-init.mode=embedded + +# Resolve Multi DataSource JMX name conflict +spring.jmx.unique-names=true + +# H2 datasource +spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.jpa.properties.hibernate.show_sql=false spring.jpa.properties.hibernate.metadata_builder_contributor=com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor -spring.h2.console.enabled = true +spring.h2.console.enabled=true spring.h2.console.settings.web-allow-others=true -apollo.portal.env= local + +# Default env +apollo.portal.envs=local diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/ApolloBizAssemblyConfiguration.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/ApolloBizAssemblyConfiguration.java new file mode 100644 index 00000000000..7b3fdf88e1d --- /dev/null +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/ApolloBizAssemblyConfiguration.java @@ -0,0 +1,36 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.biz; + +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; + +@Profile("assembly") +@Configuration +public class ApolloBizAssemblyConfiguration { + + @Primary + @ConfigurationProperties(prefix = "spring.config-datasource") + @Bean + public static DataSourceProperties dataSourceProperties() { + return new DataSourceProperties(); + } +} diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java index 714a3417962..e77be0d05d4 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java @@ -66,7 +66,7 @@ public BizDBPropertySource(final ServerConfigRepository serverConfigRepository, @PostConstruct public void runSqlScript() throws Exception { - if (env.acceptsProfiles(Profiles.of("h2"))) { + if (env.acceptsProfiles(Profiles.of("h2")) && !env.acceptsProfiles(Profiles.of("assembly"))) { Resource resource = new ClassPathResource("jpa/configdb.init.h2.sql"); if (resource.exists()) { DatabasePopulatorUtils.execute(new ResourceDatabasePopulator(resource), dataSource); diff --git a/apollo-build-sql-converter/pom.xml b/apollo-build-sql-converter/pom.xml new file mode 100644 index 00000000000..82d91068ec2 --- /dev/null +++ b/apollo-build-sql-converter/pom.xml @@ -0,0 +1,80 @@ + + + + + com.ctrip.framework.apollo + apollo + ${revision} + ../pom.xml + + 4.0.0 + apollo-build-sql-converter + Apollo Build Sql Converter + + + + org.freemarker + freemarker + + + com.h2database + h2 + test + + + org.springframework.boot + spring-boot-starter-jdbc + test + + + + + + sql-converter + + false + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + + sql-converter + compile + + java + + + + + com.ctrip.framework.apollo.build.sql.converter.ApolloSqlConverter + + + + + + + diff --git a/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloH2ConverterUtil.java b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloH2ConverterUtil.java new file mode 100644 index 00000000000..dd4bbb8b47a --- /dev/null +++ b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloH2ConverterUtil.java @@ -0,0 +1,301 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.List; +import java.util.StringJoiner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ApolloH2ConverterUtil { + + public static void convert(SqlTemplate sqlTemplate, String targetSql, + SqlTemplateContext context) { + + ApolloSqlConverterUtil.ensureDirectories(targetSql); + + String rawText = ApolloSqlConverterUtil.process(sqlTemplate, context); + + List sqlStatements = ApolloSqlConverterUtil.toStatements(rawText); + try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(targetSql), + StandardCharsets.UTF_8, StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING)) { + for (SqlStatement sqlStatement : sqlStatements) { + String convertedText; + try { + convertedText = convertAssemblyH2Line(sqlStatement); + } catch (Throwable e) { + throw new RuntimeException("convert error: " + sqlStatement.getRawText(), e); + } + bufferedWriter.write(convertedText); + bufferedWriter.write('\n'); + } + + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + + private static final Pattern OPERATION_TABLE_PATTERN = Pattern.compile( + "(?DROP|CREATE|ALTER)\\s+TABLE\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?\\s*", + Pattern.CASE_INSENSITIVE); + + private static final Pattern CREATE_INDEX_ON_PATTERN = Pattern.compile( + "CREATE\\s+INDEX\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?\\s+ON\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?", + Pattern.CASE_INSENSITIVE); + + private static String convertAssemblyH2Line(SqlStatement sqlStatement) { + String convertedText = sqlStatement.getRawText(); + + // TABLE `` + Matcher opTableMatcher = OPERATION_TABLE_PATTERN.matcher(convertedText); + if (opTableMatcher.find()) { + String operation = opTableMatcher.group("operation"); + if ("DROP".equalsIgnoreCase(operation)) { + return ""; + } else if ("CREATE".equalsIgnoreCase(operation)) { + return convertCreateTable(convertedText, sqlStatement, opTableMatcher); + } else if ("ALTER".equalsIgnoreCase(operation)) { + return convertAlterTable(convertedText, sqlStatement, opTableMatcher); + } + } + + // CREATE INDEX `` ON `` + Matcher createIndexOnMatcher = CREATE_INDEX_ON_PATTERN.matcher(convertedText); + if (createIndexOnMatcher.find()) { + String createIndexOnTableName = createIndexOnMatcher.group("tableName"); + // index with table + return convertIndexOnTable(convertedText, createIndexOnTableName, sqlStatement); + } + + // others + return convertedText; + } + + private static String convertCreateTable(String convertedText, SqlStatement sqlStatement, + Matcher opTableMatcher) { + String tableName = opTableMatcher.group("tableName"); + // table config + convertedText = convertTableConfig(convertedText, sqlStatement); + // index with table + convertedText = convertIndexWithTable(convertedText, tableName, sqlStatement); + // column + convertedText = convertColumn(convertedText, sqlStatement); + return convertedText; + } + + private static final Pattern ENGINE_PATTERN = Pattern.compile( + "ENGINE\\s*=\\s*InnoDB", Pattern.CASE_INSENSITIVE); + + private static final Pattern DEFAULT_CHARSET_PATTERN = Pattern.compile( + "DEFAULT\\s+CHARSET\\s*=\\s*utf8mb4", Pattern.CASE_INSENSITIVE); + + private static final Pattern ROW_FORMAT_PATTERN = Pattern.compile( + "ROW_FORMAT\\s*=\\s*DYNAMIC", Pattern.CASE_INSENSITIVE); + + private static String convertTableConfig(String convertedText, SqlStatement sqlStatement) { + Matcher engineMatcher = ENGINE_PATTERN.matcher(convertedText); + if (engineMatcher.find()) { + convertedText = engineMatcher.replaceAll(""); + } + Matcher defaultCharsetMatcher = DEFAULT_CHARSET_PATTERN.matcher(convertedText); + if (defaultCharsetMatcher.find()) { + convertedText = defaultCharsetMatcher.replaceAll(""); + } + Matcher rowFormatMatcher = ROW_FORMAT_PATTERN.matcher(convertedText); + if (rowFormatMatcher.find()) { + convertedText = rowFormatMatcher.replaceAll(""); + } + return convertedText; + } + + private static final Pattern INDEX_NAME_PATTERN = Pattern.compile( + // KEY `AppId_ClusterName_GroupName` + "(KEY\\s*`|KEY\\s+)(?[a-zA-Z0-9\\-_]+)(`)?\\s*" + // (`AppId`,`ClusterName`(191),`NamespaceName`(191)) + + "\\((?" + + "(`)?[a-zA-Z0-9\\-_]+(`)?\\s*(\\([0-9]+\\))?" + + "(," + + "(`)?[a-zA-Z0-9\\-_]+(`)?\\s*(\\([0-9]+\\))?" + + ")*" + + ")\\)", + Pattern.CASE_INSENSITIVE); + + private static String convertIndexWithTable(String convertedText, String tableName, + SqlStatement sqlStatement) { + String[] lines = convertedText.split("\n"); + StringJoiner joiner = new StringJoiner("\n"); + for (String line : lines) { + String convertedLine = line; + if (convertedLine.contains("KEY") || convertedLine.contains("key")) { + // replace index name + // KEY `AppId_ClusterName_GroupName` (`AppId`,`ClusterName`(191),`NamespaceName`(191)) + // -> + // KEY `tableName_AppId_ClusterName_GroupName` (`AppId`,`ClusterName`(191),`NamespaceName`(191)) + Matcher indexNameMatcher = INDEX_NAME_PATTERN.matcher(convertedLine); + if (indexNameMatcher.find()) { + convertedLine = indexNameMatcher.replaceAll( + "KEY `" + tableName + "_${indexName}` (${indexColumns})"); + } + convertedLine = removePrefixIndex(convertedLine); + } + joiner.add(convertedLine); + } + return joiner.toString(); + } + + private static String convertColumn(String convertedText, SqlStatement sqlStatement) { + // convert bit(1) to boolean + // `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal' + // -> + // `IsDeleted` boolean NOT NULL DEFAULT FALSE + if (convertedText.contains("bit(1)")) { + convertedText = convertedText.replace("bit(1)", "boolean"); + } + if (convertedText.contains("b'0'")) { + convertedText = convertedText.replace("b'0'", "FALSE"); + } + if (convertedText.contains("b'1'")) { + convertedText = convertedText.replace("b'1'", "TRUE"); + } + + return convertedText; + } + + private static String convertAlterTable(String convertedText, SqlStatement sqlStatement, + Matcher opTableMatcher) { + String tableName = opTableMatcher.group("tableName"); + // remove first table name + convertedText = opTableMatcher.replaceAll(""); + convertedText = convertAlterTableMulti(convertedText, sqlStatement, tableName); + + return convertedText; + } + + private static final Pattern ADD_COLUMN_PATTERN = Pattern.compile( + "\\s*ADD\\s+COLUMN\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?(?.*)[,;]", + Pattern.CASE_INSENSITIVE); + private static final Pattern MODIFY_COLUMN_PATTERN = Pattern.compile( + "\\s*MODIFY\\s+COLUMN\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?(?.*)[,;]", + Pattern.CASE_INSENSITIVE); + private static final Pattern CHANGE_PATTERN = Pattern.compile( + "\\s*CHANGE\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?(?.*)[,;]", + Pattern.CASE_INSENSITIVE); + private static final Pattern DROP_COLUMN_PATTERN = Pattern.compile( + "\\s*DROP\\s+(COLUMN\\s+)?(`)?(?[a-zA-Z0-9\\-_]+)(`)?\\s*[,;]", + Pattern.CASE_INSENSITIVE); + private static final Pattern ADD_KEY_PATTERN = Pattern.compile( + "\\s*ADD\\s+(?(UNIQUE\\s+)?KEY)\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?(?.*)[,;]", + Pattern.CASE_INSENSITIVE); + private static final Pattern ADD_INDEX_PATTERN = Pattern.compile( + "\\s*ADD\\s+(?(UNIQUE\\s+)?INDEX)\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?(?.*)[,;]", + Pattern.CASE_INSENSITIVE); + private static final Pattern DROP_INDEX_PATTERN = Pattern.compile( + "\\s*DROP\\s+INDEX\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?\\s*[,;]", + Pattern.CASE_INSENSITIVE); + + private static String convertAlterTableMulti(String convertedText, SqlStatement sqlStatement, + String tableName) { + Matcher addColumnMatcher = ADD_COLUMN_PATTERN.matcher(convertedText); + if (addColumnMatcher.find()) { + convertedText = addColumnMatcher.replaceAll( + "\nALTER TABLE `" + tableName + "` ADD COLUMN `${columnName}`${subStatement};"); + } + Matcher modifyColumnMatcher = MODIFY_COLUMN_PATTERN.matcher(convertedText); + if (modifyColumnMatcher.find()) { + convertedText = modifyColumnMatcher.replaceAll( + "\nALTER TABLE `" + tableName + "` MODIFY COLUMN `${columnName}`${subStatement};"); + } + Matcher changeMatcher = CHANGE_PATTERN.matcher(convertedText); + if (changeMatcher.find()) { + convertedText = changeMatcher.replaceAll("\nALTER TABLE `" + tableName + + "` CHANGE `${oldColumnName}` `${newColumnName}` ${subStatement};"); + } + + Matcher dropColumnMatcher = DROP_COLUMN_PATTERN.matcher(convertedText); + if (dropColumnMatcher.find()) { + convertedText = dropColumnMatcher.replaceAll( + "\nALTER TABLE `" + tableName + "` DROP `${columnName}`;"); + } + Matcher addKeyMatcher = ADD_KEY_PATTERN.matcher(convertedText); + if (addKeyMatcher.find()) { + convertedText = addKeyMatcher.replaceAll( + "\nALTER TABLE `" + tableName + "` ADD ${indexType} `" + tableName + + "_${indexName}` ${subStatement};"); + convertedText = removePrefixIndex(convertedText); + } + Matcher addIndexMatcher = ADD_INDEX_PATTERN.matcher(convertedText); + if (addIndexMatcher.find()) { + convertedText = addIndexMatcher.replaceAll( + "\nALTER TABLE `" + tableName + "` ADD ${indexType} `" + tableName + + "_${indexName}` ${subStatement};"); + convertedText = removePrefixIndex(convertedText); + } + Matcher dropIndexMatcher = DROP_INDEX_PATTERN.matcher(convertedText); + if (dropIndexMatcher.find()) { + convertedText = dropIndexMatcher.replaceAll( + "\nALTER TABLE `" + tableName + "` DROP INDEX `" + tableName + "_${indexName}`;"); + } + return convertedText; + } + + private static final Pattern CREATE_INDEX_PATTERN = Pattern.compile( + "CREATE\\s+(?(UNIQUE\\s+)?INDEX)\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?", + Pattern.CASE_INSENSITIVE); + + private static String convertIndexOnTable(String convertedText, String tableName, + SqlStatement sqlStatement) { + Matcher createIndexMatcher = CREATE_INDEX_PATTERN.matcher(convertedText); + if (createIndexMatcher.find()) { + convertedText = createIndexMatcher.replaceAll( + "CREATE ${indexType} `" + tableName + "_${indexName}`"); + convertedText = removePrefixIndex(convertedText); + } + return convertedText; + } + + private static final Pattern PREFIX_INDEX_PATTERN = Pattern.compile( + "(?\\(" + // other columns + + "((`)?[a-zA-Z0-9\\-_]+(`)?\\s*(\\([0-9]+\\))?,)*)" + // ``(191) + + "(`)?(?[a-zA-Z0-9\\-_]+)(`)?\\s*\\([0-9]+\\)" + // other columns + + "(?(,(`)?[a-zA-Z0-9\\-_]+(`)?\\s*(\\([0-9]+\\))?)*" + + "\\))"); + + private static String removePrefixIndex(String convertedText) { + // convert prefix index + // (`AppId`,`ClusterName`(191),`NamespaceName`(191)) + // -> + // (`AppId`,`ClusterName`,`NamespaceName`) + for (Matcher prefixIndexMatcher = PREFIX_INDEX_PATTERN.matcher(convertedText); + prefixIndexMatcher.find(); + prefixIndexMatcher = PREFIX_INDEX_PATTERN.matcher(convertedText)) { + convertedText = prefixIndexMatcher.replaceAll("${prefix}`${columnName}`${suffix}"); + } + return convertedText; + } +} diff --git a/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloMysqlDefaultConverterUtil.java b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloMysqlDefaultConverterUtil.java new file mode 100644 index 00000000000..3450cd016bb --- /dev/null +++ b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloMysqlDefaultConverterUtil.java @@ -0,0 +1,69 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.StringReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.List; + +public class ApolloMysqlDefaultConverterUtil { + + public static void convert(SqlTemplate sqlTemplate, String targetSql, + SqlTemplateContext context) { + String databaseName; + String srcSql = sqlTemplate.getSrcPath(); + if (srcSql.contains("apolloconfigdb")) { + databaseName = "ApolloConfigDB"; + } else if (srcSql.contains("apolloportaldb")) { + databaseName = "ApolloPortalDB"; + } else { + throw new IllegalArgumentException("unknown database name: " + srcSql); + } + + ApolloSqlConverterUtil.ensureDirectories(targetSql); + + String rawText = ApolloSqlConverterUtil.process(sqlTemplate, context); + + List sqlStatements = ApolloSqlConverterUtil.toStatements(rawText); + try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(targetSql), + StandardCharsets.UTF_8, StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING)) { + for (SqlStatement sqlStatement : sqlStatements) { + String convertedText = convertMainMysqlLine(sqlStatement, databaseName); + bufferedWriter.write(convertedText); + bufferedWriter.write('\n'); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static String convertMainMysqlLine(SqlStatement sqlStatement, String databaseName) { + String convertedText = sqlStatement.getRawText(); + + convertedText = convertedText.replace("ApolloAssemblyDB", databaseName); + + return convertedText; + } +} diff --git a/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverter.java b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverter.java new file mode 100644 index 00000000000..fac0e5a5d14 --- /dev/null +++ b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverter.java @@ -0,0 +1,134 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +import freemarker.template.Configuration; +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.util.List; + +public class ApolloSqlConverter { + + public static void main(String[] args) { + String repositoryDir = ApolloSqlConverterUtil.getRepositoryDir(); + String srcDir = repositoryDir + "/scripts/sql/src"; + String targetParentDir = repositoryDir + "/scripts"; + + SqlTemplateGist gists = ApolloSqlConverterUtil.getGists(repositoryDir); + + convert(repositoryDir, srcDir, targetParentDir, gists); + } + + public static List convert(String repositoryDir, String srcDir, String targetParentDir, + SqlTemplateGist gists) { + + Configuration configuration = createConfiguration(srcDir); + + // 'scripts/sql/src/apolloconfigdb.sql' + // 'scripts/sql/src/apolloportaldb.sql' + // 'scripts/sql/src/delta/**/*.sql' + List srcSqlList = ApolloSqlConverterUtil.getSqlList(srcDir); + List templateList = ApolloSqlConverterUtil.toTemplates(srcSqlList, srcDir, + configuration); + + // 'scripts/sql/src' -> 'scripts/sql/profiles/mysql-default' + convertMysqlDefaultList(templateList, srcDir, targetParentDir, gists); + + // 'scripts/sql/src' -> 'scripts/sql/profiles/mysql-database-not-specified' + convertMysqlDatabaseNotSpecifiedList(templateList, srcDir, targetParentDir, gists); + + // 'scripts/sql/src' -> 'scripts/sql/profiles/h2-default' + convertH2DefaultList(templateList, srcDir, targetParentDir, gists); + + return srcSqlList; + } + + private static Configuration createConfiguration(String srcDir) { + Configuration configuration = new Configuration(Configuration.VERSION_2_3_32); + try { + configuration.setDirectoryForTemplateLoading(new File(srcDir)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + configuration.setDefaultEncoding(StandardCharsets.UTF_8.name()); + return configuration; + } + + private static void convertMysqlDefaultList(List templateList, + String srcDir, String targetParentDir, SqlTemplateGist gists) { + String targetDir = targetParentDir + "/sql/profiles/mysql-default"; + + SqlTemplateGist mainMysqlGists = SqlTemplateGist.builder() + .autoGeneratedDeclaration(gists.getAutoGeneratedDeclaration()) + .h2Function("") + .setupDatabase(gists.getSetupDatabase()) + .useDatabase(gists.getUseDatabase()) + .build(); + SqlTemplateContext context = SqlTemplateContext.builder() + .gists(mainMysqlGists) + .build(); + + for (SqlTemplate sqlTemplate : templateList) { + String targetSql = ApolloSqlConverterUtil.replacePath(sqlTemplate.getSrcPath(), srcDir, + targetDir); + ApolloMysqlDefaultConverterUtil.convert(sqlTemplate, targetSql, context); + } + } + + private static void convertMysqlDatabaseNotSpecifiedList(List templateList, + String srcDir, + String targetParentDir, SqlTemplateGist gists) { + String targetDir = targetParentDir + "/sql/profiles/mysql-database-not-specified"; + + SqlTemplateGist mainMysqlGists = SqlTemplateGist.builder() + .autoGeneratedDeclaration(gists.getAutoGeneratedDeclaration()) + .h2Function("") + .setupDatabase("") + .useDatabase("") + .build(); + SqlTemplateContext context = SqlTemplateContext.builder() + .gists(mainMysqlGists) + .build(); + for (SqlTemplate sqlTemplate : templateList) { + String targetSql = ApolloSqlConverterUtil.replacePath(sqlTemplate.getSrcPath(), srcDir, + targetDir); + ApolloMysqlDefaultConverterUtil.convert(sqlTemplate, targetSql, context); + } + } + + private static void convertH2DefaultList(List templateList, String srcDir, + String targetParentDir, SqlTemplateGist gists) { + String targetDir = targetParentDir + "/sql/profiles/h2-default"; + + SqlTemplateGist mainMysqlGists = SqlTemplateGist.builder() + .autoGeneratedDeclaration(gists.getAutoGeneratedDeclaration()) + .h2Function(gists.getH2Function()) + .setupDatabase("") + .useDatabase("") + .build(); + SqlTemplateContext context = SqlTemplateContext.builder() + .gists(mainMysqlGists) + .build(); + for (SqlTemplate sqlTemplate : templateList) { + String targetSql = ApolloSqlConverterUtil.replacePath(sqlTemplate.getSrcPath(), srcDir, + targetDir); + ApolloH2ConverterUtil.convert(sqlTemplate, targetSql, context); + } + } +} diff --git a/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverterUtil.java b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverterUtil.java new file mode 100644 index 00000000000..af49f64655e --- /dev/null +++ b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverterUtil.java @@ -0,0 +1,412 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +import freemarker.template.Configuration; +import freemarker.template.Template; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.UncheckedIOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.CodeSource; +import java.security.ProtectionDomain; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Set; +import java.util.StringJoiner; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.regex.Pattern; + +public class ApolloSqlConverterUtil { + + private static final Pattern BASE_PATTERN = Pattern.compile( + "(apolloconfigdb|apolloportaldb)-v[0-9]{3,}-v[0-9]{3,}-base.sql"); + + private static final Pattern BEFORE_PATTERN = Pattern.compile( + "(apolloconfigdb|apolloportaldb)-v[0-9]{3,}-v[0-9]{3,}-before.sql"); + + private static final Pattern DELTA_PATTERN = Pattern.compile( + "(apolloconfigdb|apolloportaldb)-v[0-9]{3,}-v[0-9]{3,}.sql"); + + private static final Pattern AFTER_PATTERN = Pattern.compile( + "(apolloconfigdb|apolloportaldb)-v[0-9]{3,}-v[0-9]{3,}-after.sql"); + + public static String getRepositoryDir() { + ProtectionDomain protectionDomain = ApolloSqlConverter.class.getProtectionDomain(); + CodeSource codeSource = protectionDomain.getCodeSource(); + URL location = codeSource.getLocation(); + URI uri; + try { + uri = location.toURI(); + } catch (URISyntaxException e) { + throw new IllegalArgumentException(e.getLocalizedMessage(), e); + } + Path path = Paths.get(uri); + String unixClassPath = path.toString().replace("\\", "/"); + + if (!unixClassPath.endsWith("/apollo-build-sql-converter/target/classes")) { + throw new IllegalStateException("illegal class path: " + unixClassPath); + } + + return ApolloSqlConverterUtil.replacePath(unixClassPath, + "/apollo-build-sql-converter/target/classes", ""); + } + + public static void ensureDirectories(String targetFilePath) { + Path path = Paths.get(targetFilePath); + Path dirPath = path.getParent(); + try { + Files.createDirectories(dirPath); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + public static String process(SqlTemplate sqlTemplate, SqlTemplateContext context) { + Template freemarkerTemplate = sqlTemplate.getTemplate(); + StringWriter writer = new StringWriter(); + try { + freemarkerTemplate.process(context, writer); + } catch (Exception e) { + throw new RuntimeException(e); + } + return writer.toString(); + } + + public static String replacePrefix(String origin, String prefix, String target) { + if (!origin.startsWith(prefix)) { + throw new IllegalArgumentException("illegal file path: " + origin); + } + return origin.replace(prefix, target); + } + + public static String replacePath(String origin, String src, String target) { + if (!origin.contains(src)) { + throw new IllegalArgumentException("illegal file path: " + origin); + } + return origin.replace(src, target); + } + + public static SqlTemplateGist getGists(String repositoryDir) { + String gistDir = repositoryDir + "/scripts/sql/src/gist"; + String autoGeneratedDeclaration = getGist(gistDir + "/autoGeneratedDeclaration.sql"); + String h2Function = getGist(gistDir + "/h2Function.sql"); + String setupDatabase = getGist(gistDir + "/setupDatabase.sql"); + String useDatabase = getGist(gistDir + "/useDatabase.sql"); + return SqlTemplateGist.builder() + .autoGeneratedDeclaration(autoGeneratedDeclaration) + .h2Function(h2Function) + .setupDatabase(setupDatabase) + .useDatabase(useDatabase) + .build(); + } + + private static String getGist(String gistPath) { + StringJoiner joiner = new StringJoiner("\n", "\n", ""); + boolean accept = false; + try (BufferedReader bufferedReader = Files.newBufferedReader(Paths.get(gistPath), + StandardCharsets.UTF_8)) { + for (String line = bufferedReader.readLine(); line != null; + line = bufferedReader.readLine()) { + if (line.contains("@@gist-start@@")) { + accept = true; + continue; + } + if (line.contains("@@gist-end@@")) { + break; + } + if (accept) { + joiner.add(line); + } + } + } catch (IOException e) { + throw new UncheckedIOException("failed to open gistPath " + e.getLocalizedMessage(), e); + } + return joiner.toString(); + } + + public static List getSqlList(String dir, Set ignoreDirs) { + List sqlList = new ArrayList<>(); + if (Files.exists(Paths.get(dir + "/apolloconfigdb.sql"))) { + sqlList.add(dir + "/apolloconfigdb.sql"); + } + if (Files.exists(Paths.get(dir + "/apolloportaldb.sql"))) { + sqlList.add(dir + "/apolloportaldb.sql"); + } + List deltaSqlList = getDeltaSqlList(dir, ignoreDirs); + sqlList.addAll(deltaSqlList); + return sqlList; + } + + public static List getSqlList(String dir) { + return getSqlList(dir, Collections.emptySet()); + } + + public static List list(Path dir) { + List subPathList = new ArrayList<>(); + try (DirectoryStream ds = Files.newDirectoryStream(dir)) { + for (Path path : ds) { + subPathList.add(path); + } + } catch (IOException e) { + throw new UncheckedIOException("failed to open dir " + e.getLocalizedMessage(), e); + } + return subPathList; + } + + public static List listSorted(Path dir, Comparator comparator) { + List subPathList = list(dir); + List sortedSubPathList = new ArrayList<>(subPathList); + sortedSubPathList.sort(comparator); + return sortedSubPathList; + } + + public static List listSorted(Path dir) { + return listSorted(dir, Comparator.comparing(Path::toString)); + } + + public static void deleteDir(Path dir) { + try { + ApolloSqlConverterUtil.deleteDirInternal(dir); + } catch (IOException e) { + throw new UncheckedIOException("failed to delete dir " + e.getLocalizedMessage(), e); + } + } + + private static void deleteDirInternal(Path dir) throws IOException { + if (!Files.exists(dir)) { + return; + } + List files = ApolloSqlConverterUtil.list(dir); + for (Path file : files) { + if (!Files.exists(file)) { + continue; + } + if (Files.isDirectory(file)) { + ApolloSqlConverterUtil.deleteDirInternal(file); + Files.delete(file); + } else { + Files.delete(file); + } + } + } + + public static Comparator deltaSqlComparator() { + return Comparator.comparing(path -> { + String unixPath = path.replace("\\", "/"); + int lastIndex = unixPath.lastIndexOf("/"); + String fileName; + if (lastIndex > 0) { + fileName = unixPath.substring(lastIndex + 1); + } else { + fileName = unixPath; + } + if (!fileName.endsWith(".sql")) { + // not sql file + return path; + } + // sort: base < before < delta < after + if (BASE_PATTERN.matcher(fileName).matches()) { + return "00" + path; + } else if (BEFORE_PATTERN.matcher(fileName).matches()) { + return "30" + path; + } else if (DELTA_PATTERN.matcher(fileName).matches()) { + return "50" + path; + } else if (AFTER_PATTERN.matcher(fileName).matches()) { + return "90" + path; + } else { + throw new IllegalArgumentException("illegal file name: " + fileName); + } + }); + } + + private static List getDeltaSqlList(String dir, Set ignoreDirs) { + Path dirPath = Paths.get(dir + "/delta"); + if (!Files.exists(dirPath)) { + return Collections.emptyList(); + } + List deltaDirList = listSorted(dirPath); + List allDeltaSqlList = new ArrayList<>(); + for (Path deltaDir : deltaDirList) { + if (!Files.isDirectory(deltaDir)) { + continue; + } + if (ignoreDirs.contains(deltaDir.toString().replace("\\", "/"))) { + continue; + } + List deltaFiles = listSorted(deltaDir, + Comparator.comparing(Path::toString, deltaSqlComparator())); + for (Path path : deltaFiles) { + String fileName = path.toString(); + if (fileName.endsWith(".sql")) { + allDeltaSqlList.add(fileName.replace("\\", "/")); + } + } + } + + return allDeltaSqlList; + } + + + public static List toTemplates(List srcSqlList, String srcDir, + Configuration configuration) { + List templateList = new ArrayList<>(srcSqlList.size()); + for (String srcSql : srcSqlList) { + String templateName = ApolloSqlConverterUtil.replacePrefix(srcSql, srcDir + "/", ""); + Template template; + try { + template = configuration.getTemplate(templateName); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + templateList.add(new SqlTemplate(srcSql, template)); + } + return templateList; + } + + public static List toStatements(String rawText) { + List sqlStatementList = new ArrayList<>(); + try (BufferedReader bufferedReader = new BufferedReader(new StringReader(rawText))) { + AtomicReferencerawTextJoinerRef = new AtomicReference<>(new StringJoiner("\n")); + StringBuilder singleLineTextBuilder = new StringBuilder(); + List textLines = new ArrayList<>(); + AtomicBoolean comment = new AtomicBoolean(false); + for (String line = bufferedReader.readLine(); line != null; + line = bufferedReader.readLine()) { + if (line.startsWith("--")) { + commentLine(line, rawTextJoinerRef, singleLineTextBuilder, textLines, comment, + sqlStatementList); + } else { + noCommentLine(line, rawTextJoinerRef, singleLineTextBuilder, textLines, comment, + sqlStatementList); + } + } + if (!textLines.isEmpty()) { + StringJoiner sqlStatementRawTextJoiner = rawTextJoinerRef.get(); + SqlStatement sqlStatement = createStatement( + sqlStatementRawTextJoiner, singleLineTextBuilder, textLines); + sqlStatementList.add(sqlStatement); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + return sqlStatementList; + } + + private static void commentLine(String line,AtomicReference rawTextJoinerRef, + StringBuilder singleLineTextBuilder, List textLines, AtomicBoolean comment, + List sqlStatementList) { + + if (!comment.get()) { + comment.set(true); + if (!textLines.isEmpty()) { + StringJoiner sqlStatementRawTextJoiner = rawTextJoinerRef.get(); + SqlStatement sqlStatement = createStatement( + sqlStatementRawTextJoiner, singleLineTextBuilder, textLines); + + resetStatementBuffer(rawTextJoinerRef, singleLineTextBuilder, + textLines); + sqlStatementList.add(sqlStatement); + } + } + StringJoiner sqlStatementRawTextJoiner = rawTextJoinerRef.get(); + // raw text + sqlStatementRawTextJoiner.add(line); + // single line text + singleLineTextBuilder.append(line); + // text lines + textLines.add(line); + } + + private static void noCommentLine(String line, AtomicReferencerawTextJoinerRef , + StringBuilder singleLineTextBuilder, List textLines, + AtomicBoolean comment, List sqlStatementList) { + + if (comment.get()) { + comment.set(false); + if (!textLines.isEmpty()) { + StringJoiner sqlStatementRawTextJoiner = rawTextJoinerRef.get(); + SqlStatement sqlStatement = createStatement( + sqlStatementRawTextJoiner, singleLineTextBuilder, textLines); + + resetStatementBuffer(rawTextJoinerRef, singleLineTextBuilder, + textLines); + sqlStatementList.add(sqlStatement); + } + } + + StringJoiner sqlStatementRawTextJoiner = rawTextJoinerRef.get(); + // ; is the end of a statement + int indexOfSemicolon = line.indexOf(';'); + if (indexOfSemicolon == -1) { + // raw text + sqlStatementRawTextJoiner.add(line); + // single line text + singleLineTextBuilder.append(line); + // text lines + textLines.add(line); + } else { + String lineBeforeSemicolon = line.substring(0, indexOfSemicolon + 1); + // raw text + sqlStatementRawTextJoiner.add(lineBeforeSemicolon); + // single line text + singleLineTextBuilder.append(lineBeforeSemicolon); + // text lines + textLines.add(lineBeforeSemicolon); + + SqlStatement sqlStatement = createStatement( + sqlStatementRawTextJoiner, singleLineTextBuilder, textLines); + + resetStatementBuffer(rawTextJoinerRef, singleLineTextBuilder, + textLines); + + sqlStatementList.add(sqlStatement); + } + } + + private static SqlStatement createStatement(StringJoiner sqlStatementRawTextJoiner, + StringBuilder singleLineTextBuilder, List textLines) { + return SqlStatement.builder() + .rawText(sqlStatementRawTextJoiner.toString()) + .singleLineText(singleLineTextBuilder.toString()) + .textLines(new ArrayList<>(textLines)) + .build(); + } + + private static void resetStatementBuffer( + AtomicReference rawTextJoinerRef, + StringBuilder singleLineTextBuilder, List textLines) { + // raw text + rawTextJoinerRef.set(new StringJoiner("\n")); + // single line text + singleLineTextBuilder.setLength(0); + // text lines + textLines.clear(); + } +} diff --git a/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlStatement.java b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlStatement.java new file mode 100644 index 00000000000..d6f40da1915 --- /dev/null +++ b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlStatement.java @@ -0,0 +1,99 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +import java.util.Collections; +import java.util.List; +import java.util.StringJoiner; + +public class SqlStatement { + + private final String rawText; + + private final String singleLineText; + + private final List textLines; + + SqlStatement(Builder builder) { + this.rawText = builder.rawText; + this.singleLineText = builder.singleLineText; + this.textLines = builder.textLines; + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + Builder builder = new Builder(); + builder.rawText = this.rawText; + builder.singleLineText = this.singleLineText; + builder.textLines = this.textLines; + return builder; + } + + public String getRawText() { + return this.rawText; + } + + public String getSingleLineText() { + return this.singleLineText; + } + + public List getTextLines() { + return this.textLines; + } + + @Override + public String toString() { + return new StringJoiner(", ", SqlStatement.class.getSimpleName() + "[", "]") + // fields + .add("rawText='" + this.rawText + "'") + .toString(); + } + + public static final class Builder { + + private String rawText; + private String singleLineText; + private List textLines; + + Builder() { + } + + public Builder rawText(String rawText) { + this.rawText = rawText; + return this; + } + + public Builder singleLineText(String singleLineText) { + this.singleLineText = singleLineText; + return this; + } + + public Builder textLines(List textLines) { + this.textLines = textLines == null ? null : + // nonnull + (textLines.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(textLines)); + return this; + } + + public SqlStatement build() { + return new SqlStatement(this); + } + } +} diff --git a/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlTemplate.java b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlTemplate.java new file mode 100644 index 00000000000..bb1682ef3f4 --- /dev/null +++ b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlTemplate.java @@ -0,0 +1,39 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +import freemarker.template.Template; + +public class SqlTemplate { + + private final String srcPath; + + private final Template template; + + public SqlTemplate(String srcPath, Template template) { + this.srcPath = srcPath; + this.template = template; + } + + public String getSrcPath() { + return this.srcPath; + } + + public Template getTemplate() { + return this.template; + } +} diff --git a/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlTemplateContext.java b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlTemplateContext.java new file mode 100644 index 00000000000..5b0713c8caa --- /dev/null +++ b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlTemplateContext.java @@ -0,0 +1,70 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +import java.util.StringJoiner; + +public class SqlTemplateContext { + + /** + * sql gist + */ + private final SqlTemplateGist gists; + + SqlTemplateContext(Builder builder) { + this.gists = builder.gists; + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + Builder builder = new Builder(); + builder.gists = this.gists; + return builder; + } + + public SqlTemplateGist getGists() { + return this.gists; + } + + @Override + public String toString() { + return new StringJoiner(", ", SqlTemplateContext.class.getSimpleName() + "[", "]") + // fields + .add("gists=" + this.gists) + .toString(); + } + + public static final class Builder { + + private SqlTemplateGist gists; + + Builder() { + } + + public Builder gists(SqlTemplateGist gists) { + this.gists = gists; + return this; + } + + public SqlTemplateContext build() { + return new SqlTemplateContext(this); + } + } +} diff --git a/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlTemplateGist.java b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlTemplateGist.java new file mode 100644 index 00000000000..f9d0d5f4bf8 --- /dev/null +++ b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/SqlTemplateGist.java @@ -0,0 +1,112 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +import java.util.StringJoiner; + +public class SqlTemplateGist { + + private final String autoGeneratedDeclaration; + + private final String h2Function; + + private final String setupDatabase; + + private final String useDatabase; + + SqlTemplateGist(Builder builder) { + this.autoGeneratedDeclaration = builder.autoGeneratedDeclaration; + this.h2Function = builder.h2Function; + this.setupDatabase = builder.setupDatabase; + this.useDatabase = builder.useDatabase; + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + Builder builder = new Builder(); + builder.autoGeneratedDeclaration = this.autoGeneratedDeclaration; + builder.h2Function = this.h2Function; + builder.setupDatabase = this.setupDatabase; + builder.useDatabase = this.useDatabase; + return builder; + } + + public String getAutoGeneratedDeclaration() { + return this.autoGeneratedDeclaration; + } + + public String getH2Function() { + return this.h2Function; + } + + public String getSetupDatabase() { + return this.setupDatabase; + } + + public String getUseDatabase() { + return this.useDatabase; + } + + @Override + public String toString() { + return new StringJoiner(", ", SqlTemplateGist.class.getSimpleName() + "[", "]") + // fields + .add("autoGeneratedDeclaration='" + this.autoGeneratedDeclaration + "'") + .add("h2Function='" + this.h2Function + "'") + .add("setupDatabase='" + this.setupDatabase + "'") + .add("useDatabase='" + this.useDatabase + "'") + .toString(); + } + + public static final class Builder { + + private String autoGeneratedDeclaration; + private String h2Function; + private String setupDatabase; + private String useDatabase; + + Builder() { + } + + public Builder autoGeneratedDeclaration(String autoGeneratedDeclaration) { + this.autoGeneratedDeclaration = autoGeneratedDeclaration; + return this; + } + + public Builder h2Function(String h2Function) { + this.h2Function = h2Function; + return this; + } + + public Builder setupDatabase(String setupDatabase) { + this.setupDatabase = setupDatabase; + return this; + } + + public Builder useDatabase(String useDatabase) { + this.useDatabase = useDatabase; + return this; + } + + public SqlTemplateGist build() { + return new SqlTemplateGist(this); + } + } +} diff --git a/apollo-build-sql-converter/src/test/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverterAutoGeneratedTest.java b/apollo-build-sql-converter/src/test/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverterAutoGeneratedTest.java new file mode 100644 index 00000000000..d43454504ca --- /dev/null +++ b/apollo-build-sql-converter/src/test/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverterAutoGeneratedTest.java @@ -0,0 +1,219 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class ApolloSqlConverterAutoGeneratedTest { + + private static final String GENERATE_TIPS = "mvn compile -pl apollo-build-sql-converter -Psql-converter"; + + /** + * Check sql files in 'scripts/sql/profiles' are auto generated. + */ + @Test + void checkAutoGenerated() { + String repositoryDir = ApolloSqlConverterUtil.getRepositoryDir(); + + String srcDir = repositoryDir + "/scripts/sql/src"; + String checkerParentDir = repositoryDir + "/apollo-build-sql-converter/target/scripts/sql/checker-auto-generated"; + String repositoryParentDir = repositoryDir + "/scripts"; + + // generate checker sql files + ApolloSqlConverterUtil.deleteDir(Paths.get(checkerParentDir)); + SqlTemplateGist gists = ApolloSqlConverterUtil.getGists(repositoryDir); + List srcSqlList = ApolloSqlConverter.convert(repositoryDir, srcDir, checkerParentDir, + gists); + + // compare checker sql files with repository sql files + this.checkSqlList(srcSqlList, srcDir, checkerParentDir, repositoryParentDir); + } + + private void checkSqlList(List srcSqlList, String srcDir, String checkerParentDir, + String repositoryParentDir) { + + // 'scripts/sql/profiles/mysql-default' + this.checkMysqlDefaultList(srcSqlList, srcDir, checkerParentDir, repositoryParentDir); + + // 'scripts/sql/profiles/mysql-database-not-specified' + this.checkMysqlDatabaseNotSpecifiedList(srcSqlList, srcDir, checkerParentDir, + repositoryParentDir); + + // '/scripts/sql/profiles/h2-default' + this.checkH2DefaultList(srcSqlList, srcDir, checkerParentDir, repositoryParentDir); + } + + private void checkMysqlDefaultList(List srcSqlList, String srcDir, + String checkerParentDir, String repositoryParentDir) { + String checkerTargetDir = checkerParentDir + "/sql/profiles/mysql-default"; + String repositoryTargetDir = repositoryParentDir + "/sql/profiles/mysql-default"; + + List checkerSqlList = ApolloSqlConverterUtil.getSqlList(checkerTargetDir); + + Set ignoreDirs = this.getIgnoreDirs(repositoryTargetDir); + List repositorySqlList = ApolloSqlConverterUtil.getSqlList(repositoryTargetDir, + ignoreDirs); + + List redundantSqlList = this.findRedundantSqlList(checkerTargetDir, checkerSqlList, + repositoryTargetDir, repositorySqlList); + Assertions.assertEquals(0, redundantSqlList.size(), + "redundant sql files, please add sql files in 'scripts/sql/src' and then run '" + + GENERATE_TIPS + + "' to generated. Do not edit 'scripts/sql/profiles' manually !!!\npath: " + + redundantSqlList); + + List missingSqlList = this.findMissingSqlList(checkerTargetDir, checkerSqlList, + repositoryTargetDir, repositorySqlList); + Assertions.assertEquals(0, missingSqlList.size(), + "missing sql files, please run '" + GENERATE_TIPS + "' to regenerated\npath: " + + missingSqlList); + + for (String srcSql : srcSqlList) { + String checkerTargetSql = ApolloSqlConverterUtil.replacePath(srcSql, srcDir, + checkerTargetDir); + String repositoryTargetSql = ApolloSqlConverterUtil.replacePath(srcSql, srcDir, + repositoryTargetDir); + + this.doCheck(checkerTargetSql, repositoryTargetSql); + } + } + + private Set getIgnoreDirs(String repositoryTargetDir) { + Set ignoreDirs = new LinkedHashSet<>(); + ignoreDirs.add(repositoryTargetDir + "/delta/v040-v050"); + ignoreDirs.add(repositoryTargetDir + "/delta/v060-v062"); + ignoreDirs.add(repositoryTargetDir + "/delta/v080-v090"); + ignoreDirs.add(repositoryTargetDir + "/delta/v151-v160"); + ignoreDirs.add(repositoryTargetDir + "/delta/v170-v180"); + ignoreDirs.add(repositoryTargetDir + "/delta/v180-v190"); + ignoreDirs.add(repositoryTargetDir + "/delta/v190-v200"); + ignoreDirs.add(repositoryTargetDir + "/delta/v200-v210"); + ignoreDirs.add(repositoryTargetDir + "/delta/v210-v220"); + return ignoreDirs; + } + + private List findRedundantSqlList(String checkerTargetDir, List checkerSqlList, + String repositoryTargetDir, List repositorySqlList) { + // repository - checker + Map missingSqlMap = this.findMissing( + repositoryTargetDir, repositorySqlList, checkerTargetDir, checkerSqlList); + return new ArrayList<>(missingSqlMap.keySet()); + } + + private List findMissingSqlList(String checkerTargetDir, List checkerSqlList, + String repositoryTargetDir, List repositorySqlList) { + // checker - repository + Map missingSqlMap = this.findMissing(checkerTargetDir, checkerSqlList, + repositoryTargetDir, repositorySqlList); + return new ArrayList<>(missingSqlMap.values()); + } + + private Map findMissing(String sourceDir, List sourceSqlList, + String targetDir, List targetSqlList) { + Map missingSqlList = new LinkedHashMap<>(); + Set targetSqlSet = new LinkedHashSet<>(targetSqlList); + for (String sourceSql : sourceSqlList) { + String targetSql = ApolloSqlConverterUtil.replacePath(sourceSql, sourceDir, targetDir); + if (!targetSqlSet.contains(targetSql)) { + missingSqlList.put(sourceSql, targetSql); + } + } + return missingSqlList; + } + + private void doCheck(String checkerTargetSql, String repositoryTargetSql) { + List checkerLines = new ArrayList<>(); + try (BufferedReader bufferedReader = Files.newBufferedReader(Paths.get(checkerTargetSql), + StandardCharsets.UTF_8)) { + for (String line = bufferedReader.readLine(); line != null; + line = bufferedReader.readLine()) { + checkerLines.add(line); + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + + List repositoryLines = new ArrayList<>(); + try (BufferedReader bufferedReader = Files.newBufferedReader(Paths.get(repositoryTargetSql), + StandardCharsets.UTF_8)) { + for (String line = bufferedReader.readLine(); line != null; + line = bufferedReader.readLine()) { + repositoryLines.add(line); + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + + for (int i = 0; i < checkerLines.size(); i++) { + String checkerLine = checkerLines.get(i); + int lineNumber = i + 1; + if (i >= repositoryLines.size()) { + Assertions.fail("invalid sql file content, please run '" + GENERATE_TIPS + + "' to regenerated\npath: " + repositoryTargetSql + "(line: " + lineNumber + ")"); + } + String repositoryLine = repositoryLines.get(i); + Assertions.assertEquals(checkerLine, repositoryLine, + "invalid sql file content, please run '" + GENERATE_TIPS + "' to regenerated\npath: " + + repositoryTargetSql + "(line: " + lineNumber + ")"); + } + Assertions.assertEquals(checkerLines.size(), repositoryLines.size(), + "invalid sql file content, please run '" + GENERATE_TIPS + "' to regenerated\npath: " + + repositoryTargetSql+ "(line: " + checkerLines.size() + ")"); + } + + private void checkMysqlDatabaseNotSpecifiedList(List srcSqlList, String srcDir, + String checkerParentDir, String repositoryParentDir) { + String checkerTargetDir = checkerParentDir + "/sql/profiles/mysql-database-not-specified"; + String repositoryTargetDir = repositoryParentDir + "/sql/profiles/mysql-database-not-specified"; + for (String srcSql : srcSqlList) { + String checkerTargetSql = ApolloSqlConverterUtil.replacePath(srcSql, srcDir, + checkerTargetDir); + String repositoryTargetSql = ApolloSqlConverterUtil.replacePath(srcSql, srcDir, + repositoryTargetDir); + + this.doCheck(checkerTargetSql, repositoryTargetSql); + } + } + + private void checkH2DefaultList(List srcSqlList, String srcDir, + String checkerParentDir, String repositoryParentDir) { + String checkerTargetDir = checkerParentDir + "/sql/profiles/h2-default"; + String repositoryTargetDir = repositoryParentDir + "/sql/profiles/h2-default"; + for (String srcSql : srcSqlList) { + String checkerTargetSql = ApolloSqlConverterUtil.replacePath(srcSql, srcDir, + checkerTargetDir); + String repositoryTargetSql = ApolloSqlConverterUtil.replacePath(srcSql, srcDir, + repositoryTargetDir); + + this.doCheck(checkerTargetSql, repositoryTargetSql); + } + } + +} \ No newline at end of file diff --git a/apollo-build-sql-converter/src/test/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverterH2Test.java b/apollo-build-sql-converter/src/test/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverterH2Test.java new file mode 100644 index 00000000000..85276a0f4f0 --- /dev/null +++ b/apollo-build-sql-converter/src/test/java/com/ctrip/framework/apollo/build/sql/converter/ApolloSqlConverterH2Test.java @@ -0,0 +1,164 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.core.io.PathResource; +import org.springframework.jdbc.datasource.SimpleDriverDataSource; +import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; + +class ApolloSqlConverterH2Test { + + @Test + void checkH2() { + String repositoryDir = ApolloSqlConverterUtil.getRepositoryDir(); + + String srcDir = repositoryDir + "/scripts/sql/src"; + String checkerParentDir = + repositoryDir + "/apollo-build-sql-converter/target/scripts/sql/checker-h2"; + + String testSrcDir = + repositoryDir + "/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test"; + String testCheckerParentDir = + repositoryDir + "/apollo-build-sql-converter/target/scripts/sql/checker-h2-test"; + + // generate checker sql files + ApolloSqlConverterUtil.deleteDir(Paths.get(checkerParentDir)); + SqlTemplateGist gists = ApolloSqlConverterUtil.getGists(repositoryDir); + SqlTemplateGist h2TestGist = gists.toBuilder() + .h2Function("\n" + + "\n" + + "-- H2 Function\n" + + "-- ------------------------------------------------------------\n" + + "CREATE ALIAS IF NOT EXISTS UNIX_TIMESTAMP FOR \"com.ctrip.framework.apollo.build.sql.converter.TestH2Function.unixTimestamp\";\n") + .build(); + List srcSqlList = ApolloSqlConverter.convert(repositoryDir, srcDir, checkerParentDir, + h2TestGist); + List checkerSqlList = new ArrayList<>(srcSqlList.size()); + for (String srcSql : srcSqlList) { + String checkerSql = ApolloSqlConverterUtil.replacePath(srcSql, srcDir, + checkerParentDir + "/sql/profiles/h2-default"); + checkerSqlList.add(checkerSql); + } + + // generate test checker sql files + ApolloSqlConverterUtil.deleteDir(Paths.get(testCheckerParentDir)); + List testSrcSqlList = ApolloSqlConverter.convert(repositoryDir, testSrcDir, + testCheckerParentDir, h2TestGist); + List testCheckerSqlList = new ArrayList<>(testSrcSqlList.size()); + for (String testSrcSql : testSrcSqlList) { + String testCheckerSql = ApolloSqlConverterUtil.replacePath(testSrcSql, testSrcDir, + testCheckerParentDir + "/sql/profiles/h2-default"); + testCheckerSqlList.add(testCheckerSql); + } + + this.checkSort(testSrcSqlList); + + String h2Path = "test-h2"; + this.checkConfigDatabase(h2Path, checkerSqlList, testCheckerSqlList); + + this.checkPortalDatabase(h2Path, checkerSqlList, testCheckerSqlList); + + } + + private void checkSort(List testSrcSqlList) { + int baseIndex = this.getIndex(testSrcSqlList, "apolloconfigdb-v000-v010-base.sql"); + Assertions.assertTrue(baseIndex >= 0); + int beforeIndex = this.getIndex(testSrcSqlList, "apolloconfigdb-v000-v010-before.sql"); + Assertions.assertTrue(beforeIndex >= 0); + int deltaIndex = this.getIndex(testSrcSqlList, "apolloconfigdb-v000-v010.sql"); + Assertions.assertTrue(deltaIndex >= 0); + int afterIndex = this.getIndex(testSrcSqlList, "apolloconfigdb-v000-v010-after.sql"); + Assertions.assertTrue(afterIndex >= 0); + + // base < before < delta < after + Assertions.assertTrue(baseIndex < beforeIndex); + Assertions.assertTrue(beforeIndex < deltaIndex); + Assertions.assertTrue(deltaIndex < afterIndex); + } + + private int getIndex(List srcSqlList, String fileName) { + for (int i = 0; i < srcSqlList.size(); i++) { + String sqlFile = srcSqlList.get(i); + if (sqlFile.endsWith(fileName)) { + return i; + } + } + return -1; + } + + private void checkConfigDatabase(String h2Path, List checkerSqlList, + List testCheckerSqlList) { + SimpleDriverDataSource configDataSource = new SimpleDriverDataSource(); + configDataSource.setUrl("jdbc:h2:mem:~/" + h2Path + + "/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE"); + configDataSource.setDriverClass(org.h2.Driver.class); + + ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); + populator.setContinueOnError(false); + populator.setSeparator(";"); + populator.setSqlScriptEncoding(StandardCharsets.UTF_8.name()); + + for (String sqlFile : testCheckerSqlList) { + if (sqlFile.contains("apolloconfigdb-")) { + populator.addScript(new PathResource(Paths.get(sqlFile))); + } + } + + for (String sqlFile : checkerSqlList) { + if (sqlFile.contains("apolloconfigdb-")) { + populator.addScript(new PathResource(Paths.get(sqlFile))); + } + } + + DatabasePopulatorUtils.execute(populator, configDataSource); + } + + private void checkPortalDatabase(String h2Path, List checkerSqlList, + List testCheckerSqlList) { + SimpleDriverDataSource portalDataSource = new SimpleDriverDataSource(); + portalDataSource.setUrl("jdbc:h2:mem:~/" + h2Path + + "/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE"); + portalDataSource.setDriverClass(org.h2.Driver.class); + + ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); + populator.setContinueOnError(false); + populator.setSeparator(";"); + populator.setSqlScriptEncoding(StandardCharsets.UTF_8.name()); + + for (String sqlFile : testCheckerSqlList) { + if (sqlFile.contains("apolloportaldb-")) { + populator.addScript(new PathResource(Paths.get(sqlFile))); + } + } + + for (String sqlFile : checkerSqlList) { + if (sqlFile.contains("apolloportaldb-")) { + populator.addScript(new PathResource(Paths.get(sqlFile))); + } + } + + DatabasePopulatorUtils.execute(populator, portalDataSource); + } + +} \ No newline at end of file diff --git a/apollo-build-sql-converter/src/test/java/com/ctrip/framework/apollo/build/sql/converter/TestH2Function.java b/apollo-build-sql-converter/src/test/java/com/ctrip/framework/apollo/build/sql/converter/TestH2Function.java new file mode 100644 index 00000000000..e88984ad0f7 --- /dev/null +++ b/apollo-build-sql-converter/src/test/java/com/ctrip/framework/apollo/build/sql/converter/TestH2Function.java @@ -0,0 +1,24 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.build.sql.converter; + +public class TestH2Function { + + public static long unixTimestamp(java.sql.Timestamp timestamp) { + return timestamp.getTime() / 1000L; + } +} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010-after.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010-after.sql new file mode 100644 index 00000000000..000eaf8db3f --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010-after.sql @@ -0,0 +1,30 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.setupDatabase} + + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010-base.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010-base.sql new file mode 100644 index 00000000000..9448f7851be --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010-base.sql @@ -0,0 +1,414 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.setupDatabase} + +-- Dump of table app +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `App`; + +CREATE TABLE `App` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AppId` (`AppId`(191)), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `Name` (`Name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用表'; + + + +-- Dump of table appnamespace +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AppNamespace`; + +CREATE TABLE `AppNamespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', + `AppId` varchar(32) NOT NULL DEFAULT '' COMMENT 'app id', + `Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', + `IsPublic` bit(1) NOT NULL DEFAULT b'0' COMMENT 'namespace是否为公共', + `Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT '' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `Name_AppId` (`Name`,`AppId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用namespace定义'; + + + +-- Dump of table audit +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Audit`; + +CREATE TABLE `Audit` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `EntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `EntityId` int(10) unsigned DEFAULT NULL COMMENT '记录ID', + `OpName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `Comment` varchar(500) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='日志审计表'; + + + +-- Dump of table cluster +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Cluster`; + +CREATE TABLE `Cluster` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT '集群名字', + `AppId` varchar(32) NOT NULL DEFAULT '' COMMENT 'App id', + `ParentClusterId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父cluster', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT '' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_AppId_Name` (`AppId`,`Name`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='集群'; + + + +-- Dump of table commit +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Commit`; + +CREATE TABLE `Commit` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `ChangeSets` longtext NOT NULL COMMENT '修改变更集', + `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `Comment` varchar(500) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `AppId` (`AppId`(191)), + KEY `ClusterName` (`ClusterName`(191)), + KEY `NamespaceName` (`NamespaceName`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='commit 历史表'; + +-- Dump of table grayreleaserule +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `GrayReleaseRule`; + +CREATE TABLE `GrayReleaseRule` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', + `NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', + `BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'branch name', + `Rules` varchar(16000) DEFAULT '[]' COMMENT '灰度规则', + `ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '灰度对应的release', + `BranchStatus` tinyint(2) DEFAULT '1' COMMENT '灰度分支状态: 0:删除分支,1:正在使用的规则 2:全量发布', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='灰度规则表'; + + +-- Dump of table instance +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Instance`; + +CREATE TABLE `Instance` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `DataCenter` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Data Center Name', + `Ip` varchar(32) NOT NULL DEFAULT '' COMMENT 'instance ip', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `IX_UNIQUE_KEY` (`AppId`,`ClusterName`,`Ip`,`DataCenter`), + KEY `IX_IP` (`Ip`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='使用配置的应用实例'; + + + +-- Dump of table instanceconfig +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `InstanceConfig`; + +CREATE TABLE `InstanceConfig` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `InstanceId` int(11) unsigned DEFAULT NULL COMMENT 'Instance Id', + `ConfigAppId` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config App Id', + `ConfigClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Cluster Name', + `ConfigNamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Namespace Name', + `ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', + `ReleaseDeliveryTime` timestamp NULL DEFAULT NULL COMMENT '配置获取时间', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `IX_UNIQUE_KEY` (`InstanceId`,`ConfigAppId`,`ConfigNamespaceName`), + KEY `IX_ReleaseKey` (`ReleaseKey`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Valid_Namespace` (`ConfigAppId`,`ConfigClusterName`,`ConfigNamespaceName`,`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用实例的配置信息'; + + + +-- Dump of table item +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Item`; + +CREATE TABLE `Item` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', + `Key` varchar(128) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Value` longtext NOT NULL COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `LineNum` int(10) unsigned DEFAULT '0' COMMENT '行号', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_GroupId` (`NamespaceId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置项目'; + + + +-- Dump of table namespace +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Namespace`; + +CREATE TABLE `Namespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AppId_ClusterName_NamespaceName` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191)), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='命名空间'; + + + +-- Dump of table namespacelock +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `NamespaceLock`; + +CREATE TABLE `NamespaceLock` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id', + `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT 'default' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + `IsDeleted` bit(1) DEFAULT b'0' COMMENT '软删除', + PRIMARY KEY (`Id`), + UNIQUE KEY `IX_NamespaceId` (`NamespaceId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='namespace的编辑锁'; + + + +-- Dump of table privilege +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Privilege`; + +CREATE TABLE `Privilege` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Name', + `PrivilType` varchar(50) NOT NULL DEFAULT 'default' COMMENT 'PrivilType', + `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'NamespaceId', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`id`), + KEY `Name_PrivilType_NamespaceId` (`Name`(191),`PrivilType`,`NamespaceId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='权限'; + + + +-- Dump of table release +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Release`; + +CREATE TABLE `Release` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', + `Name` varchar(64) NOT NULL DEFAULT 'default' COMMENT '发布名字', + `Comment` varchar(256) DEFAULT NULL COMMENT '发布说明', + `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `Configurations` longtext NOT NULL COMMENT '发布配置', + `IsAbandoned` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否废弃', + `Status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '发布的状态,0:废弃 1:正常 2:灰度', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AppId_ClusterName_GroupName` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191)), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_ReleaseKey` (`ReleaseKey`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布'; + + +-- Dump of table releasehistory +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ReleaseHistory`; + +CREATE TABLE `ReleaseHistory` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT '发布分支名', + `ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关联的Release Id', + `PreviousReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '前一次发布的ReleaseId', + `Operation` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '发布类型,0: 普通发布,1: 回滚,2: 灰度发布,3: 灰度规则更新,4: 灰度合并回主分支发布,5: 主分支发布灰度自动发布,6: 主分支回滚灰度自动发布,7: 放弃灰度', + `OperationContext` longtext NOT NULL COMMENT '发布上下文信息', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`,`BranchName`), + KEY `IX_ReleaseId` (`ReleaseId`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布历史'; + + +-- Dump of table releasemessage +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ReleaseMessage`; + +CREATE TABLE `ReleaseMessage` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Message` varchar(1024) NOT NULL DEFAULT '' COMMENT '发布的消息内容', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Message` (`Message`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布消息'; + + + +-- Dump of table serverconfig +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ServerConfig`; + +CREATE TABLE `ServerConfig` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Cluster` varchar(32) NOT NULL DEFAULT 'default' COMMENT '配置对应的集群,default为不针对特定的集群', + `Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_Key` (`Key`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; + +-- Config +-- ------------------------------------------------------------ +INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`, `Comment`) +VALUES + ('eureka.service.url', 'default', 'http://localhost:8080/eureka/', 'Eureka服务Url'), + ('namespace.lock.switch', 'default', 'false', '一次发布只能有一个人修改开关'), + ('item.value.length.limit', 'default', '20000', 'item value最大长度限制'), + ('appnamespace.private.enable', 'default', 'false', '是否开启private namespace'), + ('item.key.length.limit', 'default', '128', 'item key 最大长度限制'); + +-- ${gists.autoGeneratedDeclaration} + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010-before.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010-before.sql new file mode 100644 index 00000000000..000eaf8db3f --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010-before.sql @@ -0,0 +1,30 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.setupDatabase} + + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010.sql new file mode 100644 index 00000000000..88193c89edf --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloconfigdb-v000-v010.sql @@ -0,0 +1,22 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v0.0.0 to v0.1.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloportaldb-v000-v010-base.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloportaldb-v000-v010-base.sql new file mode 100644 index 00000000000..bc3f0ec2021 --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloportaldb-v000-v010-base.sql @@ -0,0 +1,308 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.setupDatabase} + +-- Dump of table app +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `App`; + +CREATE TABLE `App` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AppId` (`AppId`(191)), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `Name` (`Name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用表'; + + + +-- Dump of table appnamespace +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AppNamespace`; + +CREATE TABLE `AppNamespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', + `AppId` varchar(32) NOT NULL DEFAULT '' COMMENT 'app id', + `Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', + `IsPublic` bit(1) NOT NULL DEFAULT b'0' COMMENT 'namespace是否为公共', + `Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT '' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `Name_AppId` (`Name`,`AppId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用namespace定义'; + + + +-- Dump of table consumer +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Consumer`; + +CREATE TABLE `Consumer` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AppId` (`AppId`(191)), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='开放API消费者'; + + + +-- Dump of table consumeraudit +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ConsumerAudit`; + +CREATE TABLE `ConsumerAudit` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', + `Uri` varchar(1024) NOT NULL DEFAULT '' COMMENT '访问的Uri', + `Method` varchar(16) NOT NULL DEFAULT '' COMMENT '访问的Method', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_ConsumerId` (`ConsumerId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer审计表'; + + + +-- Dump of table consumerrole +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ConsumerRole`; + +CREATE TABLE `ConsumerRole` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) DEFAULT '' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_RoleId` (`RoleId`), + KEY `IX_ConsumerId_RoleId` (`ConsumerId`,`RoleId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer和role的绑定表'; + + + +-- Dump of table consumertoken +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ConsumerToken`; + +CREATE TABLE `ConsumerToken` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'ConsumerId', + `Token` varchar(128) NOT NULL DEFAULT '' COMMENT 'token', + `Expires` datetime NOT NULL DEFAULT '2099-01-01 00:00:00' COMMENT 'token失效时间', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `IX_Token` (`Token`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer token表'; + +-- Dump of table favorite +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Favorite`; + +CREATE TABLE `Favorite` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `UserId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '收藏的用户', + `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Position` int(32) NOT NULL DEFAULT '10000' COMMENT '收藏顺序', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AppId` (`AppId`(191)), + KEY `IX_UserId` (`UserId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COMMENT='应用收藏表'; + +-- Dump of table permission +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Permission`; + +CREATE TABLE `Permission` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `PermissionType` varchar(32) NOT NULL DEFAULT '' COMMENT '权限类型', + `TargetId` varchar(256) NOT NULL DEFAULT '' COMMENT '权限对象类型', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT '' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_TargetId_PermissionType` (`TargetId`(191),`PermissionType`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='permission表'; + + + +-- Dump of table role +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Role`; + +CREATE TABLE `Role` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `RoleName` varchar(256) NOT NULL DEFAULT '' COMMENT 'Role name', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_RoleName` (`RoleName`(191)), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色表'; + + + +-- Dump of table rolepermission +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `RolePermission`; + +CREATE TABLE `RolePermission` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `PermissionId` int(10) unsigned DEFAULT NULL COMMENT 'Permission Id', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) DEFAULT '' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_RoleId` (`RoleId`), + KEY `IX_PermissionId` (`PermissionId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色和权限的绑定表'; + + + +-- Dump of table serverconfig +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ServerConfig`; + +CREATE TABLE `ServerConfig` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_Key` (`Key`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; + + + +-- Dump of table userrole +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `UserRole`; + +CREATE TABLE `UserRole` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `UserId` varchar(128) DEFAULT '' COMMENT '用户身份标识', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) DEFAULT '' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_RoleId` (`RoleId`), + KEY `IX_UserId_RoleId` (`UserId`,`RoleId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户和role的绑定表'; + +-- Config +-- ------------------------------------------------------------ +INSERT INTO `ServerConfig` (`Key`, `Value`, `Comment`) +VALUES + ('apollo.portal.envs', 'dev', '可支持的环境列表'), + ('organizations', '[{\"orgId\":\"TEST1\",\"orgName\":\"样例部门1\"},{\"orgId\":\"TEST2\",\"orgName\":\"样例部门2\"}]', '部门列表'), + ('superAdmin', 'apollo', 'Portal超级管理员'), + ('api.readTimeout', '10000', 'http接口read timeout'), + ('consumer.token.salt', 'someSalt', 'consumer token salt'); + +-- ${gists.autoGeneratedDeclaration} + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloportaldb-v000-v010.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloportaldb-v000-v010.sql new file mode 100644 index 00000000000..df9f7b68deb --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v000-v010/apolloportaldb-v000-v010.sql @@ -0,0 +1,22 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v0.4.0 to v0.5.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v040-v050/apolloconfigdb-v040-v050.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v040-v050/apolloconfigdb-v040-v050.sql new file mode 100644 index 00000000000..ed7992de6f9 --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v040-v050/apolloconfigdb-v040-v050.sql @@ -0,0 +1,30 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v0.4.0 to v0.5.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +DROP TABLE `Privilege`; +ALTER TABLE `Release` DROP `Status`; +ALTER TABLE `Namespace` ADD KEY `IX_NamespaceName` (`NamespaceName`(191)); +ALTER TABLE `Cluster` ADD KEY `IX_ParentClusterId` (`ParentClusterId`); +ALTER TABLE `AppNamespace` ADD KEY `IX_AppId` (`AppId`); +ALTER TABLE `App` DROP INDEX `Name`; +ALTER TABLE `App` ADD KEY `Name` (`Name`); + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v040-v050/apolloportaldb-v040-v050.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v040-v050/apolloportaldb-v040-v050.sql new file mode 100644 index 00000000000..a2a6108bd4d --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v040-v050/apolloportaldb-v040-v050.sql @@ -0,0 +1,26 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v0.4.0 to v0.5.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +ALTER TABLE `AppNamespace` ADD KEY `IX_AppId` (`AppId`); +ALTER TABLE `App` DROP INDEX `Name`; +ALTER TABLE `App` ADD KEY `Name` (`Name`); + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v060-v062/apolloconfigdb-v060-v062.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v060-v062/apolloconfigdb-v060-v062.sql new file mode 100644 index 00000000000..ce5d7ab8b4b --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v060-v062/apolloconfigdb-v060-v062.sql @@ -0,0 +1,25 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v0.6.0 to v0.6.2 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +ALTER TABLE `App` DROP INDEX `Name`; +CREATE INDEX `IX_NAME` ON App (`Name`(191)); + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v060-v062/apolloportaldb-v060-v062.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v060-v062/apolloportaldb-v060-v062.sql new file mode 100644 index 00000000000..5d4a1dc7091 --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v060-v062/apolloportaldb-v060-v062.sql @@ -0,0 +1,25 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v0.6.0 to v0.6.2 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +ALTER TABLE `App` DROP INDEX `Name`; +CREATE INDEX `IX_NAME` ON App (`Name`(191)); + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v080-v090/apolloportaldb-v080-v090.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v080-v090/apolloportaldb-v080-v090.sql new file mode 100644 index 00000000000..15c56f0d085 --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v080-v090/apolloportaldb-v080-v090.sql @@ -0,0 +1,44 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v0.8.0 to v0.9.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +CREATE TABLE `Users` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Username` varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户名', + `Password` varchar(64) NOT NULL DEFAULT 'default' COMMENT '密码', + `Email` varchar(64) NOT NULL DEFAULT 'default' COMMENT '邮箱地址', + `Enabled` tinyint(4) DEFAULT NULL COMMENT '是否有效', + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; + +CREATE TABLE `Authorities` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Username` varchar(50) NOT NULL, + `Authority` varchar(50) NOT NULL, + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO `Users` (`Username`, `Password`, `Email`, `Enabled`) +VALUES + ('apollo', '$2a$10$7r20uS.BQ9uBpf3Baj3uQOZvMVvB1RN3PYoKE94gtz2.WAOuiiwXS', 'apollo@acme.com', 1); + +INSERT INTO `Authorities` (`Username`, `Authority`) VALUES ('apollo', 'ROLE_user'); + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v151-v160/apolloconfigdb-v151-v160.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v151-v160/apolloconfigdb-v151-v160.sql new file mode 100644 index 00000000000..315920637ef --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v151-v160/apolloconfigdb-v151-v160.sql @@ -0,0 +1,37 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v1.5.1 to v1.6.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +CREATE TABLE `AccessKey` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Secret` varchar(128) NOT NULL DEFAULT '' COMMENT 'Secret', + `IsEnabled` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: enabled, 0: disabled', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(32) NOT NULL DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AppId` (`AppId`(191)), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='访问密钥'; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v170-v180/apolloconfigdb-v170-v180.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v170-v180/apolloconfigdb-v170-v180.sql new file mode 100644 index 00000000000..cc085536d50 --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v170-v180/apolloconfigdb-v170-v180.sql @@ -0,0 +1,29 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v1.7.0 to v1.8.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +alter table `AppNamespace` change AppId AppId varchar(64) NOT NULL DEFAULT 'default' COMMENT 'app id'; +alter table `Cluster` change AppId AppId varchar(64) NOT NULL DEFAULT 'default' COMMENT 'app id'; +alter table `GrayReleaseRule` change AppId AppId varchar(64) NOT NULL DEFAULT 'default' COMMENT 'app id'; +alter table `Instance` change AppId AppId varchar(64) NOT NULL DEFAULT 'default' COMMENT 'app id'; +alter table `InstanceConfig` change ConfigAppId ConfigAppId varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Config App Id'; +alter table `ReleaseHistory` change AppId AppId varchar(64) NOT NULL DEFAULT 'default' COMMENT 'app id'; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v170-v180/apolloportaldb-v170-v180.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v170-v180/apolloportaldb-v170-v180.sql new file mode 100644 index 00000000000..ffa769906b3 --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v170-v180/apolloportaldb-v170-v180.sql @@ -0,0 +1,24 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v1.7.0 to v1.8.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +alter table `AppNamespace` change AppId AppId varchar(64) NOT NULL DEFAULT 'default' COMMENT 'app id'; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v180-v190/apolloconfigdb-v180-v190.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v180-v190/apolloconfigdb-v180-v190.sql new file mode 100644 index 00000000000..ec6abbc0220 --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v180-v190/apolloconfigdb-v180-v190.sql @@ -0,0 +1,74 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v1.8.0 to v1.9.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +ALTER TABLE `App` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `AppNamespace` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Audit` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Cluster` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Commit` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `GrayReleaseRule` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Item` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Namespace` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `NamespaceLock` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Release` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `ReleaseHistory` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `ServerConfig` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `AccessKey` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v180-v190/apolloportaldb-v180-v190.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v180-v190/apolloportaldb-v180-v190.sql new file mode 100644 index 00000000000..95dd8a21f9e --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v180-v190/apolloportaldb-v180-v190.sql @@ -0,0 +1,102 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v1.8.0 to v1.9.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +ALTER TABLE `App` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `AppNamespace` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Consumer` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `ConsumerRole` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `ConsumerToken` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Favorite` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Permission` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Role` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `RolePermission` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `ServerConfig` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `UserRole` + MODIFY COLUMN `DataChange_CreatedBy` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + MODIFY COLUMN `DataChange_LastModifiedBy` VARCHAR(64) DEFAULT '' COMMENT '最后修改人邮箱前缀'; + +ALTER TABLE `Users` + MODIFY COLUMN `Username` varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户登录账户', + ADD COLUMN `UserDisplayName` varchar(512) NOT NULL DEFAULT 'default' COMMENT '用户名称' AFTER `Password`; +UPDATE `Users` SET `UserDisplayName`=`Username` WHERE `UserDisplayName` = 'default'; + +ALTER TABLE `Users` + MODIFY COLUMN `Password` varchar(512) NOT NULL DEFAULT 'default' COMMENT '密码'; +UPDATE `Users` SET `Password` = REPLACE(`Password`, '{nonsensical}', '{placeholder}') WHERE `Password` LIKE '{nonsensical}%'; +-- note: add the {bcrypt} prefix for `Users`.`Password` is not mandatory, and it may break the old version of apollo-portal while upgrading. +-- 注意: 向 `Users`.`Password` 添加 {bcrypt} 是非必须操作, 并且这个操作会导致升级 apollo-portal 集群的过程中旧版的 apollo-portal 无法使用. +-- UPDATE `Users` SET `Password` = CONCAT('{bcrypt}', `Password`) WHERE `Password` NOT LIKE '{%}%'; + +-- spring session (https://github.com/spring-projects/spring-session/blob/faee8f1bdb8822a5653a81eba838dddf224d92d6/spring-session-jdbc/src/main/resources/org/springframework/session/jdbc/schema-mysql.sql) +CREATE TABLE SPRING_SESSION ( + PRIMARY_ID CHAR(36) NOT NULL, + SESSION_ID CHAR(36) NOT NULL, + CREATION_TIME BIGINT NOT NULL, + LAST_ACCESS_TIME BIGINT NOT NULL, + MAX_INACTIVE_INTERVAL INT NOT NULL, + EXPIRY_TIME BIGINT NOT NULL, + PRINCIPAL_NAME VARCHAR(100), + CONSTRAINT SPRING_SESSION_PK PRIMARY KEY (PRIMARY_ID) +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; + +CREATE UNIQUE INDEX SPRING_SESSION_IX1 ON SPRING_SESSION (SESSION_ID); +CREATE INDEX SPRING_SESSION_IX2 ON SPRING_SESSION (EXPIRY_TIME); +CREATE INDEX SPRING_SESSION_IX3 ON SPRING_SESSION (PRINCIPAL_NAME); + +CREATE TABLE SPRING_SESSION_ATTRIBUTES ( + SESSION_PRIMARY_ID CHAR(36) NOT NULL, + ATTRIBUTE_NAME VARCHAR(200) NOT NULL, + ATTRIBUTE_BYTES BLOB NOT NULL, + CONSTRAINT SPRING_SESSION_ATTRIBUTES_PK PRIMARY KEY (SESSION_PRIMARY_ID, ATTRIBUTE_NAME), + CONSTRAINT SPRING_SESSION_ATTRIBUTES_FK FOREIGN KEY (SESSION_PRIMARY_ID) REFERENCES SPRING_SESSION(PRIMARY_ID) ON DELETE CASCADE +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloconfigdb-v190-v200-after.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloconfigdb-v190-v200-after.sql new file mode 100644 index 00000000000..9ae64ef85bb --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloconfigdb-v190-v200-after.sql @@ -0,0 +1,88 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v1.9.0 to v2.0.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +-- Begin:Create indexes to solve the problem of updating large tables +ALTER TABLE `Commit` ADD INDEX `idx_IsDeleted_DeletedAt` (`IsDeleted`, `DeletedAt`); +ALTER TABLE `Release` ADD INDEX `idx_IsDeleted_DeletedAt` (`IsDeleted`, `DeletedAt`); + +-- the follow DML won't change the `DataChange_LastTime` field +UPDATE `AccessKey` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `App` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `AppNamespace` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `Audit` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `Cluster` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `Commit` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `GrayReleaseRule` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `Item` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `Namespace` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `NamespaceLock` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `Release` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `ReleaseHistory` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `ServerConfig` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; + +-- add UNIQUE CONSTRAINT INDEX for each table +ALTER TABLE `AccessKey` + ADD UNIQUE INDEX `UK_AppId_Secret_DeletedAt` (`AppId`,`Secret`,`DeletedAt`), + DROP INDEX `AppId`; + +ALTER TABLE `App` + ADD UNIQUE INDEX `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + DROP INDEX `AppId`; + +ALTER TABLE `AppNamespace` + ADD UNIQUE INDEX `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + DROP INDEX `IX_AppId`; + +-- Ignore TABLE `Audit` + +ALTER TABLE `Cluster` + ADD UNIQUE INDEX `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + DROP INDEX `IX_AppId_Name`; + +-- Ignore TABLE `Commit` + +-- Ignore TABLE `GrayReleaseRule`, add unique index in future + +-- Ignore TABLE `Item`, add unique index in future + +ALTER TABLE `Namespace` + ADD UNIQUE INDEX `UK_AppId_ClusterName_NamespaceName_DeletedAt` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191),`DeletedAt`), + DROP INDEX `AppId_ClusterName_NamespaceName`; + +ALTER TABLE `NamespaceLock` + ADD UNIQUE INDEX `UK_NamespaceId_DeletedAt` (`NamespaceId`,`DeletedAt`), + DROP INDEX `IX_NamespaceId`; + +ALTER TABLE `Release` + ADD UNIQUE INDEX `UK_ReleaseKey_DeletedAt` (`ReleaseKey`,`DeletedAt`), + DROP INDEX `IX_ReleaseKey`; + +-- Ignore TABLE `ReleaseHistory` + +ALTER TABLE `ServerConfig` + ADD UNIQUE INDEX `UK_Key_Cluster_DeletedAt` (`Key`,`Cluster`,`DeletedAt`), + DROP INDEX `IX_Key`; + +-- End:Delete temporarily created indexes +ALTER TABLE `Commit` DROP INDEX `idx_IsDeleted_DeletedAt`; +ALTER TABLE `Release` DROP INDEX `idx_IsDeleted_DeletedAt`; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloconfigdb-v190-v200.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloconfigdb-v190-v200.sql new file mode 100644 index 00000000000..323afe7486a --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloconfigdb-v190-v200.sql @@ -0,0 +1,62 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v1.9.0 to v2.0.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +ALTER TABLE `App` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `AppNamespace` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `Audit` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `Cluster` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `Commit` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `GrayReleaseRule` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `Item` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`, + ADD INDEX IX_key (`Key`); + +ALTER TABLE `Namespace` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `NamespaceLock` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `Release` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `ReleaseHistory` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `ServerConfig` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `AccessKey` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloportaldb-v190-v200-after.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloportaldb-v190-v200-after.sql new file mode 100644 index 00000000000..7b05e5e115b --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloportaldb-v190-v200-after.sql @@ -0,0 +1,83 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v1.9.0 to v2.0.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +-- the follow DML won't change the `DataChange_LastTime` field +UPDATE `App` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `AppNamespace` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `Consumer` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `ConsumerRole` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `ConsumerToken` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `Favorite` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `Permission` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `Role` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `RolePermission` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `ServerConfig` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; +UPDATE `UserRole` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0; + +-- add UNIQUE CONSTRAINT INDEX for each table +ALTER TABLE `App` + ADD UNIQUE INDEX `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + DROP INDEX `AppId`; + +ALTER TABLE `AppNamespace` + ADD UNIQUE INDEX `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + DROP INDEX `IX_AppId`; + +ALTER TABLE `Consumer` + ADD UNIQUE INDEX `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + DROP INDEX `AppId`; + +ALTER TABLE `ConsumerRole` + ADD UNIQUE INDEX `UK_ConsumerId_RoleId_DeletedAt` (`ConsumerId`,`RoleId`,`DeletedAt`), + DROP INDEX `IX_ConsumerId_RoleId`; + +ALTER TABLE `ConsumerToken` + ADD UNIQUE INDEX `UK_Token_DeletedAt` (`Token`,`DeletedAt`), + DROP INDEX `IX_Token`; + +ALTER TABLE `Favorite` + ADD UNIQUE INDEX `UK_UserId_AppId_DeletedAt` (`UserId`,`AppId`,`DeletedAt`), + DROP INDEX `IX_UserId`; + +ALTER TABLE `Permission` + ADD UNIQUE INDEX `UK_TargetId_PermissionType_DeletedAt` (`TargetId`,`PermissionType`,`DeletedAt`), + DROP INDEX `IX_TargetId_PermissionType`; + +ALTER TABLE `Role` + ADD UNIQUE INDEX `UK_RoleName_DeletedAt` (`RoleName`,`DeletedAt`), + DROP INDEX `IX_RoleName`; + +ALTER TABLE `RolePermission` + ADD UNIQUE INDEX `UK_RoleId_PermissionId_DeletedAt` (`RoleId`,`PermissionId`,`DeletedAt`), + DROP INDEX `IX_RoleId`; + +ALTER TABLE `ServerConfig` + ADD UNIQUE INDEX `UK_Key_DeletedAt` (`Key`,`DeletedAt`), + DROP INDEX `IX_Key`; + +ALTER TABLE `UserRole` + ADD UNIQUE INDEX `UK_UserId_RoleId_DeletedAt` (`UserId`,`RoleId`,`DeletedAt`), + DROP INDEX `IX_UserId_RoleId`; + +ALTER TABLE `Users` + ADD UNIQUE INDEX `UK_Username` (`Username`); + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloportaldb-v190-v200.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloportaldb-v190-v200.sql new file mode 100644 index 00000000000..d521cf25a53 --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v190-v200/apolloportaldb-v190-v200.sql @@ -0,0 +1,55 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v1.9.0 to v2.0.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +ALTER TABLE `App` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `AppNamespace` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `Consumer` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `ConsumerRole` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `ConsumerToken` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `Favorite` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `Permission` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `Role` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `RolePermission` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `ServerConfig` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +ALTER TABLE `UserRole` + ADD COLUMN `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds' AFTER `IsDeleted`; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v200-v210/apolloconfigdb-v200-v210.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v200-v210/apolloconfigdb-v200-v210.sql new file mode 100644 index 00000000000..47bfa07ce82 --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v200-v210/apolloconfigdb-v200-v210.sql @@ -0,0 +1,41 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v2.0.0 to v2.1.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +-- add INDEX for ReleaseHistory table +CREATE INDEX IX_PreviousReleaseId ON ReleaseHistory(PreviousReleaseId); + +ALTER TABLE `Item` + ADD COLUMN `Type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '配置项类型,0: String,1: Number,2: Boolean,3: JSON' AFTER `Key`; + +CREATE TABLE `ServiceRegistry` ( + `Id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ServiceName` VARCHAR(64) NOT NULL COMMENT '服务名', + `Uri` VARCHAR(64) NOT NULL COMMENT '服务地址', + `Cluster` VARCHAR(64) NOT NULL COMMENT '集群,可以用来标识apollo.cluster或者网络分区', + `Metadata` VARCHAR(1024) NOT NULL DEFAULT '{}' COMMENT '元数据,key value结构的json object,为了方面后面扩展功能而不需要修改表结构', + `DataChange_CreatedTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE INDEX `IX_UNIQUE_KEY` (`ServiceName`, `Uri`), + INDEX `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='注册中心'; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v210-v220/apolloconfigdb-v210-v220.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v210-v220/apolloconfigdb-v210-v220.sql new file mode 100644 index 00000000000..78cc43b4cae --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v210-v220/apolloconfigdb-v210-v220.sql @@ -0,0 +1,97 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v2.1.0 to v2.2.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +ALTER TABLE `App` + MODIFY COLUMN `AppId` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT 'AppID'; + +ALTER TABLE `Commit` + MODIFY COLUMN `AppId` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT 'AppID'; + +ALTER TABLE `Namespace` + MODIFY COLUMN `AppId` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT 'AppID'; + +ALTER TABLE `Release` + MODIFY COLUMN `AppId` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT 'AppID'; + +ALTER TABLE `AccessKey` + MODIFY COLUMN `AppId` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT 'AppID'; + +ALTER TABLE `Commit` + DROP INDEX `AppId`, + ADD INDEX `AppId` (`AppId`); + +ALTER TABLE `Namespace` + DROP INDEX `UK_AppId_ClusterName_NamespaceName_DeletedAt`, + ADD UNIQUE INDEX `UK_AppId_ClusterName_NamespaceName_DeletedAt` (`AppId`,`ClusterName`(191),`NamespaceName`(191),`DeletedAt`); + +ALTER TABLE `Release` + DROP INDEX `AppId_ClusterName_GroupName`, + ADD INDEX `AppId_ClusterName_GroupName` (`AppId`,`ClusterName`(191),`NamespaceName`(191),`DeletedAt`); + +DROP TABLE IF EXISTS `AuditLog`; + +CREATE TABLE `AuditLog` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `TraceId` varchar(32) NOT NULL DEFAULT '' COMMENT '链路全局唯一ID', + `SpanId` varchar(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `ParentSpanId` varchar(32) DEFAULT NULL COMMENT '父跨度ID', + `FollowsFromSpanId` varchar(32) DEFAULT NULL COMMENT '上一个兄弟跨度ID', + `Operator` varchar(64) NOT NULL DEFAULT 'anonymous' COMMENT '操作人', + `OpType` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `OpName` varchar(150) NOT NULL DEFAULT 'default' COMMENT '操作名称', + `Description` varchar(200) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_TraceId` (`TraceId`), + KEY `IX_OpName` (`OpName`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_Operator` (`Operator`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志表'; + + +DROP TABLE IF EXISTS `AuditLogDataInfluence`; + +CREATE TABLE `AuditLogDataInfluence` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `SpanId` char(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `InfluenceEntityId` varchar(50) NOT NULL DEFAULT '0' COMMENT '记录ID', + `InfluenceEntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `FieldName` varchar(50) DEFAULT NULL COMMENT '字段名称', + `FieldOldValue` varchar(500) DEFAULT NULL COMMENT '字段旧值', + `FieldNewValue` varchar(500) DEFAULT NULL COMMENT '字段新值', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_SpanId` (`SpanId`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_EntityId` (`InfluenceEntityId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v210-v220/apolloportaldb-v210-v220.sql b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v210-v220/apolloportaldb-v210-v220.sql new file mode 100644 index 00000000000..0175694efe1 --- /dev/null +++ b/apollo-build-sql-converter/src/test/resources/META-INF/sql/h2-test/delta/v210-v220/apolloportaldb-v210-v220.sql @@ -0,0 +1,83 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v2.1.0 to v2.2.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + +ALTER TABLE `App` + MODIFY COLUMN `AppId` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT 'AppID'; + +ALTER TABLE `Consumer` + MODIFY COLUMN `AppId` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT 'AppID'; + +ALTER TABLE `Favorite` + MODIFY COLUMN `AppId` VARCHAR(64) NOT NULL DEFAULT 'default' COMMENT 'AppID'; + +ALTER TABLE `Favorite` + DROP INDEX `AppId`, + ADD INDEX `AppId` (`AppId`); + +DROP TABLE IF EXISTS `AuditLog`; + +CREATE TABLE `AuditLog` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `TraceId` varchar(32) NOT NULL DEFAULT '' COMMENT '链路全局唯一ID', + `SpanId` varchar(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `ParentSpanId` varchar(32) DEFAULT NULL COMMENT '父跨度ID', + `FollowsFromSpanId` varchar(32) DEFAULT NULL COMMENT '上一个兄弟跨度ID', + `Operator` varchar(64) NOT NULL DEFAULT 'anonymous' COMMENT '操作人', + `OpType` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `OpName` varchar(150) NOT NULL DEFAULT 'default' COMMENT '操作名称', + `Description` varchar(200) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_TraceId` (`TraceId`), + KEY `IX_OpName` (`OpName`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_Operator` (`Operator`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志表'; + + +DROP TABLE IF EXISTS `AuditLogDataInfluence`; + +CREATE TABLE `AuditLogDataInfluence` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `SpanId` char(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `InfluenceEntityId` varchar(50) NOT NULL DEFAULT '0' COMMENT '记录ID', + `InfluenceEntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `FieldName` varchar(50) DEFAULT NULL COMMENT '字段名称', + `FieldOldValue` varchar(500) DEFAULT NULL COMMENT '字段旧值', + `FieldNewValue` varchar(500) DEFAULT NULL COMMENT '字段新值', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_SpanId` (`SpanId`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_EntityId` (`InfluenceEntityId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; + +-- ${gists.autoGeneratedDeclaration} diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/ApolloDataSourceScriptDatabaseInitializer.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/ApolloDataSourceScriptDatabaseInitializer.java new file mode 100644 index 00000000000..e6d3af94857 --- /dev/null +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/ApolloDataSourceScriptDatabaseInitializer.java @@ -0,0 +1,73 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.common.datasource; + +import java.util.List; +import javax.sql.DataSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer; +import org.springframework.boot.sql.init.DatabaseInitializationMode; +import org.springframework.boot.sql.init.DatabaseInitializationSettings; +import org.springframework.jdbc.datasource.AbstractDriverBasedDataSource; +import org.springframework.jdbc.datasource.SimpleDriverDataSource; + +public class ApolloDataSourceScriptDatabaseInitializer extends + DataSourceScriptDatabaseInitializer { + + private static final Logger log = LoggerFactory.getLogger( + ApolloDataSourceScriptDatabaseInitializer.class); + + public ApolloDataSourceScriptDatabaseInitializer(DataSource dataSource, + DatabaseInitializationSettings settings) { + super(dataSource, settings); + if (this.isEnabled(settings)) { + log.info("Apollo DataSource Initialize is enabled"); + if (log.isDebugEnabled()) { + String jdbcUrl = this.getJdbcUrl(dataSource); + log.debug("Initialize jdbc url: {}", jdbcUrl); + List schemaLocations = settings.getSchemaLocations(); + if (!schemaLocations.isEmpty()) { + for (String schemaLocation : schemaLocations) { + log.debug("Initialize Schema Location: {}", schemaLocation); + } + } + } + } else { + log.info("Apollo DataSource Initialize is disabled"); + } + } + + private String getJdbcUrl(DataSource dataSource) { + if (dataSource instanceof AbstractDriverBasedDataSource) { + AbstractDriverBasedDataSource driverBasedDataSource = (AbstractDriverBasedDataSource) dataSource; + return driverBasedDataSource.getUrl(); + } + SimpleDriverDataSource simpleDriverDataSource = DataSourceBuilder.derivedFrom(dataSource) + .type(SimpleDriverDataSource.class) + .build(); + return simpleDriverDataSource.getUrl(); + } + + private boolean isEnabled(DatabaseInitializationSettings settings) { + if (settings.getMode() == DatabaseInitializationMode.NEVER) { + return false; + } + return settings.getMode() == DatabaseInitializationMode.ALWAYS || this.isEmbeddedDatabase(); + } +} diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/ApolloDataSourceScriptDatabaseInitializerFactory.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/ApolloDataSourceScriptDatabaseInitializerFactory.java new file mode 100644 index 00000000000..74106334df7 --- /dev/null +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/ApolloDataSourceScriptDatabaseInitializerFactory.java @@ -0,0 +1,174 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.common.datasource; + +import java.net.URL; +import java.security.CodeSource; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import javax.sql.DataSource; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.boot.jdbc.DatabaseDriver; +import org.springframework.boot.jdbc.init.PlatformPlaceholderDatabaseDriverResolver; +import org.springframework.boot.sql.init.DatabaseInitializationSettings; +import org.springframework.jdbc.datasource.SimpleDriverDataSource; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +public class ApolloDataSourceScriptDatabaseInitializerFactory { + + public static ApolloDataSourceScriptDatabaseInitializer create(DataSource dataSource, + ApolloSqlInitializationProperties properties) { + DataSource determinedDataSource = determineDataSource(dataSource, properties); + DatabaseInitializationSettings settings = getSettings(dataSource, properties); + return new ApolloDataSourceScriptDatabaseInitializer(determinedDataSource, settings); + } + + private static DataSource determineDataSource(DataSource dataSource, + ApolloSqlInitializationProperties properties) { + + String username = properties.getUsername(); + String password = properties.getPassword(); + if (StringUtils.hasText(username) && StringUtils.hasText(password)) { + return DataSourceBuilder.derivedFrom(dataSource) + .username(username) + .password(password) + .type(SimpleDriverDataSource.class) + .build(); + } + return dataSource; + } + + private static DatabaseInitializationSettings getSettings(DataSource dataSource, + ApolloSqlInitializationProperties properties) { + + PlatformPlaceholderDatabaseDriverResolver platformResolver = new PlatformPlaceholderDatabaseDriverResolver().withDriverPlatform( + DatabaseDriver.MARIADB, "mysql"); + + List schemaLocations = resolveLocations(properties.getSchemaLocations(), + platformResolver, + dataSource, properties); + List dataLocations = resolveLocations(properties.getDataLocations(), platformResolver, + dataSource, properties); + + DatabaseInitializationSettings settings = new DatabaseInitializationSettings(); + settings.setSchemaLocations( + scriptLocations(schemaLocations, "schema", properties.getPlatform())); + settings.setDataLocations(scriptLocations(dataLocations, "data", properties.getPlatform())); + settings.setContinueOnError(properties.isContinueOnError()); + settings.setSeparator(properties.getSeparator()); + settings.setEncoding(properties.getEncoding()); + settings.setMode(properties.getMode()); + return settings; + } + + + private static List resolveLocations(Collection locations, + PlatformPlaceholderDatabaseDriverResolver platformResolver, DataSource dataSource, + ApolloSqlInitializationProperties properties) { + + if (CollectionUtils.isEmpty(locations)) { + return null; + } + + Collection convertedLocations = convertRepositoryLocations(locations, dataSource); + if (CollectionUtils.isEmpty(convertedLocations)) { + return null; + } + + String platform = properties.getPlatform(); + if (StringUtils.hasText(platform) && !"all".equals(platform)) { + return platformResolver.resolveAll(platform, convertedLocations.toArray(new String[0])); + } + return platformResolver.resolveAll(dataSource, convertedLocations.toArray(new String[0])); + } + + private static Collection convertRepositoryLocations(Collection locations, + DataSource dataSource) { + if (CollectionUtils.isEmpty(locations)) { + return null; + } + String repositoryDir = findRepositoryDirectory(); + String suffix = findSuffix(dataSource); + List convertedLocations = new ArrayList<>(locations.size()); + for (String location : locations) { + String convertedLocation = convertRepositoryLocation(location, repositoryDir, suffix); + if (StringUtils.hasText(convertedLocation)) { + convertedLocations.add(convertedLocation); + } + } + return convertedLocations; + } + + private static String findSuffix(DataSource dataSource) { + DatabaseDriver databaseDriver = DatabaseDriver.fromDataSource(dataSource); + if (DatabaseDriver.H2.equals(databaseDriver)) { + return "-default"; + } + if (DatabaseDriver.MYSQL.equals(databaseDriver)) { + return "-database-not-specified"; + } + return ""; + } + + private static String findRepositoryDirectory() { + CodeSource codeSource = ApolloDataSourceScriptDatabaseInitializer.class.getProtectionDomain() + .getCodeSource(); + URL location = codeSource != null ? codeSource.getLocation() : null; + if (location == null) { + return null; + } + if ("jar".equals(location.getProtocol())) { + // running with jar + return "classpath:META-INF/sql"; + } + if ("file".equals(location.getProtocol())) { + // running with ide + String locationText = location.toString(); + if (!locationText.endsWith("/apollo-common/target/classes/")) { + throw new IllegalStateException( + "can not determine repository directory from classpath: " + locationText); + } + return locationText.replace("/apollo-common/target/classes/", "/scripts/sql"); + } + return null; + } + + private static String convertRepositoryLocation(String location, String repositoryDir, + String suffix) { + if (!StringUtils.hasText(location)) { + return location; + } + if (!StringUtils.hasText(repositoryDir)) { + // repository dir not found + return null; + } + return location.replace("@@repository@@", repositoryDir).replace("@@suffix@@", suffix); + } + + private static List scriptLocations(List locations, String fallback, + String platform) { + if (locations != null) { + return locations; + } + List fallbackLocations = new ArrayList<>(); + fallbackLocations.add("optional:classpath*:" + fallback + "-" + platform + ".sql"); + fallbackLocations.add("optional:classpath*:" + fallback + ".sql"); + return fallbackLocations; + } +} diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/ApolloSqlInitializationProperties.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/ApolloSqlInitializationProperties.java new file mode 100644 index 00000000000..4ce80f4622b --- /dev/null +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/ApolloSqlInitializationProperties.java @@ -0,0 +1,142 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.common.datasource; + +import java.nio.charset.Charset; +import java.util.List; +import org.springframework.boot.sql.init.DatabaseInitializationMode; + +public class ApolloSqlInitializationProperties { + + /** + * Locations of the schema (DDL) scripts to apply to the database. + */ + private List schemaLocations; + + /** + * Locations of the data (DML) scripts to apply to the database. + */ + private List dataLocations; + + /** + * Platform to use in the default schema or data script locations, schema-${platform}.sql and + * data-${platform}.sql. + */ + private String platform = "all"; + + /** + * Username of the database to use when applying initialization scripts (if different). + */ + private String username; + + /** + * Password of the database to use when applying initialization scripts (if different). + */ + private String password; + + /** + * Whether initialization should continue when an error occurs. + */ + private boolean continueOnError = false; + + /** + * Statement separator in the schema and data scripts. + */ + private String separator = ";"; + + /** + * Encoding of the schema and data scripts. + */ + private Charset encoding; + + /** + * Mode to apply when determining whether initialization should be performed. + */ + private DatabaseInitializationMode mode = DatabaseInitializationMode.EMBEDDED; + + public List getSchemaLocations() { + return this.schemaLocations; + } + + public void setSchemaLocations(List schemaLocations) { + this.schemaLocations = schemaLocations; + } + + public List getDataLocations() { + return this.dataLocations; + } + + public void setDataLocations(List dataLocations) { + this.dataLocations = dataLocations; + } + + public String getPlatform() { + return this.platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public boolean isContinueOnError() { + return this.continueOnError; + } + + public void setContinueOnError(boolean continueOnError) { + this.continueOnError = continueOnError; + } + + public String getSeparator() { + return this.separator; + } + + public void setSeparator(String separator) { + this.separator = separator; + } + + public Charset getEncoding() { + return this.encoding; + } + + public void setEncoding(Charset encoding) { + this.encoding = encoding; + } + + public DatabaseInitializationMode getMode() { + return this.mode; + } + + public void setMode(DatabaseInitializationMode mode) { + this.mode = mode; + } +} diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/ConfigServiceApplication.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/ConfigServiceApplication.java index 2906fb37f3d..f7dcd44855c 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/ConfigServiceApplication.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/ConfigServiceApplication.java @@ -22,6 +22,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; @@ -35,7 +36,9 @@ */ @EnableAspectJAutoProxy -@EnableAutoConfiguration +@EnableAutoConfiguration(exclude = { + UserDetailsServiceAutoConfiguration.class, +}) @Configuration @EnableTransactionManagement @PropertySource(value = {"classpath:configservice.properties"}) diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/ConfigServiceAssemblyConfiguration.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/ConfigServiceAssemblyConfiguration.java new file mode 100644 index 00000000000..3321019eb1b --- /dev/null +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/ConfigServiceAssemblyConfiguration.java @@ -0,0 +1,44 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.configservice; + +import com.ctrip.framework.apollo.common.datasource.ApolloDataSourceScriptDatabaseInitializer; +import com.ctrip.framework.apollo.common.datasource.ApolloDataSourceScriptDatabaseInitializerFactory; +import com.ctrip.framework.apollo.common.datasource.ApolloSqlInitializationProperties; +import javax.sql.DataSource; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +@Profile("assembly") +@Configuration +public class ConfigServiceAssemblyConfiguration { + + @ConfigurationProperties(prefix = "spring.sql.config-init") + @Bean + public static ApolloSqlInitializationProperties apolloSqlInitializationProperties() { + return new ApolloSqlInitializationProperties(); + } + + @Bean + public static ApolloDataSourceScriptDatabaseInitializer apolloDataSourceScriptDatabaseInitializer( + DataSource dataSource, + ApolloSqlInitializationProperties properties) { + return ApolloDataSourceScriptDatabaseInitializerFactory.create(dataSource, properties); + } +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalApplication.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalApplication.java index 15cfb2e3594..9ce5f88f959 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalApplication.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalApplication.java @@ -24,10 +24,12 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.context.annotation.PropertySource; import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableAspectJAutoProxy @Configuration +@PropertySource(value = {"classpath:portal.properties"}) @EnableAutoConfiguration(exclude = {LdapAutoConfiguration.class}) @EnableTransactionManagement @ComponentScan(basePackageClasses = {ApolloCommonConfig.class, diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalAssemblyConfiguration.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalAssemblyConfiguration.java new file mode 100644 index 00000000000..08b9909b09d --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalAssemblyConfiguration.java @@ -0,0 +1,53 @@ +/* + * Copyright 2024 Apollo Authors + * + * 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.ctrip.framework.apollo.portal; + +import com.ctrip.framework.apollo.common.datasource.ApolloDataSourceScriptDatabaseInitializer; +import com.ctrip.framework.apollo.common.datasource.ApolloDataSourceScriptDatabaseInitializerFactory; +import com.ctrip.framework.apollo.common.datasource.ApolloSqlInitializationProperties; +import javax.sql.DataSource; +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; + +@Profile("assembly") +@Configuration +public class PortalAssemblyConfiguration { + + @Primary + @ConfigurationProperties(prefix = "spring.portal-datasource") + @Bean + public static DataSourceProperties dataSourceProperties() { + return new DataSourceProperties(); + } + + @ConfigurationProperties(prefix = "spring.sql.portal-init") + @Bean + public static ApolloSqlInitializationProperties apolloSqlInitializationProperties() { + return new ApolloSqlInitializationProperties(); + } + + @Bean + public static ApolloDataSourceScriptDatabaseInitializer apolloDataSourceScriptDatabaseInitializer( + DataSource dataSource, + ApolloSqlInitializationProperties properties) { + return ApolloDataSourceScriptDatabaseInitializerFactory.create(dataSource, properties); + } +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RetryableRestTemplate.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RetryableRestTemplate.java index bc1d35bc4cf..8125632b803 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RetryableRestTemplate.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RetryableRestTemplate.java @@ -32,6 +32,7 @@ import java.net.SocketTimeoutException; import java.util.List; import java.util.Map; +import java.util.Objects; import javax.annotation.PostConstruct; import org.apache.http.conn.ConnectTimeoutException; import org.apache.http.conn.HttpHostConnectException; @@ -300,7 +301,9 @@ private T doExecute(HttpMethod method, HttpHeaders extraHeaders, ServiceDTO } private String parseHost(ServiceDTO serviceAddress) { - return serviceAddress.getHomepageUrl() + "/"; + String homepageUrl = serviceAddress.getHomepageUrl(); + Objects.requireNonNull(homepageUrl, "homepageUrl"); + return homepageUrl.endsWith("/") ? homepageUrl : homepageUrl + "/"; } //post,delete,put请求在admin server处理超时情况下不重试 diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/PortalDBPropertySource.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/PortalDBPropertySource.java index 603eb38e745..b0779c04284 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/PortalDBPropertySource.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/PortalDBPropertySource.java @@ -62,7 +62,7 @@ public PortalDBPropertySource(final ServerConfigRepository serverConfigRepositor @PostConstruct public void runSqlScript() throws Exception { - if (env.acceptsProfiles(Profiles.of("h2"))) { + if (env.acceptsProfiles(Profiles.of("h2")) && !env.acceptsProfiles(Profiles.of("assembly"))) { Resource resource = new ClassPathResource("jpa/portaldb.init.h2.sql"); if (resource.exists()) { DatabasePopulatorUtils.execute(new ResourceDatabasePopulator(resource), dataSource); diff --git a/apollo-portal/src/main/resources/application.yml b/apollo-portal/src/main/resources/application.yml index 20f126490ac..9a9f17a56b7 100644 --- a/apollo-portal/src/main/resources/application.yml +++ b/apollo-portal/src/main/resources/application.yml @@ -14,8 +14,6 @@ # limitations under the License. # spring: - application: - name: apollo-portal profiles: active: ${apollo_profile} jpa: @@ -33,7 +31,6 @@ spring: max-file-size: 200MB # import data configs max-request-size: 200MB server: - port: 8070 compression: enabled: true tomcat: @@ -44,10 +41,6 @@ server: # prevent csrf same-site: Lax -logging: - file: - name: /opt/logs/apollo-portal.log - management: health: status: diff --git a/apollo-portal/src/main/resources/portal.properties b/apollo-portal/src/main/resources/portal.properties new file mode 100644 index 00000000000..9edd0ee3b16 --- /dev/null +++ b/apollo-portal/src/main/resources/portal.properties @@ -0,0 +1,20 @@ +# +# Copyright 2024 Apollo Authors +# +# 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. +# +#Used for apollo-assembly +spring.application.name= apollo-portal +server.port= 8070 +logging.file.name= /opt/logs/apollo-portal.log +spring.jmx.default-domain = apollo-portal diff --git a/doc/images/local-development/ApolloApplication-Mysql-VM-Options.png b/doc/images/local-development/ApolloApplication-Mysql-VM-Options.png new file mode 100644 index 00000000000..051158ea44b Binary files /dev/null and b/doc/images/local-development/ApolloApplication-Mysql-VM-Options.png differ diff --git a/doc/images/local-development/ApolloApplication-Overview.png b/doc/images/local-development/ApolloApplication-Overview.png new file mode 100644 index 00000000000..7015b164cce Binary files /dev/null and b/doc/images/local-development/ApolloApplication-Overview.png differ diff --git a/doc/images/local-development/ApolloApplication-Run.png b/doc/images/local-development/ApolloApplication-Run.png new file mode 100644 index 00000000000..e32852ac56d Binary files /dev/null and b/doc/images/local-development/ApolloApplication-Run.png differ diff --git a/doc/images/local-development/ApolloApplication-VM-Options.png b/doc/images/local-development/ApolloApplication-VM-Options.png new file mode 100644 index 00000000000..73aba7fed56 Binary files /dev/null and b/doc/images/local-development/ApolloApplication-VM-Options.png differ diff --git a/docs/en/contribution/apollo-development-guide.md b/docs/en/contribution/apollo-development-guide.md index c69b2d1a435..7ecff0111d6 100644 --- a/docs/en/contribution/apollo-development-guide.md +++ b/docs/en/contribution/apollo-development-guide.md @@ -9,7 +9,7 @@ This document describes how to compile and run Apollo locally using the IDE so t Apollo local development requires the following components. 1. Java: 1.8+ -2. MySQL: 5.6.5+ 3. +2. MySQL: 5.6.5+ (If you plan to use H2 in-memory database/H2 file database, then there is no need to prepare MySQL) 3. IDE: No special requirements MySQL is required to create Apollo database and import the base data. @@ -24,13 +24,13 @@ Please refer to [Apollo Configuration Center Design](en/design/apollo-design) fo # II. Local startup -## 2.1 Apollo Config Service and Apollo Admin Service +## 2.1 Apollo Assembly -When we develop locally, we usually start both `apollo-config service` and `apollo-adminservice` in the IDE. +When we develop locally, we usually start `apollo-assembly` in the IDE. -The following is an example of how to start `apollo-configService` and `apollo-adminservice` locally with Intellij Community 2016.2 version. +The following is an example of how to start `apollo-assembly` locally with Intellij Community 2016.2 version. -![ConfigAdminApplication-Overview](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ConfigAdminApplication-Overview.png) +![ApolloApplication-Overview](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ApolloApplication-Overview.png) ### 2.1.1 Create a new running configuration @@ -40,34 +40,50 @@ The following is an example of how to start `apollo-configService` and `apollo-a `com.ctrip.framework.apollo.assembly.ApolloApplication` -> Note: If you want to start `apollo-configservice` and `apollo-adminservice` independently, you can replace Main Class with -> ConfigServiceApplication` and +> Note: If you want to start `apollo-portal`, `apollo-configservice` and `apollo-adminservice` independently, you can replace Main Class with +> `com.ctrip.framework.apollo.portal.PortalApplication` +> `com.ctrip.framework.apollo.configservice.ConfigServiceApplication` > `com.ctrip.framework.apollo.adminservice.AdminServiceApplication` ### 2.1.3 VM options configuration -![ConfigAdminApplication-VM-Options](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ConfigAdminApplication-VM-Options.png) - - -Dapollo_profile=github - -Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8 - -Dspring.datasource.username=root - -Dspring.datasource.password= +![ApolloApplication-VM-Options](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ApolloApplication-VM-Options.png) +``` +-Dapollo_profile=github,auth ->Note 1: replace spring.datasource related configuration with your own database connection information, note that the database is `ApolloConfigDB`. -> ->Note 2: The default log output of the program is /opt/logs/100003171/apollo-assembly.log, if you need to modify the log file path, you can add the `logging.file.name` parameter, as follows. +``` +>Note 1: apollo_profile is specified here as `github` and `auth`, where `github` is a profile required by Apollo for database configuration, and `auth` is added from 0.9.0 to support simple authentication using Spring Security provided by apollo. For more information you can refer to [Portal-implement-user-login-function](en/development/portal-how-to-implement-user-login-function) > ->-Dlogging.file.name=/your-path/apollo-assembly.log +>Note 2: If you plan to use a MySQL database, you need to add `spring.config-datasource.*` related configuration, +> the your-mysql-server:3306 needs to be replaced with the actual mysql server address and port, +> ApolloConfigDB and ApolloPortalDB needs to be replaced with the actual database name, +> apollo-username and apollo-password need to be replaced with the actual username and password + +![ApolloApplication-Mysql-VM-Options](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ApolloApplication-Mysql-VM-Options.png) + +``` +-Dspring.config-datasource.url=jdbc:mysql://your-mysql-server:3306/ApolloConfigDB?useUnicode=true&characterEncoding=UTF8 +-Dspring.config-datasource.username=apollo-username +-Dspring.config-datasource.password=apollo-password -### 2.1.4 Program arguments configuration +-Dspring.portal-datasource.url=jdbc:mysql://your-mysql-server:3306/ApolloPortalDB?useUnicode=true&characterEncoding=UTF8 +-Dspring.portal-datasource.username=apollo-username +-Dspring.portal-datasource.password=apollo-password -`--configservice --adminservice` +``` +The initialization script for the MySQL database can be found in the scripts/sql/profiles/mysql-default directory of this project. +[apolloconfigdb.sql](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/scripts/sql/profiles/mysql-default/apolloconfigdb.sql) +[apolloportaldb.sql](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/scripts/sql/profiles/mysql-default/apolloportaldb.sql) + +>Note 3: The default log output of the program is /opt/logs/100003171/apollo-assembly.log, if you need to modify the log file path, you can add the `logging.file.name` parameter, as follows. +> +>-Dlogging.file.name=/your-path/apollo-assembly.log -### 2.1.5 Run +### 2.1.4 Run Click Run or Debug for the new run configuration. -![ConfigAdminApplication-Run](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ConfigAdminApplication-Run.png) +![ApolloApplication-Run](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ApolloApplication-Run.png) After starting, open [http://localhost:8080](http://localhost:8080) to see that both `apollo-configservice` and `apollo-adminservice` have been started and registered to Eureka. @@ -88,66 +104,23 @@ After starting, open [http://localhost:8080](http://localhost:8080) to see that > ... > } -## 2.2 Apollo-Portal - -The following is an example of how to start `apollo-portal` locally with Intellij Community 2016.2 version. - -![PortalApplication-Overview](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/PortalApplication-Overview.png) - -### 2.2.1 New run configuration - -![NewConfiguration-Application](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/NewConfiguration-Application.png) - -### 2.2.2 Main class configuration - -`com.ctrip.framework.apollo.portal.PortalApplication` - -### 2.2.3 VM options configuration - -![PortalApplication-VM-Options](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/PortalApplication-VM-Options.png) - - -Dapollo_profile=github,auth - -Ddev_meta=http://localhost:8080/ - -Dserver.port=8070 - -Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8 - -Dspring.datasource.username=root - -Dspring.datasource.password= - ->Note 1: apollo_profile is specified here as `github` and `auth`, where `github` is a profile required by Apollo for database configuration, and `auth` is added from 0.9.0 to support simple authentication using Spring Security provided by apollo. For more information you can refer to [Portal-implement-user-login-function](en/extension/portal-how-to-implement-user-login-function) -> ->Note 2: spring.datasource related configuration replaced with your own database connection information, note that the database is `ApolloPortalDB `. -> ->Note 3: The default configuration imported in ApolloPortalDB will only show the configuration of DEV environment, so the dev\_meta property is configured here, if you want to show the configuration of other environment locally, you need to add the meta server address of other environment here, such as fat\_meta. -> ->Note 4: Here server.port=8070 is specified because `apollo-configservice` starts on port 8080, so here `apollo-portal` is configured to start on port 8070. -> ->Note 5: The default log output of the program is /opt/logs/100003173/apollo-portal.log. If you need to modify the log file path, you can add the `logging.file.name` parameter as follows. -> ->-Dlogging.file.name=/your-path/apollo-portal.log - -### 2.2.4 Running - -Click Run or Debug for the newly created run configuration. - -![PortalApplication-Run](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/PortalApplication-Run.png) - After starting, open [http://localhost:8070](http://localhost:8070) to see the Apollo Configuration Center interface. ![PortalApplication-Home](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/PortalApplication-Home.png) >Note: If `auth` profile is enabled, the default username is apollo and password is admin -### 2.2.5 Demo application access +### 2.1.5 Demo application access For better development and debugging, we usually create a demo project for our own use. You can refer to [General Application Access Guide](en/portal/apollo-user-guide?id=i-general-application-access-guide) to create your own demo project. -## 2.3 Java sample client startup +## 2.2 Java sample client startup There is a sample client project: [apollo-demo-java](https://github.com/apolloconfig/apollo-demo-java), the following is an example of how to start it locally with Intellij. -### 2.3.1 Configure the project AppId +### 2.2.1 Configure the project AppId When creating a demo project in `2.2.5 Demo Application Access`, the system will ask to fill in a globally unique AppId, which we need to configure into the app.properties file of the `apollo-demo` project: `apollo-demo-java/api-demo/src/main/resources/ META-INF/app.properties`. @@ -163,15 +136,15 @@ If our own demo project uses an AppId of 100004458, then the file content would > More ways to configure AppId can be found in [1.2.1 AppId](en/client/java-sdk-user-guide?id=_121-appid) -### 2.3.2 New run configuration +### 2.2.2 New run configuration ![NewConfiguration-Application](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/NewConfiguration-Application.png) -### 2.3.3 Main class configuration +### 2.2.3 Main class configuration `com.apolloconfig.apollo.demo.api.SimpleApolloConfigDemo` -### 2.3.4 VM options configuration +### 2.2.4 VM options configuration ![apollo-demo-vm-options](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/apollo-demo-vm-options.jpg) @@ -181,11 +154,11 @@ If our own demo project uses an AppId of 100004458, then the file content would > For more ways to configure Apollo Meta Server, please refer to [1.2.2 Apollo Meta Server](en/client/java-sdk-user-guide?id=_122-apollo-meta-server) -### 2.3.5 Overview +### 2.2.5 Overview ![apollo-demo-overview](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/apollo-demo-overview.jpg) -### 2.3.6 Running +### 2.2.6 Running Click Run or Debug on the newly created run configuration. @@ -208,11 +181,11 @@ Enter the value you have configured on the Portal, such as `timeout` in our demo > > -## 2.4 .Net sample client startup +## 2.3 .Net sample client startup The [apollo.net](https://github.com/ctripcorp/apollo.net) project has a sample client project: `ApolloDemo`, here's an example of how to start it locally with VS 2010. -### 2.4.1 Configuring the project AppId +### 2.3.1 Configuring the project AppId When creating a Demo project in `2.2.5 Demo Application Access`, the system will ask to fill in a globally unique AppId, which we need to configure into the App.config file of the `ApolloDemo` project: `apollo.net\ApolloDemo\App.config`. @@ -228,13 +201,13 @@ If our own demo project uses an AppId of 100004458, then the contents of the fil > For public Namespace configurations, the configuration can be obtained without the AppId, but the ability of the application to override the public Namespace configuration is lost. -### 2.4.2 Configuring Service Addresses +### 2.3.2 Configuring Service Addresses Apollo client will get the configuration from different servers for different environments, so we need to configure the server address (Apollo.{ENV}.Meta) in app.config or web.config. Suppose the DEV environment's configuration service (apollo-config service) address is 11.22.33.44, then we will do the following configuration. ![apollo-net-server-url-config](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/apollo-net-server-url-config.png) -### 2.4.3 Running +### 2.3.3 Running Just run `ApolloConfigDemo.cs`. diff --git a/docs/en/deployment/distributed-deployment-guide.md b/docs/en/deployment/distributed-deployment-guide.md index 2c06ee9ce9a..3251d4c5d5e 100644 --- a/docs/en/deployment/distributed-deployment-guide.md +++ b/docs/en/deployment/distributed-deployment-guide.md @@ -219,12 +219,12 @@ You can choose to create it by manually importing SQL or by automatically import #### 2.1.1.1 Manual SQL Import -You can import [apolloportaldb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/apolloportaldb.sql) through various MySQL clients. +You can import [apolloportaldb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/profiles/mysql-default/apolloportaldb.sql) through various MySQL clients. Using the native MySQL client as an example. ```sql -source /your_local_path/scripts/sql/apolloportaldb.sql +source /your_local_path/scripts/sql/profiles/mysql-default/apolloportaldb.sql ``` #### 2.1.1.2 Created via Flyway import SQL @@ -254,12 +254,12 @@ You can choose to create it by manually importing SQL or automatically importing #### 2.1.2.1 Importing SQL Manually -You can import [apolloconfigdb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/apolloconfigdb.sql) through various MySQL clients. +You can import [apolloconfigdb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/profiles/mysql-default/apolloconfigdb.sql) through various MySQL clients. Using the native MySQL client as an example. ```sql -source /your_local_path/scripts/sql/apolloconfigdb.sql +source /your_local_path/scripts/sql/profiles/mysql-default/apolloconfigdb.sql ``` #### 2.1.2.2 SQL import via Flyway diff --git a/docs/en/deployment/quick-start.md b/docs/en/deployment/quick-start.md index b6277456a47..b4fe384aa8e 100644 --- a/docs/en/deployment/quick-start.md +++ b/docs/en/deployment/quick-start.md @@ -29,7 +29,7 @@ Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode) Windows users please make sure that JAVA_HOME environment variable is set. ## 1.2 MySQL - +* If you plan to use H2 in-memory database/H2 file database, there is no need for MySQL, and you can skip this step. * Version requirement: 5.6.5+ Apollo's table structure uses multiple default declarations for `timestamp`, so version 5.6.5+ is required. @@ -66,103 +66,128 @@ Quick Start is only for local testing, so generally users do not need to downloa 2. Execute `mvn clean package -pl apollo-assembly -am -DskipTests=true` in the root directory. 3. Copy the jar package under apollo-assembly/target and rename it to apollo-all-in-one.jar -# II. Installation steps -## 2.1 Create the database -Apollo server side needs a total of two databases: `ApolloPortalDB` and `ApolloConfigDB`, we have prepared the database, table creation and sample data as sql files respectively, just import the database. - -> Note: If you have already created Apollo database locally, please take care to backup the data. The sql file we prepared will clear the Apollo related tables. - -### 2.1.1 Creating ApolloPortalDB -Just import [sql/apolloportaldb.sql](https://github.com/apolloconfig/apollo-quick-start/blob/master/sql/apolloportaldb.sql) through various MySQL clients. - -The following is an example of a native MySQL client. -```sql -source /your_local_path/sql/apolloportaldb.sql -``` +# II. Initialization and Startup +#### Precautions +1. The Apollo server process needs to use ports 8070, 8080, 8090 respectively, please ensure these three ports are not currently in use. +2. The `github` in the SPRING_PROFILES_ACTIVE environment variable in the script is a required profile, `auth` is a profile that provides simple authentication for the portal, it can be removed if authentication is not required or other authentication methods are used. +## 2.1 Use H2 in-memory database, automatic initialization +No configuration is required, just use the following command to start +> Note: When using the in-memory database, any operation will be lost after the Apollo process restarts +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +unset SPRING_SQL_CONFIG_INIT_MODE +unset SPRING_SQL_PORTAL_INIT_MODE +java -jar apollo-all-in-one.jar -After the successful import, you can verify it by executing the following sql statement. -```sql -select `Id`, `AppId`, `Name` from ApolloPortalDB.App; ``` -| Id | AppId | Name | -| ---- | --------- | ---------- | -| 1 | SampleApp | Sample App | - -### 2.1.2 Creating ApolloConfigDB -You can import [sql/apolloconfigdb.sql](https://github.com/apolloconfig/apollo-quick-start/blob/master/sql/apolloconfigdb.sql) through various MySQL clients. - -The following is an example of a native MySQL client. -```sql -source /your_local_path/sql/apolloconfigdb.sql -``` +## 2.2 Use H2 file database, automatic initialization +#### Precautions +1. The path `~/apollo/apollo-config-db` and `~/apollo/apollo-portal-db` in the environment variable in the script can be replaced with other custom paths, you need to ensure that this path has read and write permissions + +### 2.2.1 First startup +Use the SPRING_SQL_CONFIG_INIT_MODE="always" and SPRING_SQL_PORTAL_INIT_MODE="always" environment variable for initialization at the first startup +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +# config db +export SPRING_SQL_CONFIG_INIT_MODE="always" +export SPRING_CONFIG_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" +# portal db +export SPRING_SQL_PORTAL_INIT_MODE="always" +export SPRING_PORTAL_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" +java -jar apollo-all-in-one.jar -After the successful import, you can verify it by executing the following sql statement. -```sql -select `NamespaceId`, `Key`, `Value`, `Comment` from ApolloConfigDB.Item; ``` -| NamespaceId | Key | Value | Comment | -| ----------- | ------- | ----- | ---------------------------- | -| 1 | timeout | 100 | sample timeout configuration | - -## 2.2 Configuring Database Connection Information -The Apollo server needs to know how to connect to the database you created earlier, so you need to edit [demo.sh](https://github.com/apolloconfig/apollo-quick-start/blob/master/demo.sh) and modify ApolloPortalDB and ApolloConfigDB related database connection string information. -> Note: The filled in user needs to have read and write access to ApolloPortalDB and ApolloConfigDB data. +### 2.2.2 Subsequent startup +Remove the SPRING_SQL_CONFIG_INIT_MODE and SPRING_SQL_PORTAL_INIT_MODE environment variable to avoid repeated initialization at subsequent startup +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +# config db +unset SPRING_SQL_CONFIG_INIT_MODE +export SPRING_CONFIG_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" +# portal db +unset SPRING_SQL_PORTAL_INIT_MODE +export SPRING_PORTAL_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" +java -jar apollo-all-in-one.jar -```sh -#apollo config db info -apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai" -apollo_config_db_username=username -apollo_config_db_password=password (if you don't have a password, just leave it blank) - -# apollo portal db info -apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai" -apollo_portal_db_username=username -apollo_portal_db_password=password (if you don't have a password, just leave it blank) ``` -> Note: Do not modify other parts of demo.sh - -# III. Start Apollo Configuration Center -## 3.1 Make sure the port is not occupied -The Quick Start script will start 3 services locally, using ports 8070, 8080, 8090 respectively, please make sure these 3 ports are not currently used. +## 2.3 Use mysql database, automatic initialization +#### Precautions +1. The your-mysql-server:3306 in the environment variable in the script needs to be replaced with the actual mysql server address and port, ApolloConfigDB and ApolloPortalDB needs to be replaced with the actual database name +2. The "apollo-username" and "apollo-password" in the environment variables in the script need to fill in the actual username and password + +### 2.3.1 First startup +Use the SPRING_SQL_INIT_MODE="always" environment variable for initialization at the first startup +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +# config db +export SPRING_SQL_CONFIG_INIT_MODE="always" +export SPRING_CONFIG_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloConfigDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_CONFIG_DATASOURCE_USERNAME="apollo-username" +export SPRING_CONFIG_DATASOURCE_PASSWORD="apollo-password" +# portal db +export SPRING_SQL_PORTAL_INIT_MODE="always" +export SPRING_PORTAL_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloPortalDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_PORTAL_DATASOURCE_USERNAME="apollo-username" +export SPRING_PORTAL_DATASOURCE_PASSWORD="apollo-password" +java -jar apollo-all-in-one.jar -For example, under Linux/Mac, you can check with the following command. -```sh -lsof -i:8080 ``` -## 3.2 Execute the startup script -```sh -./demo.sh start -``` +### 2.3.2 Subsequent startup +Remove the SPRING_SQL_CONFIG_INIT_MODE and SPRING_SQL_PORTAL_INIT_MODE environment variable to avoid repeated initialization at subsequent startup +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +# config db +unset SPRING_SQL_CONFIG_INIT_MODE +export SPRING_CONFIG_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloConfigDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_CONFIG_DATASOURCE_USERNAME="apollo-username" +export SPRING_CONFIG_DATASOURCE_PASSWORD="apollo-password" +# portal db +unset SPRING_SQL_PORTAL_INIT_MODE +export SPRING_PORTAL_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloPortalDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_PORTAL_DATASOURCE_USERNAME="apollo-username" +export SPRING_PORTAL_DATASOURCE_PASSWORD="apollo-password" +java -jar apollo-all-in-one.jar -When you see the following output, you've started successfully! -```sh -==== starting service ==== -Service logging file is . /service/apollo-service.log -Started [10768] -Waiting for config service startup ....... -Config service started. You may visit http://localhost:8080 for service status now! -Waiting for admin service startup.... -Admin service started -==== starting portal ==== -Portal logging file is . /portal/apollo-portal.log -Started [10846] -Waiting for portal startup ...... -Portal started. You can visit http://localhost:8070 now! -You can visit now! ``` +## 2.4 Use mysql database, manual initialization + +### 2.4.1 Manually initialize ApolloConfigDB and ApolloPortalDB +You can import [apolloconfigdb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/profiles/mysql-default/apolloconfigdb.sql) to ApolloConfigDB through various MySQL clients. +You can import [apolloportaldb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/profiles/mysql-default/apolloportaldb.sql) to ApolloPortalDB through various MySQL clients. + +### 2.4.2 Run +#### Precautions +1. The your-mysql-server:3306 in the environment variable in the script needs to be replaced with the actual mysql server address and port, ApolloConfigDB and ApolloPortalDB needs to be replaced with the actual database name +2. The "apollo-username" and "apollo-password" in the environment variables in the script need to fill in the actual username and password + +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +# config db +unset SPRING_SQL_CONFIG_INIT_MODE +export SPRING_CONFIG_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloConfigDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_CONFIG_DATASOURCE_USERNAME="apollo-username" +export SPRING_CONFIG_DATASOURCE_PASSWORD="apollo-password" +# portal db +unset SPRING_SQL_PORTAL_INIT_MODE +export SPRING_PORTAL_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloPortalDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_PORTAL_DATASOURCE_USERNAME="apollo-username" +export SPRING_PORTAL_DATASOURCE_PASSWORD="apollo-password" +java -jar apollo-all-in-one.jar +``` -## 3.3 Troubleshooting +# III. Additional Startup Instructions +## 3.1 Troubleshooting If you encounter an exception in the startup, you can check the log files in the service and portal directories respectively to troubleshoot the problem. -> Note: During start-up of apollo-configservice, eureka registration failure message will be output in the log, e.g. `com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused`. Note that this is expected because apollo-configservice needs to register the service with Meta Server (itself), but since it is not up yet during the startup process itself, this error is reported. A retry action will be performed later, so it will register properly when the service is up by itself. +> Note: During start-up, eureka registration failure message will be output in the log, e.g. `com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused`. Note that this is expected because apollo-configservice needs to register the service with Meta Server (itself), but since it is not up yet during the startup process itself, this error is reported. A retry action will be performed later, so it will register properly when the service is up by itself. -## 3.4 Note +## 3.2 Note Quick Start is only used to help you quickly experience Apollo project, please refer to: [distributed-deployment-guide](en/deployment/distributed-deployment-guide) for details. diff --git a/docs/en/extension/portal-how-to-implement-user-login-function.md b/docs/en/extension/portal-how-to-implement-user-login-function.md index 80686150e96..13610b4ea9b 100644 --- a/docs/en/extension/portal-how-to-implement-user-login-function.md +++ b/docs/en/extension/portal-how-to-implement-user-login-function.md @@ -10,7 +10,7 @@ Use the following steps. ### 1. Install 0.9.0 or above -> If the previous version is 0.8.0, you need to import [apolloportaldb-v080-v090.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/delta/v080-v090/apolloportaldb-v080-v090.sql) +> If the previous version is 0.8.0, you need to import [apolloportaldb-v080-v090.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/profiles/mysql-default/delta/v080-v090/apolloportaldb-v080-v090.sql) Checking ApolloPortalDB, the `Users` table should already exist and have an initial record. The initial user name is apollo and the password is admin. diff --git a/docs/zh/contribution/apollo-development-guide.md b/docs/zh/contribution/apollo-development-guide.md index 90864e2e4a5..ac6c3c3eb9c 100644 --- a/docs/zh/contribution/apollo-development-guide.md +++ b/docs/zh/contribution/apollo-development-guide.md @@ -6,7 +6,7 @@ Apollo本地开发需要以下组件: 1. Java: 1.8+ -2. MySQL: 5.6.5+ +2. MySQL: 5.6.5+ (如果使用 H2 内存数据库/H2 文件数据库,则无需 MySQL) 3. IDE: 没有特殊要求 其中MySQL需要创建Apollo数据库并导入基础数据。 @@ -19,12 +19,12 @@ Apollo本地开发需要以下组件: 具体请参考[Apollo配置中心设计](zh/design/apollo-design) # 二、本地启动 -## 2.1 Apollo Config Service和Apollo Admin Service -我们在本地开发时,一般会在IDE中同时启动`apollo-configservice`和`apollo-adminservice`。 +## 2.1 Apollo Assembly +我们在本地开发时,一般会在IDE中启动`apollo-assembly`。 -下面以Intellij Community 2016.2版本为例来说明如何在本地启动`apollo-configservice`和`apollo-adminservice`。 +下面以Intellij Community 2016.2版本为例来说明如何在本地启动`apollo-assembly`。 -![ConfigAdminApplication-Overview](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ConfigAdminApplication-Overview.png) +![ApolloApplication-Overview](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ApolloApplication-Overview.png) ### 2.1.1 新建运行配置 ![NewConfiguration-Application](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/NewConfiguration-Application.png) @@ -32,31 +32,48 @@ Apollo本地开发需要以下组件: ### 2.1.2 Main class配置 `com.ctrip.framework.apollo.assembly.ApolloApplication` -> 注:如果希望独立启动`apollo-configservice`和`apollo-adminservice`,可以把Main Class分别换成 -> `com.ctrip.framework.apollo.configservice.ConfigServiceApplication`和 +> 注:如果希望独立启动`apollo-portal`、`apollo-configservice`和`apollo-adminservice`,可以把Main Class分别换成 +> `com.ctrip.framework.apollo.portal.PortalApplication` +> `com.ctrip.framework.apollo.configservice.ConfigServiceApplication` > `com.ctrip.framework.apollo.adminservice.AdminServiceApplication` ### 2.1.3 VM options配置 -![ConfigAdminApplication-VM-Options](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ConfigAdminApplication-VM-Options.png) - - -Dapollo_profile=github - -Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8 - -Dspring.datasource.username=root - -Dspring.datasource.password= +![ApolloApplication-VM-Options](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ApolloApplication-VM-Options.png) +``` +-Dapollo_profile=github,auth ->注1:spring.datasource相关配置替换成你自己的数据库连接信息,注意数据库是`ApolloConfigDB` +``` +>注1:这里指定了apollo_profile是`github`和`auth`,其中`github`是Apollo必须的一个profile,用于数据库的配置,`auth`是从0.9.0新增的,用来支持使用apollo提供的Spring Security简单认证,更多信息可以参考[Portal-实现用户登录功能](zh/development/portal-how-to-implement-user-login-function) > ->注2:程序默认日志输出为/opt/logs/100003171/apollo-assembly.log,如果需要修改日志文件路径,可以增加`logging.file.name`参数,如下: +>注2:如果需要使用 mysql 数据库,添加`spring.config-datasource.*` 和 `spring.portal-datasource.*` 相关配置, +> your-mysql-server:3306 需要替换为实际的 mysql 服务器地址和端口, +> ApolloConfigDB 和 ApolloPortalDB 需要替换为实际的数据库名称, +> apollo-username 和 apollo-password 需要替换为实际的用户名和密码 + +![ApolloApplication-Mysql-VM-Options](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ApolloApplication-Mysql-VM-Options.png) + +``` +-Dspring.config-datasource.url=jdbc:mysql://your-mysql-server:3306/ApolloConfigDB?useUnicode=true&characterEncoding=UTF8 +-Dspring.config-datasource.username=apollo-username +-Dspring.config-datasource.password=apollo-password + +-Dspring.portal-datasource.url=jdbc:mysql://your-mysql-server:3306/ApolloPortalDB?useUnicode=true&characterEncoding=UTF8 +-Dspring.portal-datasource.username=apollo-username +-Dspring.portal-datasource.password=apollo-password + +``` +mysql 数据库初始化脚本见 本项目 scripts/sql/profiles/mysql-default 目录下的文件 +[apolloconfigdb.sql](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/scripts/sql/profiles/mysql-default/apolloconfigdb.sql) +[apolloportaldb.sql](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/scripts/sql/profiles/mysql-default/apolloportaldb.sql) + +>注3:程序默认日志输出为/opt/logs/100003171/apollo-assembly.log,如果需要修改日志文件路径,可以增加`logging.file.name`参数,如下: > >-Dlogging.file.name=/your-path/apollo-assembly.log -### 2.1.4 Program arguments配置 -`--configservice --adminservice` - -### 2.1.5 运行 +### 2.1.4 运行 对新建的运行配置点击Run或Debug皆可。 -![ConfigAdminApplication-Run](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ConfigAdminApplication-Run.png) +![ApolloApplication-Run](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/ApolloApplication-Run.png) 启动完后,打开[http://localhost:8080](http://localhost:8080)可以看到`apollo-configservice`和`apollo-adminservice`都已经启动完成并注册到Eureka。 @@ -77,62 +94,23 @@ Apollo本地开发需要以下组件: > ... > } -## 2.2 Apollo-Portal - -下面以Intellij Community 2016.2版本为例来说明如何在本地启动`apollo-portal`。 - -![PortalApplication-Overview](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/PortalApplication-Overview.png) - -### 2.2.1 新建运行配置 -![NewConfiguration-Application](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/NewConfiguration-Application.png) - -### 2.2.2 Main class配置 -`com.ctrip.framework.apollo.portal.PortalApplication` - -### 2.2.3 VM options配置 -![PortalApplication-VM-Options](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/PortalApplication-VM-Options.png) - - -Dapollo_profile=github,auth - -Ddev_meta=http://localhost:8080/ - -Dserver.port=8070 - -Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8 - -Dspring.datasource.username=root - -Dspring.datasource.password= - ->注1:这里指定了apollo_profile是`github`和`auth`,其中`github`是Apollo必须的一个profile,用于数据库的配置,`auth`是从0.9.0新增的,用来支持使用apollo提供的Spring Security简单认证,更多信息可以参考[Portal-实现用户登录功能](zh/extension/portal-how-to-implement-user-login-function) -> ->注2:spring.datasource相关配置替换成你自己的数据库连接信息,注意数据库是`ApolloPortalDB `。 -> ->注3:默认ApolloPortalDB中导入的配置只会展示DEV环境的配置,所以这里配置了dev\_meta属性,如果你希望在本地展示其它环境的配置,需要在这里增加其它环境的meta服务器地址,如fat\_meta。 -> ->注4:这里指定了server.port=8070是因为`apollo-configservice`启动在8080端口,所以这里配置`apollo-portal`启动在8070端口。 -> ->注5:程序默认日志输出为/opt/logs/100003173/apollo-portal.log,如果需要修改日志文件路径,可以增加`logging.file.name`参数,如下: -> ->-Dlogging.file.name=/your-path/apollo-portal.log - -### 2.2.4 运行 -对新建的运行配置点击Run或Debug皆可。 - -![PortalApplication-Run](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/PortalApplication-Run.png) - 启动完后,打开[http://localhost:8070](http://localhost:8070)就可以看到Apollo配置中心界面了。 ![PortalApplication-Home](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/PortalApplication-Home.png) >注:如果启用了`auth` profile的话,默认的用户名是apollo,密码是admin -### 2.2.5 Demo应用接入 +### 2.1.5 Demo应用接入 为了更好的开发和调试,一般我们都会自己创建一个demo项目给自己使用。 可以参考[一、普通应用接入指南](zh/portal/apollo-user-guide#一、普通应用接入指南)创建自己的demo项目。 -## 2.3 Java样例客户端启动 +## 2.2 Java样例客户端启动 仓库中有一个样例客户端的项目:[apollo-demo-java](https://github.com/apolloconfig/apollo-demo-java),下面以Intellij为例来说明如何在本地启动。 -### 2.3.1 配置项目AppId +### 2.2.1 配置项目AppId 在`2.2.5 Demo应用接入`中创建Demo项目时,系统会要求填入一个全局唯一的AppId,我们需要把这个AppId配置到`apollo-demo`项目的app.properties文件中:`apollo-demo-java/api-demo/src/main/resources/META-INF/app.properties`。 ![apollo-demo-app-properties](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/apollo-demo-app-properties.jpg) @@ -147,13 +125,13 @@ Apollo本地开发需要以下组件: > 更多配置AppId的方式可以参考[1.2.1 AppId](zh/client/java-sdk-user-guide#_121-appid) -### 2.3.2 新建运行配置 +### 2.2.2 新建运行配置 ![NewConfiguration-Application](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/NewConfiguration-Application.png) -### 2.3.3 Main class配置 +### 2.2.3 Main class配置 `com.apolloconfig.apollo.demo.api.SimpleApolloConfigDemo` -### 2.3.4 VM options配置 +### 2.2.4 VM options配置 ![apollo-demo-vm-options](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/apollo-demo-vm-options.jpg) -Dapollo.meta=http://localhost:8080 @@ -162,11 +140,11 @@ Apollo本地开发需要以下组件: > 更多配置Apollo Meta Server的方式可以参考[1.2.2 Apollo Meta Server](zh/client/java-sdk-user-guide#_122-apollo-meta-server) -### 2.3.5 概览 +### 2.2.5 概览 ![apollo-demo-overview](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/apollo-demo-overview.jpg) -### 2.3.6 运行 +### 2.2.6 运行 对新建的运行配置点击Run或Debug皆可。 ![apollo-demo-run](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/local-development/apollo-demo-run.png) @@ -188,11 +166,11 @@ Apollo本地开发需要以下组件: > > ``` -## 2.4 .Net样例客户端启动 +## 2.3 .Net样例客户端启动 [apollo.net](https://github.com/ctripcorp/apollo.net)项目中有一个样例客户端的项目:`ApolloDemo`,下面就以VS 2010为例来说明如何在本地启动。 -### 2.4.1 配置项目AppId +### 2.3.1 配置项目AppId 在`2.2.5 Demo应用接入`中创建Demo项目时,系统会要求填入一个全局唯一的AppId,我们需要把这个AppId配置到`ApolloDemo`项目的APP.config文件中:`apollo.net\ApolloDemo\App.config`。 ![apollo-demo-app-config](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/apollo-net-app-config.png) @@ -206,12 +184,12 @@ Apollo本地开发需要以下组件: > 对于公共Namespace的配置,没有AppId也可以获取到配置,但是就失去了应用覆盖公共Namespace配置的能力。 -### 2.4.2 配置服务地址 +### 2.3.2 配置服务地址 Apollo客户端针对不同的环境会从不同的服务器获取配置,所以我们需要在app.config或web.config配置服务器地址(Apollo.{ENV}.Meta)。假设DEV环境的配置服务(apollo-configservice)地址是11.22.33.44,那么我们就做如下配置: ![apollo-net-server-url-config](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/doc/images/apollo-net-server-url-config.png) -### 2.4.3 运行 +### 2.3.3 运行 运行`ApolloConfigDemo.cs`即可。 启动完后,忽略前面的调试信息,可以看到如下提示: diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index eecc6f8b493..4d21e1c80aa 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -217,11 +217,11 @@ Apollo服务端共需要两个数据库:`ApolloPortalDB`和`ApolloConfigDB`, #### 2.1.1.1 手动导入SQL创建 -通过各种MySQL客户端导入[apolloportaldb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/apolloportaldb.sql)即可。 +通过各种MySQL客户端导入[apolloportaldb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/profiles/mysql-default/apolloportaldb.sql)即可。 以MySQL原生客户端为例: ```sql -source /your_local_path/scripts/sql/apolloportaldb.sql +source /your_local_path/scripts/sql/profiles/mysql-default/apolloportaldb.sql ``` #### 2.1.1.2 通过Flyway导入SQL创建 @@ -250,11 +250,11 @@ select `Id`, `Key`, `Value`, `Comment` from `ApolloPortalDB`.`ServerConfig` limi #### 2.1.2.1 手动导入SQL -通过各种MySQL客户端导入[apolloconfigdb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/apolloconfigdb.sql)即可。 +通过各种MySQL客户端导入[apolloconfigdb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/profiles/mysql-default/apolloconfigdb.sql)即可。 以MySQL原生客户端为例: ```sql -source /your_local_path/scripts/sql/apolloconfigdb.sql +source /your_local_path/scripts/sql/profiles/mysql-default/apolloconfigdb.sql ``` #### 2.1.2.2 通过Flyway导入SQL diff --git a/docs/zh/deployment/quick-start.md b/docs/zh/deployment/quick-start.md index 9474fc98b0f..a87c15b4149 100644 --- a/docs/zh/deployment/quick-start.md +++ b/docs/zh/deployment/quick-start.md @@ -29,7 +29,7 @@ Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode) Windows用户请确保JAVA_HOME环境变量已经设置。 ## 1.2 MySQL - +* 如果使用 H2 内存数据库/H2 文件数据库,则无需 MySQL,可以跳过此步骤 * 版本要求:5.6.5+ Apollo的表结构对`timestamp`使用了多个default声明,所以需要5.6.5以上版本。 @@ -66,100 +66,129 @@ Quick Start只针对本地测试使用,所以一般用户不需要自己下载 2. 在根目录下执行`mvn clean package -pl apollo-assembly -am -DskipTests=true` 3. 复制apollo-assembly/target下的jar包,rename为apollo-all-in-one.jar -# 二、安装步骤 -## 2.1 创建数据库 -Apollo服务端共需要两个数据库:`ApolloPortalDB`和`ApolloConfigDB`,我们把数据库、表的创建和样例数据都分别准备了sql文件,只需要导入数据库即可。 - -> 注意:如果你本地已经创建过Apollo数据库,请注意备份数据。我们准备的sql文件会清空Apollo相关的表。 +# 二、数据库初始化及启动 +#### 注意事项 +1. apollo 服务端进程需要分别使用8070, 8080, 8090端口,请确保这3个端口当前没有被使用。 +2. 脚本中的 SPRING_PROFILES_ACTIVE 环境变量中的 `github` 是必须的 profile,`auth` 是 portal 提供简单认证的 profile,不需要认证或者使用其它认证方式时可以去掉 -### 2.1.1 创建ApolloPortalDB -通过各种MySQL客户端导入[sql/apolloportaldb.sql](https://github.com/apolloconfig/apollo-quick-start/blob/master/sql/apolloportaldb.sql)即可。 +## 2.1 使用 H2 内存数据库,自动初始化 +无需任何配置,直接使用如下命令启动即可 +> 注:使用内存数据库时,任何操作都会在 apollo 进程重启后丢失 +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +unset SPRING_SQL_CONFIG_INIT_MODE +unset SPRING_SQL_PORTAL_INIT_MODE +java -jar apollo-all-in-one.jar -下面以MySQL原生客户端为例: -```sql -source /your_local_path/sql/apolloportaldb.sql ``` -导入成功后,可以通过执行以下sql语句来验证: -```sql -select `Id`, `AppId`, `Name` from ApolloPortalDB.App; -``` +## 2.2 使用 H2 文件数据库,自动初始化 +#### 注意事项 +1. 脚本中环境变量中的路径 `~/apollo/apollo-config-db` 和 `~/apollo/apollo-portal-db` 可以替换为其它自定义路径,需要保证该路径有读写权限 + +### 2.2.1 首次启动 +首次启动使用 SPRING_SQL_CONFIG_INIT_MODE="always" 和 SPRING_SQL_PORTAL_INIT_MODE="always" 环境变量来进行初始化 +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +# config db +export SPRING_SQL_CONFIG_INIT_MODE="always" +export SPRING_CONFIG_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" +# portal db +export SPRING_SQL_PORTAL_INIT_MODE="always" +export SPRING_PORTAL_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" +java -jar apollo-all-in-one.jar -| Id | AppId | Name | -|----|-----------|------------| -| 1 | SampleApp | Sample App | - -### 2.1.2 创建ApolloConfigDB -通过各种MySQL客户端导入[sql/apolloconfigdb.sql](https://github.com/apolloconfig/apollo-quick-start/blob/master/sql/apolloconfigdb.sql)即可。 - -下面以MySQL原生客户端为例: -```sql -source /your_local_path/sql/apolloconfigdb.sql ``` -导入成功后,可以通过执行以下sql语句来验证: -```sql -select `NamespaceId`, `Key`, `Value`, `Comment` from ApolloConfigDB.Item; -``` -| NamespaceId | Key | Value | Comment | -|-------------|---------|-------|--------------------| -| 1 | timeout | 100 | sample timeout配置 | +### 2.2.2 后续启动 +后续启动去掉 SPRING_SQL_CONFIG_INIT_MODE 和 SPRING_SQL_PORTAL_INIT_MODE 环境变量来避免重复初始化 +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +# config db +unset SPRING_SQL_CONFIG_INIT_MODE +export SPRING_CONFIG_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" +# portal db +unset SPRING_SQL_PORTAL_INIT_MODE +export SPRING_PORTAL_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" +java -jar apollo-all-in-one.jar -## 2.2 配置数据库连接信息 -Apollo服务端需要知道如何连接到你前面创建的数据库,所以需要编辑[demo.sh](https://github.com/apolloconfig/apollo-quick-start/blob/master/demo.sh),修改ApolloPortalDB和ApolloConfigDB相关的数据库连接串信息。 +``` -> 注意:填入的用户需要具备对ApolloPortalDB和ApolloConfigDB数据的读写权限。 +## 2.3 使用 mysql 数据库,自动初始化 +#### 注意事项 +1. 脚本环境变量中的 your-mysql-server:3306 需要替换为实际的 mysql 服务器地址和端口,ApolloConfigDB 和 ApolloPortalDB 需要替换为实际的数据库名称 +2. 脚本环境变量中的 "apollo-username" 和 "apollo-password" 需要填写实际的用户名和密码 + +### 2.3.1 首次启动 +首次启动使用 SPRING_SQL_INIT_MODE="always" 环境变量来进行初始化 +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +# config db +export SPRING_SQL_CONFIG_INIT_MODE="always" +export SPRING_CONFIG_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloConfigDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_CONFIG_DATASOURCE_USERNAME="apollo-username" +export SPRING_CONFIG_DATASOURCE_PASSWORD="apollo-password" +# portal db +export SPRING_SQL_PORTAL_INIT_MODE="always" +export SPRING_PORTAL_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloPortalDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_PORTAL_DATASOURCE_USERNAME="apollo-username" +export SPRING_PORTAL_DATASOURCE_PASSWORD="apollo-password" +java -jar apollo-all-in-one.jar -```sh -#apollo config db info -apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai" -apollo_config_db_username=用户名 -apollo_config_db_password=密码(如果没有密码,留空即可) - -# apollo portal db info -apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai" -apollo_portal_db_username=用户名 -apollo_portal_db_password=密码(如果没有密码,留空即可) ``` -> 注意:不要修改demo.sh的其它部分 - -# 三、启动Apollo配置中心 -## 3.1 确保端口未被占用 -Quick Start脚本会在本地启动3个服务,分别使用8070, 8080, 8090端口,请确保这3个端口当前没有被使用。 +### 2.3.2 后续启动 +后续启动去掉 SPRING_SQL_CONFIG_INIT_MODE 和 SPRING_SQL_PORTAL_INIT_MODE 环境变量来避免重复初始化 +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +# config db +unset SPRING_SQL_CONFIG_INIT_MODE +export SPRING_CONFIG_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloConfigDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_CONFIG_DATASOURCE_USERNAME="apollo-username" +export SPRING_CONFIG_DATASOURCE_PASSWORD="apollo-password" +# portal db +unset SPRING_SQL_PORTAL_INIT_MODE +export SPRING_PORTAL_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloPortalDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_PORTAL_DATASOURCE_USERNAME="apollo-username" +export SPRING_PORTAL_DATASOURCE_PASSWORD="apollo-password" +java -jar apollo-all-in-one.jar -例如,在Linux/Mac下,可以通过如下命令检查: -```sh -lsof -i:8080 ``` -## 3.2 执行启动脚本 -```sh -./demo.sh start -``` +## 2.4 使用 mysql 数据库,手动初始化 + +### 2.4.1 手动初始化 ApolloConfigDB 和 ApolloPortalDB +ApolloConfigDB 通过各种MySQL客户端导入[apolloconfigdb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/profiles/mysql-default/apolloconfigdb.sql)即可。 +ApolloPortalDB 通过各种MySQL客户端导入[apolloportaldb.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/profiles/mysql-default/apolloportaldb.sql)即可。 + +### 2.4.2 运行 +#### 注意事项 +1. 脚本环境变量中的 your-mysql-server:3306 需要替换为实际的 mysql 服务器地址和端口,ApolloConfigDB 和 ApolloPortalDB 需要替换为实际的数据库名称 +2. 脚本环境变量中的 "apollo-username" 和 "apollo-password" 需要填写实际的用户名和密码 + +```bash +export SPRING_PROFILES_ACTIVE="github,auth" +# config db +unset SPRING_SQL_CONFIG_INIT_MODE +export SPRING_CONFIG_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloConfigDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_CONFIG_DATASOURCE_USERNAME="apollo-username" +export SPRING_CONFIG_DATASOURCE_PASSWORD="apollo-password" +# portal db +unset SPRING_SQL_PORTAL_INIT_MODE +export SPRING_PORTAL_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloPortalDB?useUnicode=true&characterEncoding=UTF8" +export SPRING_PORTAL_DATASOURCE_USERNAME="apollo-username" +export SPRING_PORTAL_DATASOURCE_PASSWORD="apollo-password" +java -jar apollo-all-in-one.jar -当看到如下输出后,就说明启动成功了! -```sh -==== starting service ==== -Service logging file is ./service/apollo-service.log -Started [10768] -Waiting for config service startup....... -Config service started. You may visit http://localhost:8080 for service status now! -Waiting for admin service startup.... -Admin service started -==== starting portal ==== -Portal logging file is ./portal/apollo-portal.log -Started [10846] -Waiting for portal startup...... -Portal started. You can visit http://localhost:8070 now! ``` -## 3.3 异常排查 +# 三、启动额外说明 +## 3.1 异常排查 如果启动遇到了异常,可以分别查看service和portal目录下的log文件排查问题。 -> 注:在启动apollo-configservice的过程中会在日志中输出eureka注册失败的信息,如`com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused`。需要注意的是,这个是预期的情况,因为apollo-configservice需要向Meta Server(它自己)注册服务,但是因为在启动过程中,自己还没起来,所以会报这个错。后面会进行重试的动作,所以等自己服务起来后就会注册正常了。 +> 注:在启动的过程中会在日志中输出eureka注册失败的信息,如`com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused`。需要注意的是,这个是预期的情况,因为apollo-configservice需要向Meta Server(它自己)注册服务,但是因为在启动过程中,自己还没起来,所以会报这个错。后面会进行重试的动作,所以等自己服务起来后就会注册正常了。 -## 3.4 注意 +## 3.2 注意 Quick Start只是用来帮助大家快速体验Apollo项目,具体实际使用时请参考:[分布式部署指南](zh/deployment/distributed-deployment-guide)。 另外需要注意的是Quick Start不支持增加环境,只有通过分布式部署才可以新增环境,同样请参考:[分布式部署指南](zh/deployment/distributed-deployment-guide) diff --git a/docs/zh/extension/portal-how-to-implement-user-login-function.md b/docs/zh/extension/portal-how-to-implement-user-login-function.md index cb406e616e3..ae8d996517b 100644 --- a/docs/zh/extension/portal-how-to-implement-user-login-function.md +++ b/docs/zh/extension/portal-how-to-implement-user-login-function.md @@ -8,7 +8,7 @@ Apollo是配置管理系统,会提供权限管理(Authorization),理论 使用步骤如下: ### 1. 安装0.9.0以上版本 ->如果之前是0.8.0版本,需要导入[apolloportaldb-v080-v090.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/delta/v080-v090/apolloportaldb-v080-v090.sql) +>如果之前是0.8.0版本,需要导入[apolloportaldb-v080-v090.sql](https://github.com/apolloconfig/apollo/blob/master/scripts/sql/profiles/mysql-default/delta/v080-v090/apolloportaldb-v080-v090.sql) 查看ApolloPortalDB,应该已经存在`Users`表,并有一条初始记录。初始用户名是apollo,密码是admin。 diff --git a/pom.xml b/pom.xml index 2869b72a45c..c8535c07671 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ + apollo-build-sql-converter apollo-buildtools apollo-common apollo-biz diff --git a/scripts/sql/profiles/h2-default/apolloconfigdb.sql b/scripts/sql/profiles/h2-default/apolloconfigdb.sql new file mode 100644 index 00000000000..8a24f1c82c9 --- /dev/null +++ b/scripts/sql/profiles/h2-default/apolloconfigdb.sql @@ -0,0 +1,501 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- + +-- H2 Function +-- ------------------------------------------------------------ +CREATE ALIAS IF NOT EXISTS UNIX_TIMESTAMP FOR "com.ctrip.framework.apollo.common.jpa.H2Function.unixTimestamp"; + +-- + +-- Dump of table app +-- ------------------------------------------------------------ + + +CREATE TABLE `App` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `App_UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + KEY `App_DataChange_LastTime` (`DataChange_LastTime`), + KEY `App_IX_Name` (`Name`) +) COMMENT='应用表'; + + + +-- Dump of table appnamespace +-- ------------------------------------------------------------ + + +CREATE TABLE `AppNamespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', + `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'app id', + `Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', + `IsPublic` boolean NOT NULL DEFAULT FALSE COMMENT 'namespace是否为公共', + `Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `AppNamespace_UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + KEY `AppNamespace_Name_AppId` (`Name`,`AppId`), + KEY `AppNamespace_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='应用namespace定义'; + + + +-- Dump of table audit +-- ------------------------------------------------------------ + + +CREATE TABLE `Audit` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `EntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `EntityId` int(10) unsigned DEFAULT NULL COMMENT '记录ID', + `OpName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `Comment` varchar(500) DEFAULT NULL COMMENT '备注', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `Audit_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='日志审计表'; + + + +-- Dump of table cluster +-- ------------------------------------------------------------ + + +CREATE TABLE `Cluster` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT '集群名字', + `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'App id', + `ParentClusterId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父cluster', + `Comment` varchar(64) DEFAULT NULL COMMENT '备注', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `Cluster_UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + KEY `Cluster_IX_ParentClusterId` (`ParentClusterId`), + KEY `Cluster_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='集群'; + + + +-- Dump of table commit +-- ------------------------------------------------------------ + + +CREATE TABLE `Commit` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `ChangeSets` longtext NOT NULL COMMENT '修改变更集', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `Comment` varchar(500) DEFAULT NULL COMMENT '备注', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `Commit_DataChange_LastTime` (`DataChange_LastTime`), + KEY `Commit_AppId` (`AppId`), + KEY `Commit_ClusterName` (`ClusterName`), + KEY `Commit_NamespaceName` (`NamespaceName`) +) COMMENT='commit 历史表'; + +-- Dump of table grayreleaserule +-- ------------------------------------------------------------ + + +CREATE TABLE `GrayReleaseRule` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', + `NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', + `BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'branch name', + `Rules` varchar(16000) DEFAULT '[]' COMMENT '灰度规则', + `ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '灰度对应的release', + `BranchStatus` tinyint(2) DEFAULT '1' COMMENT '灰度分支状态: 0:删除分支,1:正在使用的规则 2:全量发布', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `GrayReleaseRule_DataChange_LastTime` (`DataChange_LastTime`), + KEY `GrayReleaseRule_IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`) +) COMMENT='灰度规则表'; + + +-- Dump of table instance +-- ------------------------------------------------------------ + + +CREATE TABLE `Instance` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `DataCenter` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Data Center Name', + `Ip` varchar(32) NOT NULL DEFAULT '' COMMENT 'instance ip', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `Instance_IX_UNIQUE_KEY` (`AppId`,`ClusterName`,`Ip`,`DataCenter`), + KEY `Instance_IX_IP` (`Ip`), + KEY `Instance_IX_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='使用配置的应用实例'; + + + +-- Dump of table instanceconfig +-- ------------------------------------------------------------ + + +CREATE TABLE `InstanceConfig` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `InstanceId` int(11) unsigned DEFAULT NULL COMMENT 'Instance Id', + `ConfigAppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Config App Id', + `ConfigClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Cluster Name', + `ConfigNamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Namespace Name', + `ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', + `ReleaseDeliveryTime` timestamp NULL DEFAULT NULL COMMENT '配置获取时间', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `InstanceConfig_IX_UNIQUE_KEY` (`InstanceId`,`ConfigAppId`,`ConfigNamespaceName`), + KEY `InstanceConfig_IX_ReleaseKey` (`ReleaseKey`), + KEY `InstanceConfig_IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `InstanceConfig_IX_Valid_Namespace` (`ConfigAppId`,`ConfigClusterName`,`ConfigNamespaceName`,`DataChange_LastTime`) +) COMMENT='应用实例的配置信息'; + + + +-- Dump of table item +-- ------------------------------------------------------------ + + +CREATE TABLE `Item` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', + `Key` varchar(128) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '配置项类型,0: String,1: Number,2: Boolean,3: JSON', + `Value` longtext NOT NULL COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `LineNum` int(10) unsigned DEFAULT '0' COMMENT '行号', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `Item_IX_GroupId` (`NamespaceId`), + KEY `Item_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='配置项目'; + + + +-- Dump of table namespace +-- ------------------------------------------------------------ + + +CREATE TABLE `Namespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `Namespace_UK_AppId_ClusterName_NamespaceName_DeletedAt` (`AppId`,`ClusterName`,`NamespaceName`,`DeletedAt`), + KEY `Namespace_DataChange_LastTime` (`DataChange_LastTime`), + KEY `Namespace_IX_NamespaceName` (`NamespaceName`) +) COMMENT='命名空间'; + + + +-- Dump of table namespacelock +-- ------------------------------------------------------------ + + +CREATE TABLE `NamespaceLock` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id', + `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + `IsDeleted` boolean DEFAULT FALSE COMMENT '软删除', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + PRIMARY KEY (`Id`), + UNIQUE KEY `NamespaceLock_UK_NamespaceId_DeletedAt` (`NamespaceId`,`DeletedAt`), + KEY `NamespaceLock_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='namespace的编辑锁'; + + + +-- Dump of table release +-- ------------------------------------------------------------ + + +CREATE TABLE `Release` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', + `Name` varchar(64) NOT NULL DEFAULT 'default' COMMENT '发布名字', + `Comment` varchar(256) DEFAULT NULL COMMENT '发布说明', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `Configurations` longtext NOT NULL COMMENT '发布配置', + `IsAbandoned` boolean NOT NULL DEFAULT FALSE COMMENT '是否废弃', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `Release_UK_ReleaseKey_DeletedAt` (`ReleaseKey`,`DeletedAt`), + KEY `Release_AppId_ClusterName_GroupName` (`AppId`,`ClusterName`,`NamespaceName`), + KEY `Release_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='发布'; + + +-- Dump of table releasehistory +-- ------------------------------------------------------------ + + +CREATE TABLE `ReleaseHistory` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT '发布分支名', + `ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关联的Release Id', + `PreviousReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '前一次发布的ReleaseId', + `Operation` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '发布类型,0: 普通发布,1: 回滚,2: 灰度发布,3: 灰度规则更新,4: 灰度合并回主分支发布,5: 主分支发布灰度自动发布,6: 主分支回滚灰度自动发布,7: 放弃灰度', + `OperationContext` longtext NOT NULL COMMENT '发布上下文信息', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `ReleaseHistory_IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`,`BranchName`), + KEY `ReleaseHistory_IX_ReleaseId` (`ReleaseId`), + KEY `ReleaseHistory_IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `ReleaseHistory_IX_PreviousReleaseId` (`PreviousReleaseId`) +) COMMENT='发布历史'; + + +-- Dump of table releasemessage +-- ------------------------------------------------------------ + + +CREATE TABLE `ReleaseMessage` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Message` varchar(1024) NOT NULL DEFAULT '' COMMENT '发布的消息内容', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `ReleaseMessage_DataChange_LastTime` (`DataChange_LastTime`), + KEY `ReleaseMessage_IX_Message` (`Message`) +) COMMENT='发布消息'; + + + +-- Dump of table serverconfig +-- ------------------------------------------------------------ + + +CREATE TABLE `ServerConfig` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Cluster` varchar(32) NOT NULL DEFAULT 'default' COMMENT '配置对应的集群,default为不针对特定的集群', + `Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `ServerConfig_UK_Key_Cluster_DeletedAt` (`Key`,`Cluster`,`DeletedAt`), + KEY `ServerConfig_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='配置服务自身配置'; + +-- Dump of table accesskey +-- ------------------------------------------------------------ + + +CREATE TABLE `AccessKey` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Secret` varchar(128) NOT NULL DEFAULT '' COMMENT 'Secret', + `IsEnabled` boolean NOT NULL DEFAULT FALSE COMMENT '1: enabled, 0: disabled', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `AccessKey_UK_AppId_Secret_DeletedAt` (`AppId`,`Secret`,`DeletedAt`), + KEY `AccessKey_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='访问密钥'; + + +-- Dump of table serviceregistry +-- ------------------------------------------------------------ + + +CREATE TABLE `ServiceRegistry` ( + `Id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ServiceName` VARCHAR(64) NOT NULL COMMENT '服务名', + `Uri` VARCHAR(64) NOT NULL COMMENT '服务地址', + `Cluster` VARCHAR(64) NOT NULL COMMENT '集群,可以用来标识apollo.cluster或者网络分区', + `Metadata` VARCHAR(1024) NOT NULL DEFAULT '{}' COMMENT '元数据,key value结构的json object,为了方面后面扩展功能而不需要修改表结构', + `DataChange_CreatedTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE INDEX `IX_UNIQUE_KEY` (`ServiceName`, `Uri`), + INDEX `IX_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='注册中心'; + +-- Dump of table AuditLog +-- ------------------------------------------------------------ + + +CREATE TABLE `AuditLog` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `TraceId` varchar(32) NOT NULL DEFAULT '' COMMENT '链路全局唯一ID', + `SpanId` varchar(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `ParentSpanId` varchar(32) DEFAULT NULL COMMENT '父跨度ID', + `FollowsFromSpanId` varchar(32) DEFAULT NULL COMMENT '上一个兄弟跨度ID', + `Operator` varchar(64) NOT NULL DEFAULT 'anonymous' COMMENT '操作人', + `OpType` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `OpName` varchar(150) NOT NULL DEFAULT 'default' COMMENT '操作名称', + `Description` varchar(200) DEFAULT NULL COMMENT '备注', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AuditLog_IX_TraceId` (`TraceId`), + KEY `AuditLog_IX_OpName` (`OpName`), + KEY `AuditLog_IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `AuditLog_IX_Operator` (`Operator`) +) COMMENT='审计日志表'; + +-- Dump of table AuditLogDataInfluence +-- ------------------------------------------------------------ + + +CREATE TABLE `AuditLogDataInfluence` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `SpanId` char(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `InfluenceEntityId` varchar(50) NOT NULL DEFAULT '0' COMMENT '记录ID', + `InfluenceEntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `FieldName` varchar(50) DEFAULT NULL COMMENT '字段名称', + `FieldOldValue` varchar(500) DEFAULT NULL COMMENT '字段旧值', + `FieldNewValue` varchar(500) DEFAULT NULL COMMENT '字段新值', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AuditLogDataInfluence_IX_SpanId` (`SpanId`), + KEY `AuditLogDataInfluence_IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `AuditLogDataInfluence_IX_EntityId` (`InfluenceEntityId`) +) COMMENT='审计日志数据变动表'; + +-- Config +-- ------------------------------------------------------------ +INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`, `Comment`) +VALUES + ('eureka.service.url', 'default', 'http://localhost:8080/eureka/', 'Eureka服务Url,多个service以英文逗号分隔'), + ('namespace.lock.switch', 'default', 'false', '一次发布只能有一个人修改开关'), + ('item.key.length.limit', 'default', '128', 'item key 最大长度限制'), + ('item.value.length.limit', 'default', '20000', 'item value最大长度限制'), + ('config-service.cache.enabled', 'default', 'false', 'ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!'); + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/scripts/sql/profiles/h2-default/apolloportaldb.sql b/scripts/sql/profiles/h2-default/apolloportaldb.sql new file mode 100644 index 00000000000..e1be67d3d6e --- /dev/null +++ b/scripts/sql/profiles/h2-default/apolloportaldb.sql @@ -0,0 +1,445 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- + +-- H2 Function +-- ------------------------------------------------------------ +CREATE ALIAS IF NOT EXISTS UNIX_TIMESTAMP FOR "com.ctrip.framework.apollo.common.jpa.H2Function.unixTimestamp"; + +-- + +-- Dump of table app +-- ------------------------------------------------------------ + + +CREATE TABLE `App` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `App_UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + KEY `App_DataChange_LastTime` (`DataChange_LastTime`), + KEY `App_IX_Name` (`Name`) +) COMMENT='应用表'; + + + +-- Dump of table appnamespace +-- ------------------------------------------------------------ + + +CREATE TABLE `AppNamespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', + `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'app id', + `Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', + `IsPublic` boolean NOT NULL DEFAULT FALSE COMMENT 'namespace是否为公共', + `Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `AppNamespace_UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + KEY `AppNamespace_Name_AppId` (`Name`,`AppId`), + KEY `AppNamespace_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='应用namespace定义'; + + + +-- Dump of table consumer +-- ------------------------------------------------------------ + + +CREATE TABLE `Consumer` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `Consumer_UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + KEY `Consumer_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='开放API消费者'; + + + +-- Dump of table consumeraudit +-- ------------------------------------------------------------ + + +CREATE TABLE `ConsumerAudit` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', + `Uri` varchar(1024) NOT NULL DEFAULT '' COMMENT '访问的Uri', + `Method` varchar(16) NOT NULL DEFAULT '' COMMENT '访问的Method', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `ConsumerAudit_IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `ConsumerAudit_IX_ConsumerId` (`ConsumerId`) +) COMMENT='consumer审计表'; + + + +-- Dump of table consumerrole +-- ------------------------------------------------------------ + + +CREATE TABLE `ConsumerRole` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `ConsumerRole_UK_ConsumerId_RoleId_DeletedAt` (`ConsumerId`,`RoleId`,`DeletedAt`), + KEY `ConsumerRole_IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `ConsumerRole_IX_RoleId` (`RoleId`) +) COMMENT='consumer和role的绑定表'; + + + +-- Dump of table consumertoken +-- ------------------------------------------------------------ + + +CREATE TABLE `ConsumerToken` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'ConsumerId', + `Token` varchar(128) NOT NULL DEFAULT '' COMMENT 'token', + `Expires` datetime NOT NULL DEFAULT '2099-01-01 00:00:00' COMMENT 'token失效时间', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `ConsumerToken_UK_Token_DeletedAt` (`Token`,`DeletedAt`), + KEY `ConsumerToken_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='consumer token表'; + +-- Dump of table favorite +-- ------------------------------------------------------------ + + +CREATE TABLE `Favorite` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `UserId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '收藏的用户', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Position` int(32) NOT NULL DEFAULT '10000' COMMENT '收藏顺序', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `Favorite_UK_UserId_AppId_DeletedAt` (`UserId`,`AppId`,`DeletedAt`), + KEY `Favorite_AppId` (`AppId`), + KEY `Favorite_DataChange_LastTime` (`DataChange_LastTime`) +) AUTO_INCREMENT=23 COMMENT='应用收藏表'; + +-- Dump of table permission +-- ------------------------------------------------------------ + + +CREATE TABLE `Permission` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `PermissionType` varchar(32) NOT NULL DEFAULT '' COMMENT '权限类型', + `TargetId` varchar(256) NOT NULL DEFAULT '' COMMENT '权限对象类型', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `Permission_UK_TargetId_PermissionType_DeletedAt` (`TargetId`,`PermissionType`,`DeletedAt`), + KEY `Permission_IX_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='permission表'; + + + +-- Dump of table role +-- ------------------------------------------------------------ + + +CREATE TABLE `Role` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `RoleName` varchar(256) NOT NULL DEFAULT '' COMMENT 'Role name', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `Role_UK_RoleName_DeletedAt` (`RoleName`,`DeletedAt`), + KEY `Role_IX_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='角色表'; + + + +-- Dump of table rolepermission +-- ------------------------------------------------------------ + + +CREATE TABLE `RolePermission` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `PermissionId` int(10) unsigned DEFAULT NULL COMMENT 'Permission Id', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `RolePermission_UK_RoleId_PermissionId_DeletedAt` (`RoleId`,`PermissionId`,`DeletedAt`), + KEY `RolePermission_IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `RolePermission_IX_PermissionId` (`PermissionId`) +) COMMENT='角色和权限的绑定表'; + + + +-- Dump of table serverconfig +-- ------------------------------------------------------------ + + +CREATE TABLE `ServerConfig` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `ServerConfig_UK_Key_DeletedAt` (`Key`,`DeletedAt`), + KEY `ServerConfig_DataChange_LastTime` (`DataChange_LastTime`) +) COMMENT='配置服务自身配置'; + + + +-- Dump of table userrole +-- ------------------------------------------------------------ + + +CREATE TABLE `UserRole` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `UserId` varchar(128) DEFAULT '' COMMENT '用户身份标识', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UserRole_UK_UserId_RoleId_DeletedAt` (`UserId`,`RoleId`,`DeletedAt`), + KEY `UserRole_IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `UserRole_IX_RoleId` (`RoleId`) +) COMMENT='用户和role的绑定表'; + +-- Dump of table Users +-- ------------------------------------------------------------ + + +CREATE TABLE `Users` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Username` varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户登录账户', + `Password` varchar(512) NOT NULL DEFAULT 'default' COMMENT '密码', + `UserDisplayName` varchar(512) NOT NULL DEFAULT 'default' COMMENT '用户名称', + `Email` varchar(64) NOT NULL DEFAULT 'default' COMMENT '邮箱地址', + `Enabled` tinyint(4) DEFAULT NULL COMMENT '是否有效', + PRIMARY KEY (`Id`), + UNIQUE KEY `Users_UK_Username` (`Username`) +) COMMENT='用户表'; + + +-- Dump of table Authorities +-- ------------------------------------------------------------ + + +CREATE TABLE `Authorities` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Username` varchar(64) NOT NULL, + `Authority` varchar(50) NOT NULL, + PRIMARY KEY (`Id`) +) ; + +-- spring session (https://github.com/spring-projects/spring-session/blob/faee8f1bdb8822a5653a81eba838dddf224d92d6/spring-session-jdbc/src/main/resources/org/springframework/session/jdbc/schema-mysql.sql) +-- Dump of table SPRING_SESSION +-- ------------------------------------------------------------ + + +CREATE TABLE `SPRING_SESSION` ( + `PRIMARY_ID` char(36) NOT NULL, + `SESSION_ID` char(36) NOT NULL, + `CREATION_TIME` bigint NOT NULL, + `LAST_ACCESS_TIME` bigint NOT NULL, + `MAX_INACTIVE_INTERVAL` int NOT NULL, + `EXPIRY_TIME` bigint NOT NULL, + `PRINCIPAL_NAME` varchar(100) DEFAULT NULL, + PRIMARY KEY (`PRIMARY_ID`), + UNIQUE KEY `SPRING_SESSION_SPRING_SESSION_IX1` (`SESSION_ID`), + KEY `SPRING_SESSION_SPRING_SESSION_IX2` (`EXPIRY_TIME`), + KEY `SPRING_SESSION_SPRING_SESSION_IX3` (`PRINCIPAL_NAME`) +) ; + +-- Dump of table SPRING_SESSION_ATTRIBUTES +-- ------------------------------------------------------------ + + +CREATE TABLE `SPRING_SESSION_ATTRIBUTES` ( + `SESSION_PRIMARY_ID` char(36) NOT NULL, + `ATTRIBUTE_NAME` varchar(200) NOT NULL, + `ATTRIBUTE_BYTES` blob NOT NULL, + PRIMARY KEY (`SESSION_PRIMARY_ID`,`ATTRIBUTE_NAME`), + CONSTRAINT `SPRING_SESSION_ATTRIBUTES_FK` FOREIGN KEY (`SESSION_PRIMARY_ID`) REFERENCES `SPRING_SESSION` (`PRIMARY_ID`) ON DELETE CASCADE +) ; + +-- Dump of table AuditLog +-- ------------------------------------------------------------ + + +CREATE TABLE `AuditLog` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `TraceId` varchar(32) NOT NULL DEFAULT '' COMMENT '链路全局唯一ID', + `SpanId` varchar(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `ParentSpanId` varchar(32) DEFAULT NULL COMMENT '父跨度ID', + `FollowsFromSpanId` varchar(32) DEFAULT NULL COMMENT '上一个兄弟跨度ID', + `Operator` varchar(64) NOT NULL DEFAULT 'anonymous' COMMENT '操作人', + `OpType` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `OpName` varchar(150) NOT NULL DEFAULT 'default' COMMENT '操作名称', + `Description` varchar(200) DEFAULT NULL COMMENT '备注', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AuditLog_IX_TraceId` (`TraceId`), + KEY `AuditLog_IX_OpName` (`OpName`), + KEY `AuditLog_IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `AuditLog_IX_Operator` (`Operator`) +) COMMENT='审计日志表'; + +-- Dump of table AuditLogDataInfluence +-- ------------------------------------------------------------ + + +CREATE TABLE `AuditLogDataInfluence` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `SpanId` char(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `InfluenceEntityId` varchar(50) NOT NULL DEFAULT '0' COMMENT '记录ID', + `InfluenceEntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `FieldName` varchar(50) DEFAULT NULL COMMENT '字段名称', + `FieldOldValue` varchar(500) DEFAULT NULL COMMENT '字段旧值', + `FieldNewValue` varchar(500) DEFAULT NULL COMMENT '字段新值', + `IsDeleted` boolean NOT NULL DEFAULT FALSE COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `AuditLogDataInfluence_IX_SpanId` (`SpanId`), + KEY `AuditLogDataInfluence_IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `AuditLogDataInfluence_IX_EntityId` (`InfluenceEntityId`) +) COMMENT='审计日志数据变动表'; + +-- Config +-- ------------------------------------------------------------ +INSERT INTO `ServerConfig` (`Key`, `Value`, `Comment`) +VALUES + ('apollo.portal.envs', 'dev', '可支持的环境列表'), + ('organizations', '[{"orgId":"TEST1","orgName":"样例部门1"},{"orgId":"TEST2","orgName":"样例部门2"}]', '部门列表'), + ('superAdmin', 'apollo', 'Portal超级管理员'), + ('api.readTimeout', '10000', 'http接口read timeout'), + ('consumer.token.salt', 'someSalt', 'consumer token salt'), + ('admin.createPrivateNamespace.switch', 'true', '是否允许项目管理员创建私有namespace'), + ('configView.memberOnly.envs', 'pro', '只对项目成员显示配置信息的环境列表,多个env以英文逗号分隔'), + ('apollo.portal.meta.servers', '{}', '各环境Meta Service列表'); + + +INSERT INTO `Users` (`Username`, `Password`, `UserDisplayName`, `Email`, `Enabled`) +VALUES + ('apollo', '$2a$10$7r20uS.BQ9uBpf3Baj3uQOZvMVvB1RN3PYoKE94gtz2.WAOuiiwXS', 'apollo', 'apollo@acme.com', 1); + +INSERT INTO `Authorities` (`Username`, `Authority`) VALUES ('apollo', 'ROLE_user'); + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/scripts/sql/profiles/h2-default/delta/v220-v230/apolloconfigdb-v220-v230.sql b/scripts/sql/profiles/h2-default/delta/v220-v230/apolloconfigdb-v220-v230.sql new file mode 100644 index 00000000000..ec703d5aa80 --- /dev/null +++ b/scripts/sql/profiles/h2-default/delta/v220-v230/apolloconfigdb-v220-v230.sql @@ -0,0 +1,43 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v2.2.0 to v2.3.0 + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- + +-- H2 Function +-- ------------------------------------------------------------ +CREATE ALIAS IF NOT EXISTS UNIX_TIMESTAMP FOR "com.ctrip.framework.apollo.common.jpa.H2Function.unixTimestamp"; + +-- + +ALTER TABLE `Cluster` ADD COLUMN `Comment` varchar(64) DEFAULT NULL COMMENT '备注'; + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== diff --git a/scripts/sql/profiles/h2-default/delta/v220-v230/apolloportaldb-v220-v230.sql b/scripts/sql/profiles/h2-default/delta/v220-v230/apolloportaldb-v220-v230.sql new file mode 100644 index 00000000000..80971e7e15c --- /dev/null +++ b/scripts/sql/profiles/h2-default/delta/v220-v230/apolloportaldb-v220-v230.sql @@ -0,0 +1,42 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v2.2.0 to v2.3.0 + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- + +-- H2 Function +-- ------------------------------------------------------------ +CREATE ALIAS IF NOT EXISTS UNIX_TIMESTAMP FOR "com.ctrip.framework.apollo.common.jpa.H2Function.unixTimestamp"; + +-- + + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== diff --git a/scripts/sql/profiles/mysql-database-not-specified/apolloconfigdb.sql b/scripts/sql/profiles/mysql-database-not-specified/apolloconfigdb.sql new file mode 100644 index 00000000000..4d2e0c19118 --- /dev/null +++ b/scripts/sql/profiles/mysql-database-not-specified/apolloconfigdb.sql @@ -0,0 +1,515 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- +-- + +-- Dump of table app +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `App`; + +CREATE TABLE `App` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Name` (`Name`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用表'; + + + +-- Dump of table appnamespace +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AppNamespace`; + +CREATE TABLE `AppNamespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', + `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'app id', + `Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', + `IsPublic` bit(1) NOT NULL DEFAULT b'0' COMMENT 'namespace是否为公共', + `Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + KEY `Name_AppId` (`Name`,`AppId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用namespace定义'; + + + +-- Dump of table audit +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Audit`; + +CREATE TABLE `Audit` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `EntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `EntityId` int(10) unsigned DEFAULT NULL COMMENT '记录ID', + `OpName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `Comment` varchar(500) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='日志审计表'; + + + +-- Dump of table cluster +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Cluster`; + +CREATE TABLE `Cluster` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT '集群名字', + `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'App id', + `ParentClusterId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父cluster', + `Comment` varchar(64) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + KEY `IX_ParentClusterId` (`ParentClusterId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='集群'; + + + +-- Dump of table commit +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Commit`; + +CREATE TABLE `Commit` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `ChangeSets` longtext NOT NULL COMMENT '修改变更集', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `Comment` varchar(500) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `AppId` (`AppId`), + KEY `ClusterName` (`ClusterName`(191)), + KEY `NamespaceName` (`NamespaceName`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='commit 历史表'; + +-- Dump of table grayreleaserule +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `GrayReleaseRule`; + +CREATE TABLE `GrayReleaseRule` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', + `NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', + `BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'branch name', + `Rules` varchar(16000) DEFAULT '[]' COMMENT '灰度规则', + `ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '灰度对应的release', + `BranchStatus` tinyint(2) DEFAULT '1' COMMENT '灰度分支状态: 0:删除分支,1:正在使用的规则 2:全量发布', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='灰度规则表'; + + +-- Dump of table instance +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Instance`; + +CREATE TABLE `Instance` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `DataCenter` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Data Center Name', + `Ip` varchar(32) NOT NULL DEFAULT '' COMMENT 'instance ip', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `IX_UNIQUE_KEY` (`AppId`,`ClusterName`,`Ip`,`DataCenter`), + KEY `IX_IP` (`Ip`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='使用配置的应用实例'; + + + +-- Dump of table instanceconfig +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `InstanceConfig`; + +CREATE TABLE `InstanceConfig` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `InstanceId` int(11) unsigned DEFAULT NULL COMMENT 'Instance Id', + `ConfigAppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Config App Id', + `ConfigClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Cluster Name', + `ConfigNamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Namespace Name', + `ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', + `ReleaseDeliveryTime` timestamp NULL DEFAULT NULL COMMENT '配置获取时间', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `IX_UNIQUE_KEY` (`InstanceId`,`ConfigAppId`,`ConfigNamespaceName`), + KEY `IX_ReleaseKey` (`ReleaseKey`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Valid_Namespace` (`ConfigAppId`,`ConfigClusterName`,`ConfigNamespaceName`,`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用实例的配置信息'; + + + +-- Dump of table item +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Item`; + +CREATE TABLE `Item` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', + `Key` varchar(128) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '配置项类型,0: String,1: Number,2: Boolean,3: JSON', + `Value` longtext NOT NULL COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `LineNum` int(10) unsigned DEFAULT '0' COMMENT '行号', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_GroupId` (`NamespaceId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置项目'; + + + +-- Dump of table namespace +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Namespace`; + +CREATE TABLE `Namespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_ClusterName_NamespaceName_DeletedAt` (`AppId`,`ClusterName`(191),`NamespaceName`(191),`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_NamespaceName` (`NamespaceName`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='命名空间'; + + + +-- Dump of table namespacelock +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `NamespaceLock`; + +CREATE TABLE `NamespaceLock` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id', + `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + `IsDeleted` bit(1) DEFAULT b'0' COMMENT '软删除', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_NamespaceId_DeletedAt` (`NamespaceId`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='namespace的编辑锁'; + + + +-- Dump of table release +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Release`; + +CREATE TABLE `Release` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', + `Name` varchar(64) NOT NULL DEFAULT 'default' COMMENT '发布名字', + `Comment` varchar(256) DEFAULT NULL COMMENT '发布说明', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `Configurations` longtext NOT NULL COMMENT '发布配置', + `IsAbandoned` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否废弃', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_ReleaseKey_DeletedAt` (`ReleaseKey`,`DeletedAt`), + KEY `AppId_ClusterName_GroupName` (`AppId`,`ClusterName`(191),`NamespaceName`(191)), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布'; + + +-- Dump of table releasehistory +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ReleaseHistory`; + +CREATE TABLE `ReleaseHistory` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT '发布分支名', + `ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关联的Release Id', + `PreviousReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '前一次发布的ReleaseId', + `Operation` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '发布类型,0: 普通发布,1: 回滚,2: 灰度发布,3: 灰度规则更新,4: 灰度合并回主分支发布,5: 主分支发布灰度自动发布,6: 主分支回滚灰度自动发布,7: 放弃灰度', + `OperationContext` longtext NOT NULL COMMENT '发布上下文信息', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`,`BranchName`), + KEY `IX_ReleaseId` (`ReleaseId`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_PreviousReleaseId` (`PreviousReleaseId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布历史'; + + +-- Dump of table releasemessage +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ReleaseMessage`; + +CREATE TABLE `ReleaseMessage` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Message` varchar(1024) NOT NULL DEFAULT '' COMMENT '发布的消息内容', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Message` (`Message`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布消息'; + + + +-- Dump of table serverconfig +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ServerConfig`; + +CREATE TABLE `ServerConfig` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Cluster` varchar(32) NOT NULL DEFAULT 'default' COMMENT '配置对应的集群,default为不针对特定的集群', + `Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_Key_Cluster_DeletedAt` (`Key`,`Cluster`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; + +-- Dump of table accesskey +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AccessKey`; + +CREATE TABLE `AccessKey` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Secret` varchar(128) NOT NULL DEFAULT '' COMMENT 'Secret', + `IsEnabled` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: enabled, 0: disabled', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_Secret_DeletedAt` (`AppId`,`Secret`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='访问密钥'; + + +-- Dump of table serviceregistry +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ServiceRegistry`; + +CREATE TABLE `ServiceRegistry` ( + `Id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ServiceName` VARCHAR(64) NOT NULL COMMENT '服务名', + `Uri` VARCHAR(64) NOT NULL COMMENT '服务地址', + `Cluster` VARCHAR(64) NOT NULL COMMENT '集群,可以用来标识apollo.cluster或者网络分区', + `Metadata` VARCHAR(1024) NOT NULL DEFAULT '{}' COMMENT '元数据,key value结构的json object,为了方面后面扩展功能而不需要修改表结构', + `DataChange_CreatedTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE INDEX `IX_UNIQUE_KEY` (`ServiceName`, `Uri`), + INDEX `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='注册中心'; + +-- Dump of table AuditLog +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AuditLog`; + +CREATE TABLE `AuditLog` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `TraceId` varchar(32) NOT NULL DEFAULT '' COMMENT '链路全局唯一ID', + `SpanId` varchar(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `ParentSpanId` varchar(32) DEFAULT NULL COMMENT '父跨度ID', + `FollowsFromSpanId` varchar(32) DEFAULT NULL COMMENT '上一个兄弟跨度ID', + `Operator` varchar(64) NOT NULL DEFAULT 'anonymous' COMMENT '操作人', + `OpType` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `OpName` varchar(150) NOT NULL DEFAULT 'default' COMMENT '操作名称', + `Description` varchar(200) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_TraceId` (`TraceId`), + KEY `IX_OpName` (`OpName`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_Operator` (`Operator`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志表'; + +-- Dump of table AuditLogDataInfluence +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AuditLogDataInfluence`; + +CREATE TABLE `AuditLogDataInfluence` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `SpanId` char(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `InfluenceEntityId` varchar(50) NOT NULL DEFAULT '0' COMMENT '记录ID', + `InfluenceEntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `FieldName` varchar(50) DEFAULT NULL COMMENT '字段名称', + `FieldOldValue` varchar(500) DEFAULT NULL COMMENT '字段旧值', + `FieldNewValue` varchar(500) DEFAULT NULL COMMENT '字段新值', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_SpanId` (`SpanId`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_EntityId` (`InfluenceEntityId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; + +-- Config +-- ------------------------------------------------------------ +INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`, `Comment`) +VALUES + ('eureka.service.url', 'default', 'http://localhost:8080/eureka/', 'Eureka服务Url,多个service以英文逗号分隔'), + ('namespace.lock.switch', 'default', 'false', '一次发布只能有一个人修改开关'), + ('item.key.length.limit', 'default', '128', 'item key 最大长度限制'), + ('item.value.length.limit', 'default', '20000', 'item value最大长度限制'), + ('config-service.cache.enabled', 'default', 'false', 'ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!'); + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/scripts/sql/profiles/mysql-database-not-specified/apolloportaldb.sql b/scripts/sql/profiles/mysql-database-not-specified/apolloportaldb.sql new file mode 100644 index 00000000000..e6de5a1a4a9 --- /dev/null +++ b/scripts/sql/profiles/mysql-database-not-specified/apolloportaldb.sql @@ -0,0 +1,458 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- +-- + +-- Dump of table app +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `App`; + +CREATE TABLE `App` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Name` (`Name`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用表'; + + + +-- Dump of table appnamespace +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AppNamespace`; + +CREATE TABLE `AppNamespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', + `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'app id', + `Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', + `IsPublic` bit(1) NOT NULL DEFAULT b'0' COMMENT 'namespace是否为公共', + `Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + KEY `Name_AppId` (`Name`,`AppId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用namespace定义'; + + + +-- Dump of table consumer +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Consumer`; + +CREATE TABLE `Consumer` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='开放API消费者'; + + + +-- Dump of table consumeraudit +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ConsumerAudit`; + +CREATE TABLE `ConsumerAudit` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', + `Uri` varchar(1024) NOT NULL DEFAULT '' COMMENT '访问的Uri', + `Method` varchar(16) NOT NULL DEFAULT '' COMMENT '访问的Method', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_ConsumerId` (`ConsumerId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer审计表'; + + + +-- Dump of table consumerrole +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ConsumerRole`; + +CREATE TABLE `ConsumerRole` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_ConsumerId_RoleId_DeletedAt` (`ConsumerId`,`RoleId`,`DeletedAt`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_RoleId` (`RoleId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer和role的绑定表'; + + + +-- Dump of table consumertoken +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ConsumerToken`; + +CREATE TABLE `ConsumerToken` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'ConsumerId', + `Token` varchar(128) NOT NULL DEFAULT '' COMMENT 'token', + `Expires` datetime NOT NULL DEFAULT '2099-01-01 00:00:00' COMMENT 'token失效时间', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_Token_DeletedAt` (`Token`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer token表'; + +-- Dump of table favorite +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Favorite`; + +CREATE TABLE `Favorite` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `UserId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '收藏的用户', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Position` int(32) NOT NULL DEFAULT '10000' COMMENT '收藏顺序', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_UserId_AppId_DeletedAt` (`UserId`,`AppId`,`DeletedAt`), + KEY `AppId` (`AppId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COMMENT='应用收藏表'; + +-- Dump of table permission +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Permission`; + +CREATE TABLE `Permission` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `PermissionType` varchar(32) NOT NULL DEFAULT '' COMMENT '权限类型', + `TargetId` varchar(256) NOT NULL DEFAULT '' COMMENT '权限对象类型', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_TargetId_PermissionType_DeletedAt` (`TargetId`,`PermissionType`,`DeletedAt`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='permission表'; + + + +-- Dump of table role +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Role`; + +CREATE TABLE `Role` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `RoleName` varchar(256) NOT NULL DEFAULT '' COMMENT 'Role name', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_RoleName_DeletedAt` (`RoleName`,`DeletedAt`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色表'; + + + +-- Dump of table rolepermission +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `RolePermission`; + +CREATE TABLE `RolePermission` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `PermissionId` int(10) unsigned DEFAULT NULL COMMENT 'Permission Id', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_RoleId_PermissionId_DeletedAt` (`RoleId`,`PermissionId`,`DeletedAt`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_PermissionId` (`PermissionId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色和权限的绑定表'; + + + +-- Dump of table serverconfig +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ServerConfig`; + +CREATE TABLE `ServerConfig` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_Key_DeletedAt` (`Key`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; + + + +-- Dump of table userrole +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `UserRole`; + +CREATE TABLE `UserRole` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `UserId` varchar(128) DEFAULT '' COMMENT '用户身份标识', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_UserId_RoleId_DeletedAt` (`UserId`,`RoleId`,`DeletedAt`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_RoleId` (`RoleId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户和role的绑定表'; + +-- Dump of table Users +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Users`; + +CREATE TABLE `Users` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Username` varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户登录账户', + `Password` varchar(512) NOT NULL DEFAULT 'default' COMMENT '密码', + `UserDisplayName` varchar(512) NOT NULL DEFAULT 'default' COMMENT '用户名称', + `Email` varchar(64) NOT NULL DEFAULT 'default' COMMENT '邮箱地址', + `Enabled` tinyint(4) DEFAULT NULL COMMENT '是否有效', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_Username` (`Username`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; + + +-- Dump of table Authorities +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Authorities`; + +CREATE TABLE `Authorities` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Username` varchar(64) NOT NULL, + `Authority` varchar(50) NOT NULL, + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- spring session (https://github.com/spring-projects/spring-session/blob/faee8f1bdb8822a5653a81eba838dddf224d92d6/spring-session-jdbc/src/main/resources/org/springframework/session/jdbc/schema-mysql.sql) +-- Dump of table SPRING_SESSION +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `SPRING_SESSION`; + +CREATE TABLE `SPRING_SESSION` ( + `PRIMARY_ID` char(36) NOT NULL, + `SESSION_ID` char(36) NOT NULL, + `CREATION_TIME` bigint NOT NULL, + `LAST_ACCESS_TIME` bigint NOT NULL, + `MAX_INACTIVE_INTERVAL` int NOT NULL, + `EXPIRY_TIME` bigint NOT NULL, + `PRINCIPAL_NAME` varchar(100) DEFAULT NULL, + PRIMARY KEY (`PRIMARY_ID`), + UNIQUE KEY `SPRING_SESSION_IX1` (`SESSION_ID`), + KEY `SPRING_SESSION_IX2` (`EXPIRY_TIME`), + KEY `SPRING_SESSION_IX3` (`PRINCIPAL_NAME`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; + +-- Dump of table SPRING_SESSION_ATTRIBUTES +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `SPRING_SESSION_ATTRIBUTES`; + +CREATE TABLE `SPRING_SESSION_ATTRIBUTES` ( + `SESSION_PRIMARY_ID` char(36) NOT NULL, + `ATTRIBUTE_NAME` varchar(200) NOT NULL, + `ATTRIBUTE_BYTES` blob NOT NULL, + PRIMARY KEY (`SESSION_PRIMARY_ID`,`ATTRIBUTE_NAME`), + CONSTRAINT `SPRING_SESSION_ATTRIBUTES_FK` FOREIGN KEY (`SESSION_PRIMARY_ID`) REFERENCES `SPRING_SESSION` (`PRIMARY_ID`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; + +-- Dump of table AuditLog +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AuditLog`; + +CREATE TABLE `AuditLog` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `TraceId` varchar(32) NOT NULL DEFAULT '' COMMENT '链路全局唯一ID', + `SpanId` varchar(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `ParentSpanId` varchar(32) DEFAULT NULL COMMENT '父跨度ID', + `FollowsFromSpanId` varchar(32) DEFAULT NULL COMMENT '上一个兄弟跨度ID', + `Operator` varchar(64) NOT NULL DEFAULT 'anonymous' COMMENT '操作人', + `OpType` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `OpName` varchar(150) NOT NULL DEFAULT 'default' COMMENT '操作名称', + `Description` varchar(200) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_TraceId` (`TraceId`), + KEY `IX_OpName` (`OpName`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_Operator` (`Operator`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志表'; + +-- Dump of table AuditLogDataInfluence +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AuditLogDataInfluence`; + +CREATE TABLE `AuditLogDataInfluence` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `SpanId` char(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `InfluenceEntityId` varchar(50) NOT NULL DEFAULT '0' COMMENT '记录ID', + `InfluenceEntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `FieldName` varchar(50) DEFAULT NULL COMMENT '字段名称', + `FieldOldValue` varchar(500) DEFAULT NULL COMMENT '字段旧值', + `FieldNewValue` varchar(500) DEFAULT NULL COMMENT '字段新值', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_SpanId` (`SpanId`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_EntityId` (`InfluenceEntityId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; + +-- Config +-- ------------------------------------------------------------ +INSERT INTO `ServerConfig` (`Key`, `Value`, `Comment`) +VALUES + ('apollo.portal.envs', 'dev', '可支持的环境列表'), + ('organizations', '[{"orgId":"TEST1","orgName":"样例部门1"},{"orgId":"TEST2","orgName":"样例部门2"}]', '部门列表'), + ('superAdmin', 'apollo', 'Portal超级管理员'), + ('api.readTimeout', '10000', 'http接口read timeout'), + ('consumer.token.salt', 'someSalt', 'consumer token salt'), + ('admin.createPrivateNamespace.switch', 'true', '是否允许项目管理员创建私有namespace'), + ('configView.memberOnly.envs', 'pro', '只对项目成员显示配置信息的环境列表,多个env以英文逗号分隔'), + ('apollo.portal.meta.servers', '{}', '各环境Meta Service列表'); + + +INSERT INTO `Users` (`Username`, `Password`, `UserDisplayName`, `Email`, `Enabled`) +VALUES + ('apollo', '$2a$10$7r20uS.BQ9uBpf3Baj3uQOZvMVvB1RN3PYoKE94gtz2.WAOuiiwXS', 'apollo', 'apollo@acme.com', 1); + +INSERT INTO `Authorities` (`Username`, `Authority`) VALUES ('apollo', 'ROLE_user'); + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/scripts/sql/profiles/mysql-database-not-specified/delta/v220-v230/apolloconfigdb-v220-v230.sql b/scripts/sql/profiles/mysql-database-not-specified/delta/v220-v230/apolloconfigdb-v220-v230.sql new file mode 100644 index 00000000000..3f659cea710 --- /dev/null +++ b/scripts/sql/profiles/mysql-database-not-specified/delta/v220-v230/apolloconfigdb-v220-v230.sql @@ -0,0 +1,39 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v2.2.0 to v2.3.0 + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- +-- + +ALTER TABLE `Cluster` + ADD COLUMN `Comment` varchar(64) DEFAULT NULL COMMENT '备注'; + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== diff --git a/scripts/sql/profiles/mysql-database-not-specified/delta/v220-v230/apolloportaldb-v220-v230.sql b/scripts/sql/profiles/mysql-database-not-specified/delta/v220-v230/apolloportaldb-v220-v230.sql new file mode 100644 index 00000000000..9f8443856a1 --- /dev/null +++ b/scripts/sql/profiles/mysql-database-not-specified/delta/v220-v230/apolloportaldb-v220-v230.sql @@ -0,0 +1,37 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v2.2.0 to v2.3.0 + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- +-- + + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== diff --git a/scripts/sql/profiles/mysql-default/apolloconfigdb.sql b/scripts/sql/profiles/mysql-default/apolloconfigdb.sql new file mode 100644 index 00000000000..3736ea599f3 --- /dev/null +++ b/scripts/sql/profiles/mysql-default/apolloconfigdb.sql @@ -0,0 +1,520 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- +-- +-- Create Database +-- ------------------------------------------------------------ +CREATE DATABASE IF NOT EXISTS ApolloConfigDB DEFAULT CHARACTER SET = utf8mb4; + +Use ApolloConfigDB; + +-- Dump of table app +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `App`; + +CREATE TABLE `App` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Name` (`Name`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用表'; + + + +-- Dump of table appnamespace +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AppNamespace`; + +CREATE TABLE `AppNamespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', + `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'app id', + `Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', + `IsPublic` bit(1) NOT NULL DEFAULT b'0' COMMENT 'namespace是否为公共', + `Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + KEY `Name_AppId` (`Name`,`AppId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用namespace定义'; + + + +-- Dump of table audit +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Audit`; + +CREATE TABLE `Audit` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `EntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `EntityId` int(10) unsigned DEFAULT NULL COMMENT '记录ID', + `OpName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `Comment` varchar(500) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='日志审计表'; + + + +-- Dump of table cluster +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Cluster`; + +CREATE TABLE `Cluster` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT '集群名字', + `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'App id', + `ParentClusterId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父cluster', + `Comment` varchar(64) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + KEY `IX_ParentClusterId` (`ParentClusterId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='集群'; + + + +-- Dump of table commit +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Commit`; + +CREATE TABLE `Commit` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `ChangeSets` longtext NOT NULL COMMENT '修改变更集', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `Comment` varchar(500) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `AppId` (`AppId`), + KEY `ClusterName` (`ClusterName`(191)), + KEY `NamespaceName` (`NamespaceName`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='commit 历史表'; + +-- Dump of table grayreleaserule +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `GrayReleaseRule`; + +CREATE TABLE `GrayReleaseRule` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', + `NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', + `BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'branch name', + `Rules` varchar(16000) DEFAULT '[]' COMMENT '灰度规则', + `ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '灰度对应的release', + `BranchStatus` tinyint(2) DEFAULT '1' COMMENT '灰度分支状态: 0:删除分支,1:正在使用的规则 2:全量发布', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='灰度规则表'; + + +-- Dump of table instance +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Instance`; + +CREATE TABLE `Instance` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `DataCenter` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Data Center Name', + `Ip` varchar(32) NOT NULL DEFAULT '' COMMENT 'instance ip', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `IX_UNIQUE_KEY` (`AppId`,`ClusterName`,`Ip`,`DataCenter`), + KEY `IX_IP` (`Ip`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='使用配置的应用实例'; + + + +-- Dump of table instanceconfig +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `InstanceConfig`; + +CREATE TABLE `InstanceConfig` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `InstanceId` int(11) unsigned DEFAULT NULL COMMENT 'Instance Id', + `ConfigAppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Config App Id', + `ConfigClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Cluster Name', + `ConfigNamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Namespace Name', + `ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', + `ReleaseDeliveryTime` timestamp NULL DEFAULT NULL COMMENT '配置获取时间', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `IX_UNIQUE_KEY` (`InstanceId`,`ConfigAppId`,`ConfigNamespaceName`), + KEY `IX_ReleaseKey` (`ReleaseKey`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Valid_Namespace` (`ConfigAppId`,`ConfigClusterName`,`ConfigNamespaceName`,`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用实例的配置信息'; + + + +-- Dump of table item +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Item`; + +CREATE TABLE `Item` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', + `Key` varchar(128) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '配置项类型,0: String,1: Number,2: Boolean,3: JSON', + `Value` longtext NOT NULL COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `LineNum` int(10) unsigned DEFAULT '0' COMMENT '行号', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_GroupId` (`NamespaceId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置项目'; + + + +-- Dump of table namespace +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Namespace`; + +CREATE TABLE `Namespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_ClusterName_NamespaceName_DeletedAt` (`AppId`,`ClusterName`(191),`NamespaceName`(191),`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_NamespaceName` (`NamespaceName`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='命名空间'; + + + +-- Dump of table namespacelock +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `NamespaceLock`; + +CREATE TABLE `NamespaceLock` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id', + `NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + `IsDeleted` bit(1) DEFAULT b'0' COMMENT '软删除', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_NamespaceId_DeletedAt` (`NamespaceId`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='namespace的编辑锁'; + + + +-- Dump of table release +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Release`; + +CREATE TABLE `Release` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', + `Name` varchar(64) NOT NULL DEFAULT 'default' COMMENT '发布名字', + `Comment` varchar(256) DEFAULT NULL COMMENT '发布说明', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `Configurations` longtext NOT NULL COMMENT '发布配置', + `IsAbandoned` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否废弃', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_ReleaseKey_DeletedAt` (`ReleaseKey`,`DeletedAt`), + KEY `AppId_ClusterName_GroupName` (`AppId`,`ClusterName`(191),`NamespaceName`(191)), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布'; + + +-- Dump of table releasehistory +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ReleaseHistory`; + +CREATE TABLE `ReleaseHistory` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', + `NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', + `BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT '发布分支名', + `ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关联的Release Id', + `PreviousReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '前一次发布的ReleaseId', + `Operation` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '发布类型,0: 普通发布,1: 回滚,2: 灰度发布,3: 灰度规则更新,4: 灰度合并回主分支发布,5: 主分支发布灰度自动发布,6: 主分支回滚灰度自动发布,7: 放弃灰度', + `OperationContext` longtext NOT NULL COMMENT '发布上下文信息', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`,`BranchName`), + KEY `IX_ReleaseId` (`ReleaseId`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_PreviousReleaseId` (`PreviousReleaseId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布历史'; + + +-- Dump of table releasemessage +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ReleaseMessage`; + +CREATE TABLE `ReleaseMessage` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Message` varchar(1024) NOT NULL DEFAULT '' COMMENT '发布的消息内容', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Message` (`Message`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布消息'; + + + +-- Dump of table serverconfig +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ServerConfig`; + +CREATE TABLE `ServerConfig` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Cluster` varchar(32) NOT NULL DEFAULT 'default' COMMENT '配置对应的集群,default为不针对特定的集群', + `Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_Key_Cluster_DeletedAt` (`Key`,`Cluster`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; + +-- Dump of table accesskey +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AccessKey`; + +CREATE TABLE `AccessKey` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Secret` varchar(128) NOT NULL DEFAULT '' COMMENT 'Secret', + `IsEnabled` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: enabled, 0: disabled', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_Secret_DeletedAt` (`AppId`,`Secret`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='访问密钥'; + + +-- Dump of table serviceregistry +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ServiceRegistry`; + +CREATE TABLE `ServiceRegistry` ( + `Id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ServiceName` VARCHAR(64) NOT NULL COMMENT '服务名', + `Uri` VARCHAR(64) NOT NULL COMMENT '服务地址', + `Cluster` VARCHAR(64) NOT NULL COMMENT '集群,可以用来标识apollo.cluster或者网络分区', + `Metadata` VARCHAR(1024) NOT NULL DEFAULT '{}' COMMENT '元数据,key value结构的json object,为了方面后面扩展功能而不需要修改表结构', + `DataChange_CreatedTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE INDEX `IX_UNIQUE_KEY` (`ServiceName`, `Uri`), + INDEX `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='注册中心'; + +-- Dump of table AuditLog +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AuditLog`; + +CREATE TABLE `AuditLog` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `TraceId` varchar(32) NOT NULL DEFAULT '' COMMENT '链路全局唯一ID', + `SpanId` varchar(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `ParentSpanId` varchar(32) DEFAULT NULL COMMENT '父跨度ID', + `FollowsFromSpanId` varchar(32) DEFAULT NULL COMMENT '上一个兄弟跨度ID', + `Operator` varchar(64) NOT NULL DEFAULT 'anonymous' COMMENT '操作人', + `OpType` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `OpName` varchar(150) NOT NULL DEFAULT 'default' COMMENT '操作名称', + `Description` varchar(200) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_TraceId` (`TraceId`), + KEY `IX_OpName` (`OpName`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_Operator` (`Operator`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志表'; + +-- Dump of table AuditLogDataInfluence +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AuditLogDataInfluence`; + +CREATE TABLE `AuditLogDataInfluence` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `SpanId` char(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `InfluenceEntityId` varchar(50) NOT NULL DEFAULT '0' COMMENT '记录ID', + `InfluenceEntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `FieldName` varchar(50) DEFAULT NULL COMMENT '字段名称', + `FieldOldValue` varchar(500) DEFAULT NULL COMMENT '字段旧值', + `FieldNewValue` varchar(500) DEFAULT NULL COMMENT '字段新值', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_SpanId` (`SpanId`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_EntityId` (`InfluenceEntityId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; + +-- Config +-- ------------------------------------------------------------ +INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`, `Comment`) +VALUES + ('eureka.service.url', 'default', 'http://localhost:8080/eureka/', 'Eureka服务Url,多个service以英文逗号分隔'), + ('namespace.lock.switch', 'default', 'false', '一次发布只能有一个人修改开关'), + ('item.key.length.limit', 'default', '128', 'item key 最大长度限制'), + ('item.value.length.limit', 'default', '20000', 'item value最大长度限制'), + ('config-service.cache.enabled', 'default', 'false', 'ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!'); + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/scripts/sql/profiles/mysql-default/apolloportaldb.sql b/scripts/sql/profiles/mysql-default/apolloportaldb.sql new file mode 100644 index 00000000000..264f948a53b --- /dev/null +++ b/scripts/sql/profiles/mysql-default/apolloportaldb.sql @@ -0,0 +1,463 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- +-- +-- Create Database +-- ------------------------------------------------------------ +CREATE DATABASE IF NOT EXISTS ApolloPortalDB DEFAULT CHARACTER SET = utf8mb4; + +Use ApolloPortalDB; + +-- Dump of table app +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `App`; + +CREATE TABLE `App` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_Name` (`Name`(191)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用表'; + + + +-- Dump of table appnamespace +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AppNamespace`; + +CREATE TABLE `AppNamespace` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', + `AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'app id', + `Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', + `IsPublic` bit(1) NOT NULL DEFAULT b'0' COMMENT 'namespace是否为公共', + `Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`), + KEY `Name_AppId` (`Name`,`AppId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用namespace定义'; + + + +-- Dump of table consumer +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Consumer`; + +CREATE TABLE `Consumer` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', + `OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', + `OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', + `OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', + `OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='开放API消费者'; + + + +-- Dump of table consumeraudit +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ConsumerAudit`; + +CREATE TABLE `ConsumerAudit` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', + `Uri` varchar(1024) NOT NULL DEFAULT '' COMMENT '访问的Uri', + `Method` varchar(16) NOT NULL DEFAULT '' COMMENT '访问的Method', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_ConsumerId` (`ConsumerId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer审计表'; + + + +-- Dump of table consumerrole +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ConsumerRole`; + +CREATE TABLE `ConsumerRole` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_ConsumerId_RoleId_DeletedAt` (`ConsumerId`,`RoleId`,`DeletedAt`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_RoleId` (`RoleId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer和role的绑定表'; + + + +-- Dump of table consumertoken +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ConsumerToken`; + +CREATE TABLE `ConsumerToken` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'ConsumerId', + `Token` varchar(128) NOT NULL DEFAULT '' COMMENT 'token', + `Expires` datetime NOT NULL DEFAULT '2099-01-01 00:00:00' COMMENT 'token失效时间', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_Token_DeletedAt` (`Token`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer token表'; + +-- Dump of table favorite +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Favorite`; + +CREATE TABLE `Favorite` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `UserId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '收藏的用户', + `AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', + `Position` int(32) NOT NULL DEFAULT '10000' COMMENT '收藏顺序', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_UserId_AppId_DeletedAt` (`UserId`,`AppId`,`DeletedAt`), + KEY `AppId` (`AppId`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COMMENT='应用收藏表'; + +-- Dump of table permission +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Permission`; + +CREATE TABLE `Permission` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `PermissionType` varchar(32) NOT NULL DEFAULT '' COMMENT '权限类型', + `TargetId` varchar(256) NOT NULL DEFAULT '' COMMENT '权限对象类型', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_TargetId_PermissionType_DeletedAt` (`TargetId`,`PermissionType`,`DeletedAt`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='permission表'; + + + +-- Dump of table role +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Role`; + +CREATE TABLE `Role` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `RoleName` varchar(256) NOT NULL DEFAULT '' COMMENT 'Role name', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_RoleName_DeletedAt` (`RoleName`,`DeletedAt`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色表'; + + + +-- Dump of table rolepermission +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `RolePermission`; + +CREATE TABLE `RolePermission` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `PermissionId` int(10) unsigned DEFAULT NULL COMMENT 'Permission Id', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_RoleId_PermissionId_DeletedAt` (`RoleId`,`PermissionId`,`DeletedAt`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_PermissionId` (`PermissionId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色和权限的绑定表'; + + + +-- Dump of table serverconfig +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `ServerConfig`; + +CREATE TABLE `ServerConfig` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', + `Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', + `Comment` varchar(1024) DEFAULT '' COMMENT '注释', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_Key_DeletedAt` (`Key`,`DeletedAt`), + KEY `DataChange_LastTime` (`DataChange_LastTime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; + + + +-- Dump of table userrole +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `UserRole`; + +CREATE TABLE `UserRole` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `UserId` varchar(128) DEFAULT '' COMMENT '用户身份标识', + `RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_UserId_RoleId_DeletedAt` (`UserId`,`RoleId`,`DeletedAt`), + KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), + KEY `IX_RoleId` (`RoleId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户和role的绑定表'; + +-- Dump of table Users +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Users`; + +CREATE TABLE `Users` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Username` varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户登录账户', + `Password` varchar(512) NOT NULL DEFAULT 'default' COMMENT '密码', + `UserDisplayName` varchar(512) NOT NULL DEFAULT 'default' COMMENT '用户名称', + `Email` varchar(64) NOT NULL DEFAULT 'default' COMMENT '邮箱地址', + `Enabled` tinyint(4) DEFAULT NULL COMMENT '是否有效', + PRIMARY KEY (`Id`), + UNIQUE KEY `UK_Username` (`Username`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; + + +-- Dump of table Authorities +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `Authorities`; + +CREATE TABLE `Authorities` ( + `Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', + `Username` varchar(64) NOT NULL, + `Authority` varchar(50) NOT NULL, + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- spring session (https://github.com/spring-projects/spring-session/blob/faee8f1bdb8822a5653a81eba838dddf224d92d6/spring-session-jdbc/src/main/resources/org/springframework/session/jdbc/schema-mysql.sql) +-- Dump of table SPRING_SESSION +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `SPRING_SESSION`; + +CREATE TABLE `SPRING_SESSION` ( + `PRIMARY_ID` char(36) NOT NULL, + `SESSION_ID` char(36) NOT NULL, + `CREATION_TIME` bigint NOT NULL, + `LAST_ACCESS_TIME` bigint NOT NULL, + `MAX_INACTIVE_INTERVAL` int NOT NULL, + `EXPIRY_TIME` bigint NOT NULL, + `PRINCIPAL_NAME` varchar(100) DEFAULT NULL, + PRIMARY KEY (`PRIMARY_ID`), + UNIQUE KEY `SPRING_SESSION_IX1` (`SESSION_ID`), + KEY `SPRING_SESSION_IX2` (`EXPIRY_TIME`), + KEY `SPRING_SESSION_IX3` (`PRINCIPAL_NAME`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; + +-- Dump of table SPRING_SESSION_ATTRIBUTES +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `SPRING_SESSION_ATTRIBUTES`; + +CREATE TABLE `SPRING_SESSION_ATTRIBUTES` ( + `SESSION_PRIMARY_ID` char(36) NOT NULL, + `ATTRIBUTE_NAME` varchar(200) NOT NULL, + `ATTRIBUTE_BYTES` blob NOT NULL, + PRIMARY KEY (`SESSION_PRIMARY_ID`,`ATTRIBUTE_NAME`), + CONSTRAINT `SPRING_SESSION_ATTRIBUTES_FK` FOREIGN KEY (`SESSION_PRIMARY_ID`) REFERENCES `SPRING_SESSION` (`PRIMARY_ID`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; + +-- Dump of table AuditLog +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AuditLog`; + +CREATE TABLE `AuditLog` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `TraceId` varchar(32) NOT NULL DEFAULT '' COMMENT '链路全局唯一ID', + `SpanId` varchar(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `ParentSpanId` varchar(32) DEFAULT NULL COMMENT '父跨度ID', + `FollowsFromSpanId` varchar(32) DEFAULT NULL COMMENT '上一个兄弟跨度ID', + `Operator` varchar(64) NOT NULL DEFAULT 'anonymous' COMMENT '操作人', + `OpType` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', + `OpName` varchar(150) NOT NULL DEFAULT 'default' COMMENT '操作名称', + `Description` varchar(200) DEFAULT NULL COMMENT '备注', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_TraceId` (`TraceId`), + KEY `IX_OpName` (`OpName`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_Operator` (`Operator`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志表'; + +-- Dump of table AuditLogDataInfluence +-- ------------------------------------------------------------ + +DROP TABLE IF EXISTS `AuditLogDataInfluence`; + +CREATE TABLE `AuditLogDataInfluence` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `SpanId` char(32) NOT NULL DEFAULT '' COMMENT '跨度ID', + `InfluenceEntityId` varchar(50) NOT NULL DEFAULT '0' COMMENT '记录ID', + `InfluenceEntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', + `FieldName` varchar(50) DEFAULT NULL COMMENT '字段名称', + `FieldOldValue` varchar(500) DEFAULT NULL COMMENT '字段旧值', + `FieldNewValue` varchar(500) DEFAULT NULL COMMENT '字段新值', + `IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', + `DeletedAt` BIGINT(20) NOT NULL DEFAULT '0' COMMENT 'Delete timestamp based on milliseconds', + `DataChange_CreatedBy` varchar(64) DEFAULT NULL COMMENT '创建人邮箱前缀', + `DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', + `DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', + PRIMARY KEY (`Id`), + KEY `IX_SpanId` (`SpanId`), + KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), + KEY `IX_EntityId` (`InfluenceEntityId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; + +-- Config +-- ------------------------------------------------------------ +INSERT INTO `ServerConfig` (`Key`, `Value`, `Comment`) +VALUES + ('apollo.portal.envs', 'dev', '可支持的环境列表'), + ('organizations', '[{"orgId":"TEST1","orgName":"样例部门1"},{"orgId":"TEST2","orgName":"样例部门2"}]', '部门列表'), + ('superAdmin', 'apollo', 'Portal超级管理员'), + ('api.readTimeout', '10000', 'http接口read timeout'), + ('consumer.token.salt', 'someSalt', 'consumer token salt'), + ('admin.createPrivateNamespace.switch', 'true', '是否允许项目管理员创建私有namespace'), + ('configView.memberOnly.envs', 'pro', '只对项目成员显示配置信息的环境列表,多个env以英文逗号分隔'), + ('apollo.portal.meta.servers', '{}', '各环境Meta Service列表'); + + +INSERT INTO `Users` (`Username`, `Password`, `UserDisplayName`, `Email`, `Enabled`) +VALUES + ('apollo', '$2a$10$7r20uS.BQ9uBpf3Baj3uQOZvMVvB1RN3PYoKE94gtz2.WAOuiiwXS', 'apollo', 'apollo@acme.com', 1); + +INSERT INTO `Authorities` (`Username`, `Authority`) VALUES ('apollo', 'ROLE_user'); + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/scripts/sql/delta/v040-v050/apolloconfigdb-v040-v050.sql b/scripts/sql/profiles/mysql-default/delta/v040-v050/apolloconfigdb-v040-v050.sql similarity index 100% rename from scripts/sql/delta/v040-v050/apolloconfigdb-v040-v050.sql rename to scripts/sql/profiles/mysql-default/delta/v040-v050/apolloconfigdb-v040-v050.sql diff --git a/scripts/sql/delta/v040-v050/apolloportaldb-v040-v050.sql b/scripts/sql/profiles/mysql-default/delta/v040-v050/apolloportaldb-v040-v050.sql similarity index 100% rename from scripts/sql/delta/v040-v050/apolloportaldb-v040-v050.sql rename to scripts/sql/profiles/mysql-default/delta/v040-v050/apolloportaldb-v040-v050.sql diff --git a/scripts/sql/delta/v060-v062/apolloconfigdb-v060-v062.sql b/scripts/sql/profiles/mysql-default/delta/v060-v062/apolloconfigdb-v060-v062.sql similarity index 100% rename from scripts/sql/delta/v060-v062/apolloconfigdb-v060-v062.sql rename to scripts/sql/profiles/mysql-default/delta/v060-v062/apolloconfigdb-v060-v062.sql diff --git a/scripts/sql/delta/v060-v062/apolloportaldb-v060-v062.sql b/scripts/sql/profiles/mysql-default/delta/v060-v062/apolloportaldb-v060-v062.sql similarity index 100% rename from scripts/sql/delta/v060-v062/apolloportaldb-v060-v062.sql rename to scripts/sql/profiles/mysql-default/delta/v060-v062/apolloportaldb-v060-v062.sql diff --git a/scripts/sql/delta/v080-v090/apolloportaldb-v080-v090.sql b/scripts/sql/profiles/mysql-default/delta/v080-v090/apolloportaldb-v080-v090.sql similarity index 100% rename from scripts/sql/delta/v080-v090/apolloportaldb-v080-v090.sql rename to scripts/sql/profiles/mysql-default/delta/v080-v090/apolloportaldb-v080-v090.sql diff --git a/scripts/sql/delta/v151-v160/apolloconfigdb-v151-v160.sql b/scripts/sql/profiles/mysql-default/delta/v151-v160/apolloconfigdb-v151-v160.sql similarity index 100% rename from scripts/sql/delta/v151-v160/apolloconfigdb-v151-v160.sql rename to scripts/sql/profiles/mysql-default/delta/v151-v160/apolloconfigdb-v151-v160.sql diff --git a/scripts/sql/delta/v170-v180/apolloconfigdb-v170-v180.sql b/scripts/sql/profiles/mysql-default/delta/v170-v180/apolloconfigdb-v170-v180.sql similarity index 100% rename from scripts/sql/delta/v170-v180/apolloconfigdb-v170-v180.sql rename to scripts/sql/profiles/mysql-default/delta/v170-v180/apolloconfigdb-v170-v180.sql diff --git a/scripts/sql/delta/v170-v180/apolloportaldb-v170-v180.sql b/scripts/sql/profiles/mysql-default/delta/v170-v180/apolloportaldb-v170-v180.sql similarity index 100% rename from scripts/sql/delta/v170-v180/apolloportaldb-v170-v180.sql rename to scripts/sql/profiles/mysql-default/delta/v170-v180/apolloportaldb-v170-v180.sql diff --git a/scripts/sql/delta/v180-v190/apolloconfigdb-v180-v190.sql b/scripts/sql/profiles/mysql-default/delta/v180-v190/apolloconfigdb-v180-v190.sql similarity index 100% rename from scripts/sql/delta/v180-v190/apolloconfigdb-v180-v190.sql rename to scripts/sql/profiles/mysql-default/delta/v180-v190/apolloconfigdb-v180-v190.sql diff --git a/scripts/sql/delta/v180-v190/apolloportaldb-v180-v190.sql b/scripts/sql/profiles/mysql-default/delta/v180-v190/apolloportaldb-v180-v190.sql similarity index 100% rename from scripts/sql/delta/v180-v190/apolloportaldb-v180-v190.sql rename to scripts/sql/profiles/mysql-default/delta/v180-v190/apolloportaldb-v180-v190.sql diff --git a/scripts/sql/delta/v190-v200/apolloconfigdb-v190-v200-after.sql b/scripts/sql/profiles/mysql-default/delta/v190-v200/apolloconfigdb-v190-v200-after.sql similarity index 100% rename from scripts/sql/delta/v190-v200/apolloconfigdb-v190-v200-after.sql rename to scripts/sql/profiles/mysql-default/delta/v190-v200/apolloconfigdb-v190-v200-after.sql diff --git a/scripts/sql/delta/v190-v200/apolloconfigdb-v190-v200.sql b/scripts/sql/profiles/mysql-default/delta/v190-v200/apolloconfigdb-v190-v200.sql similarity index 100% rename from scripts/sql/delta/v190-v200/apolloconfigdb-v190-v200.sql rename to scripts/sql/profiles/mysql-default/delta/v190-v200/apolloconfigdb-v190-v200.sql diff --git a/scripts/sql/delta/v190-v200/apolloportaldb-v190-v200-after.sql b/scripts/sql/profiles/mysql-default/delta/v190-v200/apolloportaldb-v190-v200-after.sql similarity index 100% rename from scripts/sql/delta/v190-v200/apolloportaldb-v190-v200-after.sql rename to scripts/sql/profiles/mysql-default/delta/v190-v200/apolloportaldb-v190-v200-after.sql diff --git a/scripts/sql/delta/v190-v200/apolloportaldb-v190-v200.sql b/scripts/sql/profiles/mysql-default/delta/v190-v200/apolloportaldb-v190-v200.sql similarity index 100% rename from scripts/sql/delta/v190-v200/apolloportaldb-v190-v200.sql rename to scripts/sql/profiles/mysql-default/delta/v190-v200/apolloportaldb-v190-v200.sql diff --git a/scripts/sql/delta/v200-v210/apolloconfigdb-v200-v210.sql b/scripts/sql/profiles/mysql-default/delta/v200-v210/apolloconfigdb-v200-v210.sql similarity index 100% rename from scripts/sql/delta/v200-v210/apolloconfigdb-v200-v210.sql rename to scripts/sql/profiles/mysql-default/delta/v200-v210/apolloconfigdb-v200-v210.sql diff --git a/scripts/sql/delta/v210-v220/apolloconfigdb-v210-v220.sql b/scripts/sql/profiles/mysql-default/delta/v210-v220/apolloconfigdb-v210-v220.sql similarity index 98% rename from scripts/sql/delta/v210-v220/apolloconfigdb-v210-v220.sql rename to scripts/sql/profiles/mysql-default/delta/v210-v220/apolloconfigdb-v210-v220.sql index 81183f62c5e..f63cfb6f95d 100644 --- a/scripts/sql/delta/v210-v220/apolloconfigdb-v210-v220.sql +++ b/scripts/sql/profiles/mysql-default/delta/v210-v220/apolloconfigdb-v210-v220.sql @@ -13,7 +13,7 @@ -- See the License for the specific language governing permissions and -- limitations under the License. -- -# delta schema to upgrade apollo config db from v2.1.0 to v2.2.0 +-- delta schema to upgrade apollo config db from v2.1.0 to v2.2.0 Use ApolloConfigDB; @@ -90,4 +90,4 @@ CREATE TABLE `AuditLogDataInfluence` ( KEY `IX_SpanId` (`SpanId`), KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), KEY `IX_EntityId` (`InfluenceEntityId`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; diff --git a/scripts/sql/delta/v210-v220/apolloportaldb-v210-v220.sql b/scripts/sql/profiles/mysql-default/delta/v210-v220/apolloportaldb-v210-v220.sql similarity index 97% rename from scripts/sql/delta/v210-v220/apolloportaldb-v210-v220.sql rename to scripts/sql/profiles/mysql-default/delta/v210-v220/apolloportaldb-v210-v220.sql index c2c0ab7083c..9f946a4d0c1 100644 --- a/scripts/sql/delta/v210-v220/apolloportaldb-v210-v220.sql +++ b/scripts/sql/profiles/mysql-default/delta/v210-v220/apolloportaldb-v210-v220.sql @@ -13,7 +13,7 @@ -- See the License for the specific language governing permissions and -- limitations under the License. -- -# delta schema to upgrade apollo portal db from v2.1.0 to v2.2.0 +-- delta schema to upgrade apollo portal db from v2.1.0 to v2.2.0 Use ApolloPortalDB; @@ -76,4 +76,4 @@ CREATE TABLE `AuditLogDataInfluence` ( KEY `IX_SpanId` (`SpanId`), KEY `IX_DataChange_CreatedTime` (`DataChange_CreatedTime`), KEY `IX_EntityId` (`InfluenceEntityId`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; diff --git a/scripts/sql/profiles/mysql-default/delta/v220-v230/apolloconfigdb-v220-v230.sql b/scripts/sql/profiles/mysql-default/delta/v220-v230/apolloconfigdb-v220-v230.sql new file mode 100644 index 00000000000..a1defac266c --- /dev/null +++ b/scripts/sql/profiles/mysql-default/delta/v220-v230/apolloconfigdb-v220-v230.sql @@ -0,0 +1,41 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo config db from v2.2.0 to v2.3.0 + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- +-- +-- Use Database +Use ApolloConfigDB; + +ALTER TABLE `Cluster` + ADD COLUMN `Comment` varchar(64) DEFAULT NULL COMMENT '备注'; + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== diff --git a/scripts/sql/profiles/mysql-default/delta/v220-v230/apolloportaldb-v220-v230.sql b/scripts/sql/profiles/mysql-default/delta/v220-v230/apolloportaldb-v220-v230.sql new file mode 100644 index 00000000000..0ff6f7efb75 --- /dev/null +++ b/scripts/sql/profiles/mysql-default/delta/v220-v230/apolloportaldb-v220-v230.sql @@ -0,0 +1,39 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v2.2.0 to v2.3.0 + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- +-- +-- Use Database +Use ApolloPortalDB; + + +-- +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== diff --git a/scripts/sql/apolloconfigdb.sql b/scripts/sql/src/apolloconfigdb.sql similarity index 92% rename from scripts/sql/apolloconfigdb.sql rename to scripts/sql/src/apolloconfigdb.sql index 301f1ebe838..9f85a8791ce 100644 --- a/scripts/sql/apolloconfigdb.sql +++ b/scripts/sql/src/apolloconfigdb.sql @@ -21,14 +21,12 @@ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -# Create Database -# ------------------------------------------------------------ -CREATE DATABASE IF NOT EXISTS ApolloConfigDB DEFAULT CHARACTER SET = utf8mb4; +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.setupDatabase} -Use ApolloConfigDB; - -# Dump of table app -# ------------------------------------------------------------ +-- Dump of table app +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `App`; @@ -54,8 +52,8 @@ CREATE TABLE `App` ( -# Dump of table appnamespace -# ------------------------------------------------------------ +-- Dump of table appnamespace +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `AppNamespace`; @@ -80,8 +78,8 @@ CREATE TABLE `AppNamespace` ( -# Dump of table audit -# ------------------------------------------------------------ +-- Dump of table audit +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Audit`; @@ -103,8 +101,8 @@ CREATE TABLE `Audit` ( -# Dump of table cluster -# ------------------------------------------------------------ +-- Dump of table cluster +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Cluster`; @@ -128,8 +126,8 @@ CREATE TABLE `Cluster` ( -# Dump of table commit -# ------------------------------------------------------------ +-- Dump of table commit +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Commit`; @@ -153,8 +151,8 @@ CREATE TABLE `Commit` ( KEY `NamespaceName` (`NamespaceName`(191)) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='commit 历史表'; -# Dump of table grayreleaserule -# ------------------------------------------------------------ +-- Dump of table grayreleaserule +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `GrayReleaseRule`; @@ -179,8 +177,8 @@ CREATE TABLE `GrayReleaseRule` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='灰度规则表'; -# Dump of table instance -# ------------------------------------------------------------ +-- Dump of table instance +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Instance`; @@ -200,8 +198,8 @@ CREATE TABLE `Instance` ( -# Dump of table instanceconfig -# ------------------------------------------------------------ +-- Dump of table instanceconfig +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `InstanceConfig`; @@ -224,8 +222,8 @@ CREATE TABLE `InstanceConfig` ( -# Dump of table item -# ------------------------------------------------------------ +-- Dump of table item +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Item`; @@ -250,8 +248,8 @@ CREATE TABLE `Item` ( -# Dump of table namespace -# ------------------------------------------------------------ +-- Dump of table namespace +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Namespace`; @@ -274,8 +272,8 @@ CREATE TABLE `Namespace` ( -# Dump of table namespacelock -# ------------------------------------------------------------ +-- Dump of table namespacelock +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `NamespaceLock`; @@ -295,8 +293,8 @@ CREATE TABLE `NamespaceLock` ( -# Dump of table release -# ------------------------------------------------------------ +-- Dump of table release +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Release`; @@ -323,8 +321,8 @@ CREATE TABLE `Release` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布'; -# Dump of table releasehistory -# ------------------------------------------------------------ +-- Dump of table releasehistory +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `ReleaseHistory`; @@ -352,8 +350,8 @@ CREATE TABLE `ReleaseHistory` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布历史'; -# Dump of table releasemessage -# ------------------------------------------------------------ +-- Dump of table releasemessage +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `ReleaseMessage`; @@ -368,8 +366,8 @@ CREATE TABLE `ReleaseMessage` ( -# Dump of table serverconfig -# ------------------------------------------------------------ +-- Dump of table serverconfig +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `ServerConfig`; @@ -390,8 +388,8 @@ CREATE TABLE `ServerConfig` ( KEY `DataChange_LastTime` (`DataChange_LastTime`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; -# Dump of table accesskey -# ------------------------------------------------------------ +-- Dump of table accesskey +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `AccessKey`; @@ -412,8 +410,8 @@ CREATE TABLE `AccessKey` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='访问密钥'; -# Dump of table serviceregistry -# ------------------------------------------------------------ +-- Dump of table serviceregistry +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `ServiceRegistry`; @@ -430,8 +428,8 @@ CREATE TABLE `ServiceRegistry` ( INDEX `IX_DataChange_LastTime` (`DataChange_LastTime`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='注册中心'; -# Dump of table AuditLog -# ------------------------------------------------------------ +-- Dump of table AuditLog +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `AuditLog`; @@ -458,8 +456,8 @@ CREATE TABLE `AuditLog` ( KEY `IX_Operator` (`Operator`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志表'; -# Dump of table AuditLogDataInfluence -# ------------------------------------------------------------ +-- Dump of table AuditLogDataInfluence +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `AuditLogDataInfluence`; @@ -483,8 +481,8 @@ CREATE TABLE `AuditLogDataInfluence` ( KEY `IX_EntityId` (`InfluenceEntityId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; -# Config -# ------------------------------------------------------------ +-- Config +-- ------------------------------------------------------------ INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`, `Comment`) VALUES ('eureka.service.url', 'default', 'http://localhost:8080/eureka/', 'Eureka服务Url,多个service以英文逗号分隔'), @@ -493,6 +491,8 @@ VALUES ('item.value.length.limit', 'default', '20000', 'item value最大长度限制'), ('config-service.cache.enabled', 'default', 'false', 'ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!'); +-- ${gists.autoGeneratedDeclaration} + /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; diff --git a/scripts/sql/apolloportaldb.sql b/scripts/sql/src/apolloportaldb.sql similarity index 90% rename from scripts/sql/apolloportaldb.sql rename to scripts/sql/src/apolloportaldb.sql index 8af0c276f0d..323a8191149 100644 --- a/scripts/sql/apolloportaldb.sql +++ b/scripts/sql/src/apolloportaldb.sql @@ -21,14 +21,12 @@ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -# Create Database -# ------------------------------------------------------------ -CREATE DATABASE IF NOT EXISTS ApolloPortalDB DEFAULT CHARACTER SET = utf8mb4; +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.setupDatabase} -Use ApolloPortalDB; - -# Dump of table app -# ------------------------------------------------------------ +-- Dump of table app +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `App`; @@ -54,8 +52,8 @@ CREATE TABLE `App` ( -# Dump of table appnamespace -# ------------------------------------------------------------ +-- Dump of table appnamespace +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `AppNamespace`; @@ -80,8 +78,8 @@ CREATE TABLE `AppNamespace` ( -# Dump of table consumer -# ------------------------------------------------------------ +-- Dump of table consumer +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Consumer`; @@ -106,8 +104,8 @@ CREATE TABLE `Consumer` ( -# Dump of table consumeraudit -# ------------------------------------------------------------ +-- Dump of table consumeraudit +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `ConsumerAudit`; @@ -125,8 +123,8 @@ CREATE TABLE `ConsumerAudit` ( -# Dump of table consumerrole -# ------------------------------------------------------------ +-- Dump of table consumerrole +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `ConsumerRole`; @@ -148,8 +146,8 @@ CREATE TABLE `ConsumerRole` ( -# Dump of table consumertoken -# ------------------------------------------------------------ +-- Dump of table consumertoken +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `ConsumerToken`; @@ -169,8 +167,8 @@ CREATE TABLE `ConsumerToken` ( KEY `DataChange_LastTime` (`DataChange_LastTime`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer token表'; -# Dump of table favorite -# ------------------------------------------------------------ +-- Dump of table favorite +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Favorite`; @@ -191,8 +189,8 @@ CREATE TABLE `Favorite` ( KEY `DataChange_LastTime` (`DataChange_LastTime`) ) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COMMENT='应用收藏表'; -# Dump of table permission -# ------------------------------------------------------------ +-- Dump of table permission +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Permission`; @@ -213,8 +211,8 @@ CREATE TABLE `Permission` ( -# Dump of table role -# ------------------------------------------------------------ +-- Dump of table role +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Role`; @@ -234,8 +232,8 @@ CREATE TABLE `Role` ( -# Dump of table rolepermission -# ------------------------------------------------------------ +-- Dump of table rolepermission +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `RolePermission`; @@ -257,8 +255,8 @@ CREATE TABLE `RolePermission` ( -# Dump of table serverconfig -# ------------------------------------------------------------ +-- Dump of table serverconfig +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `ServerConfig`; @@ -280,8 +278,8 @@ CREATE TABLE `ServerConfig` ( -# Dump of table userrole -# ------------------------------------------------------------ +-- Dump of table userrole +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `UserRole`; @@ -301,8 +299,8 @@ CREATE TABLE `UserRole` ( KEY `IX_RoleId` (`RoleId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户和role的绑定表'; -# Dump of table Users -# ------------------------------------------------------------ +-- Dump of table Users +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Users`; @@ -318,8 +316,8 @@ CREATE TABLE `Users` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; -# Dump of table Authorities -# ------------------------------------------------------------ +-- Dump of table Authorities +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `Authorities`; @@ -331,8 +329,8 @@ CREATE TABLE `Authorities` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- spring session (https://github.com/spring-projects/spring-session/blob/faee8f1bdb8822a5653a81eba838dddf224d92d6/spring-session-jdbc/src/main/resources/org/springframework/session/jdbc/schema-mysql.sql) -# Dump of table SPRING_SESSION -# ------------------------------------------------------------ +-- Dump of table SPRING_SESSION +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `SPRING_SESSION`; @@ -350,8 +348,8 @@ CREATE TABLE `SPRING_SESSION` ( KEY `SPRING_SESSION_IX3` (`PRINCIPAL_NAME`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; -# Dump of table SPRING_SESSION_ATTRIBUTES -# ------------------------------------------------------------ +-- Dump of table SPRING_SESSION_ATTRIBUTES +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `SPRING_SESSION_ATTRIBUTES`; @@ -363,8 +361,8 @@ CREATE TABLE `SPRING_SESSION_ATTRIBUTES` ( CONSTRAINT `SPRING_SESSION_ATTRIBUTES_FK` FOREIGN KEY (`SESSION_PRIMARY_ID`) REFERENCES `SPRING_SESSION` (`PRIMARY_ID`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; -# Dump of table AuditLog -# ------------------------------------------------------------ +-- Dump of table AuditLog +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `AuditLog`; @@ -391,8 +389,8 @@ CREATE TABLE `AuditLog` ( KEY `IX_Operator` (`Operator`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志表'; -# Dump of table AuditLogDataInfluence -# ------------------------------------------------------------ +-- Dump of table AuditLogDataInfluence +-- ------------------------------------------------------------ DROP TABLE IF EXISTS `AuditLogDataInfluence`; @@ -416,12 +414,12 @@ CREATE TABLE `AuditLogDataInfluence` ( KEY `IX_EntityId` (`InfluenceEntityId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='审计日志数据变动表'; -# Config -# ------------------------------------------------------------ +-- Config +-- ------------------------------------------------------------ INSERT INTO `ServerConfig` (`Key`, `Value`, `Comment`) VALUES ('apollo.portal.envs', 'dev', '可支持的环境列表'), - ('organizations', '[{\"orgId\":\"TEST1\",\"orgName\":\"样例部门1\"},{\"orgId\":\"TEST2\",\"orgName\":\"样例部门2\"}]', '部门列表'), + ('organizations', '[{"orgId":"TEST1","orgName":"样例部门1"},{"orgId":"TEST2","orgName":"样例部门2"}]', '部门列表'), ('superAdmin', 'apollo', 'Portal超级管理员'), ('api.readTimeout', '10000', 'http接口read timeout'), ('consumer.token.salt', 'someSalt', 'consumer token salt'), @@ -436,9 +434,11 @@ VALUES INSERT INTO `Authorities` (`Username`, `Authority`) VALUES ('apollo', 'ROLE_user'); +-- ${gists.autoGeneratedDeclaration} + /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; \ No newline at end of file +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/scripts/sql/delta/v220-v230/apolloconfigdb-v220-v230.sql b/scripts/sql/src/delta/v220-v230/apolloconfigdb-v220-v230.sql similarity index 78% rename from scripts/sql/delta/v220-v230/apolloconfigdb-v220-v230.sql rename to scripts/sql/src/delta/v220-v230/apolloconfigdb-v220-v230.sql index 412b67f5fd2..b072cf9f311 100644 --- a/scripts/sql/delta/v220-v230/apolloconfigdb-v220-v230.sql +++ b/scripts/sql/src/delta/v220-v230/apolloconfigdb-v220-v230.sql @@ -13,9 +13,13 @@ -- See the License for the specific language governing permissions and -- limitations under the License. -- -# delta schema to upgrade apollo config db from v2.2.0 to v2.3.0 +-- delta schema to upgrade apollo config db from v2.2.0 to v2.3.0 -Use ApolloConfigDB; +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} ALTER TABLE `Cluster` - ADD COLUMN `Comment` varchar(64) DEFAULT NULL COMMENT '备注'; \ No newline at end of file + ADD COLUMN `Comment` varchar(64) DEFAULT NULL COMMENT '备注'; + +-- ${gists.autoGeneratedDeclaration} diff --git a/scripts/sql/src/delta/v220-v230/apolloportaldb-v220-v230.sql b/scripts/sql/src/delta/v220-v230/apolloportaldb-v220-v230.sql new file mode 100644 index 00000000000..cdfa354b3c3 --- /dev/null +++ b/scripts/sql/src/delta/v220-v230/apolloportaldb-v220-v230.sql @@ -0,0 +1,23 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- delta schema to upgrade apollo portal db from v2.2.0 to v2.3.0 + +-- ${gists.autoGeneratedDeclaration} +-- ${gists.h2Function} +-- ${gists.useDatabase} + + +-- ${gists.autoGeneratedDeclaration} diff --git a/scripts/sql/src/gist/autoGeneratedDeclaration.sql b/scripts/sql/src/gist/autoGeneratedDeclaration.sql new file mode 100644 index 00000000000..d3a2fe50f5c --- /dev/null +++ b/scripts/sql/src/gist/autoGeneratedDeclaration.sql @@ -0,0 +1,24 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- @@gist-start@@ +-- =============================================================================== +-- == == +-- == Generated from 'scripts/sql/src/' == +-- == by running 'mvn compile -pl apollo-build-sql-converter -Psql-converter'. == +-- == DO NOT EDIT !!! == +-- == == +-- =============================================================================== +-- @@gist-end@@ diff --git a/scripts/sql/src/gist/h2Function.sql b/scripts/sql/src/gist/h2Function.sql new file mode 100644 index 00000000000..e50d37950f7 --- /dev/null +++ b/scripts/sql/src/gist/h2Function.sql @@ -0,0 +1,22 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- @@gist-start@@ + +-- H2 Function +-- ------------------------------------------------------------ +CREATE ALIAS IF NOT EXISTS UNIX_TIMESTAMP FOR "com.ctrip.framework.apollo.common.jpa.H2Function.unixTimestamp"; + +-- @@gist-end@@ diff --git a/scripts/sql/src/gist/setupDatabase.sql b/scripts/sql/src/gist/setupDatabase.sql new file mode 100644 index 00000000000..8497b44cfec --- /dev/null +++ b/scripts/sql/src/gist/setupDatabase.sql @@ -0,0 +1,22 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- @@gist-start@@ +-- Create Database +-- ------------------------------------------------------------ +CREATE DATABASE IF NOT EXISTS ApolloAssemblyDB DEFAULT CHARACTER SET = utf8mb4; + +Use ApolloAssemblyDB; +-- @@gist-end@@ diff --git a/scripts/sql/src/gist/useDatabase.sql b/scripts/sql/src/gist/useDatabase.sql new file mode 100644 index 00000000000..71f17586d84 --- /dev/null +++ b/scripts/sql/src/gist/useDatabase.sql @@ -0,0 +1,19 @@ +-- +-- Copyright 2024 Apollo Authors +-- +-- 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. +-- +-- @@gist-start@@ +-- Use Database +Use ApolloAssemblyDB; +-- @@gist-end@@