From 169e311dceedb5e81491f5cee2f747623073d5fe Mon Sep 17 00:00:00 2001 From: yh263208 Date: Fri, 8 Sep 2023 12:28:17 +0800 Subject: [PATCH 1/2] refactor(migrates): add some abstract methods for migrates --- .../BootstrapSchemaHistoryRepository.java | 156 ++++++++++++++++++ .../core/migrate/MigrateConfiguration.java | 8 - .../oceanbase/odc/core/migrate/Migrates.java | 9 +- .../core/migrate/SchemaHistoryRepository.java | 131 ++------------- ...BootstrapSchemaHistoryRepositoryTest.java} | 6 +- .../odc/core/migrate/MigratesTest.java | 17 +- .../odc/migrate/AbstractMetaDBMigrate.java | 4 +- 7 files changed, 187 insertions(+), 144 deletions(-) create mode 100644 server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepository.java rename server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/{SchemaHistoryRepositoryTest.java => BootstrapSchemaHistoryRepositoryTest.java} (94%) diff --git a/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepository.java b/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepository.java new file mode 100644 index 0000000000..868d806f9e --- /dev/null +++ b/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepository.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2023 OceanBase. + * + * 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.oceanbase.odc.core.migrate; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.List; + +import javax.sql.DataSource; + +import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.jdbc.core.namedparam.SqlParameterSource; +import org.springframework.jdbc.core.simple.SimpleJdbcInsert; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +import org.springframework.util.CollectionUtils; + +import com.oceanbase.odc.common.util.ResourceUtils; + +import lombok.extern.slf4j.Slf4j; + +/** + * schema history persistent, the table schema define in migrate_schema_history_table_template.sql + * + * @author yizhou.xw + * @version : SchemaHistoryRepository.java, v 0.1 2021-03-26 14:26 + */ +@Slf4j +public class BootstrapSchemaHistoryRepository implements SchemaHistoryRepository { + + private static final String DEFAULT_TABLE = "migrate_schema_history"; + private final String TABLE_TEMPLATE_FILE_NAME = "migrate_schema_history_table_template.sql"; + private final String ALL_COLUMNS = "install_rank, version, description, type, script, checksum," + + " installed_by, installed_on, execution_millis, success"; + + private final DataSource dataSource; + private final JdbcTemplate jdbcTemplate; + private final NamedParameterJdbcTemplate namedJdbcTemplate; + + private final SimpleJdbcInsert simpleJdbcInsert; + private final String table; + + public BootstrapSchemaHistoryRepository(String table, DataSource dataSource) { + Validate.notBlank(table, "parameter table may not be blank"); + Validate.notNull(dataSource, "parameter dataSource may not be null"); + + this.dataSource = dataSource; + this.table = table; + this.jdbcTemplate = new JdbcTemplate(dataSource); + this.namedJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); + this.simpleJdbcInsert = new SimpleJdbcInsert(jdbcTemplate).withTableName(table) + .usingGeneratedKeyColumns("install_rank"); + + try { + initialize(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException("Initialize schema history repository failed", e); + } + } + + public BootstrapSchemaHistoryRepository(DataSource dataSource) { + this(DEFAULT_TABLE, dataSource); + } + + @Override + public List listAll() { + String sql = new StringBuilder() + .append("select ") + .append(ALL_COLUMNS) + .append(" from ") + .append("`").append(table).append("`") + .toString(); + return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SchemaHistory.class)); + } + + @Override + public List listSuccess() { + String selectLatestInstallRank = new StringBuilder() + .append("select ") + .append(" max(install_rank) as install_rank") + .append(" from ") + .append("`").append(table).append("`") + .append(" where `success`=1") + .append(" group by version, script") + .toString(); + String selectInstallRankIn = new StringBuilder() + .append("select ") + .append(ALL_COLUMNS) + .append(" from ") + .append("`").append(table).append("`") + .append(" where install_rank in (:installRanks)") + .toString(); + List installRanks = jdbcTemplate.queryForList(selectLatestInstallRank, Long.class); + if (CollectionUtils.isEmpty(installRanks)) { + return Collections.emptyList(); + } + MapSqlParameterSource parameterSource = new MapSqlParameterSource(); + parameterSource.addValue("installRanks", installRanks); + return namedJdbcTemplate.query(selectInstallRankIn, parameterSource, + new BeanPropertyRowMapper<>(SchemaHistory.class)); + } + + @Override + public SchemaHistory create(SchemaHistory schemaHistory) { + if (StringUtils.isEmpty(schemaHistory.getInstalledBy())) { + schemaHistory.setInstalledBy(currentUser()); + } + SqlParameterSource beanPropertySqlParameterSource = new BeanPropertySqlParameterSource(schemaHistory); + Number installRank = simpleJdbcInsert.executeAndReturnKey(beanPropertySqlParameterSource); + schemaHistory.setInstallRank(installRank.longValue()); + log.info("schema history created, history={}", schemaHistory); + return schemaHistory; + } + + private void initialize() throws IOException, ClassNotFoundException { + String content; + try (InputStream inputStream = ResourceUtils.getFileAsStream(TABLE_TEMPLATE_FILE_NAME)) { + content = IOUtils.toString(inputStream, Charsets.UTF_8); + } + String replaced = StringUtils.replace(content, "${schema_history}", table); + ByteArrayResource resource = new ByteArrayResource(replaced.getBytes(Charsets.UTF_8)); + + ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(resource); + databasePopulator.setSqlScriptEncoding("UTF-8"); + databasePopulator.execute(dataSource); + log.info("Schema history repository initialized."); + } + + String currentUser() { + String sql = "select CURRENT_USER() as user_name FROM DUAL"; + return jdbcTemplate.queryForObject(sql, String.class); + } + +} diff --git a/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/MigrateConfiguration.java b/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/MigrateConfiguration.java index 119a67cab7..4f3e9bb162 100644 --- a/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/MigrateConfiguration.java +++ b/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/MigrateConfiguration.java @@ -34,19 +34,11 @@ @Data @Builder public class MigrateConfiguration { - private static final String DEFAULT_TABLE = "migrate_schema_history"; /** * dataSource for connect to target database, the history table will also be created into */ private DataSource dataSource; - - /** - * schema history table name - */ - @Builder.Default - private String historyTable = DEFAULT_TABLE; - /** * if run in dry mode */ diff --git a/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/Migrates.java b/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/Migrates.java index 73ca0f6477..b94614c621 100644 --- a/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/Migrates.java +++ b/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/Migrates.java @@ -56,16 +56,17 @@ */ @Slf4j public class Migrates { + private final MigrateConfiguration configuration; private final SchemaHistoryRepository repository; private final Map> version2Histories; private final List migrateMetas = new LinkedList<>(); - public Migrates(MigrateConfiguration configuration) { + public Migrates(MigrateConfiguration configuration, SchemaHistoryRepository repository) { this.configuration = configuration; - this.repository = new SchemaHistoryRepository(configuration.getHistoryTable(), configuration.getDataSource()); - this.version2Histories = repository.listSuccess().stream().collect( - Collectors.groupingBy(SchemaHistory::getVersion)); + this.repository = repository; + this.version2Histories = repository.listSuccess().stream() + .collect(Collectors.groupingBy(SchemaHistory::getVersion)); initResourceManager(configuration); } diff --git a/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/SchemaHistoryRepository.java b/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/SchemaHistoryRepository.java index 2371978a0d..2c264aafc1 100644 --- a/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/SchemaHistoryRepository.java +++ b/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/SchemaHistoryRepository.java @@ -13,135 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.oceanbase.odc.core.migrate; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collections; import java.util.List; -import javax.sql.DataSource; - -import org.apache.commons.io.Charsets; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.Validate; -import org.springframework.core.io.ByteArrayResource; -import org.springframework.jdbc.core.BeanPropertyRowMapper; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; -import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import org.springframework.jdbc.core.namedparam.SqlParameterSource; -import org.springframework.jdbc.core.simple.SimpleJdbcInsert; -import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; -import org.springframework.util.CollectionUtils; - -import com.oceanbase.odc.common.util.ResourceUtils; - -import lombok.extern.slf4j.Slf4j; - /** - * schema history persistent, the table schema define in migrate_schema_history_table_template.sql - * - * @author yizhou.xw - * @version : SchemaHistoryRepository.java, v 0.1 2021-03-26 14:26 + * {@link SchemaHistoryRepository} + * + * @author yh263208 + * @date 2023-09-08 12:20 + * @since ODC-release_4.2.1 */ -@Slf4j -class SchemaHistoryRepository { - private final String TABLE_TEMPLATE_FILE_NAME = "migrate_schema_history_table_template.sql"; - private final String ALL_COLUMNS = "install_rank, version, description, type, script, checksum," - + " installed_by, installed_on, execution_millis, success"; - - private final DataSource dataSource; - private final JdbcTemplate jdbcTemplate; - private final NamedParameterJdbcTemplate namedJdbcTemplate; - - private final SimpleJdbcInsert simpleJdbcInsert; - private final String table; - - public SchemaHistoryRepository(String table, DataSource dataSource) { - Validate.notBlank(table, "parameter table may not be blank"); - Validate.notNull(dataSource, "parameter dataSource may not be null"); - - this.dataSource = dataSource; - this.table = table; - this.jdbcTemplate = new JdbcTemplate(dataSource); - this.namedJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); - this.simpleJdbcInsert = new SimpleJdbcInsert(jdbcTemplate).withTableName(table) - .usingGeneratedKeyColumns("install_rank"); - - try { - initialize(); - } catch (IOException | ClassNotFoundException e) { - throw new RuntimeException("Initialize schema history repository failed", e); - } - } - - public List listAll() { - String sql = new StringBuilder() - .append("select ") - .append(ALL_COLUMNS) - .append(" from ") - .append("`").append(table).append("`") - .toString(); - return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SchemaHistory.class)); - } - - public List listSuccess() { - String selectLatestInstallRank = new StringBuilder() - .append("select ") - .append(" max(install_rank) as install_rank") - .append(" from ") - .append("`").append(table).append("`") - .append(" where `success`=1") - .append(" group by version, script") - .toString(); - String selectInstallRankIn = new StringBuilder() - .append("select ") - .append(ALL_COLUMNS) - .append(" from ") - .append("`").append(table).append("`") - .append(" where install_rank in (:installRanks)") - .toString(); - List installRanks = jdbcTemplate.queryForList(selectLatestInstallRank, Long.class); - if (CollectionUtils.isEmpty(installRanks)) { - return Collections.emptyList(); - } - MapSqlParameterSource parameterSource = new MapSqlParameterSource(); - parameterSource.addValue("installRanks", installRanks); - return namedJdbcTemplate.query(selectInstallRankIn, parameterSource, - new BeanPropertyRowMapper<>(SchemaHistory.class)); - } - - public SchemaHistory create(SchemaHistory schemaHistory) { - if (StringUtils.isEmpty(schemaHistory.getInstalledBy())) { - schemaHistory.setInstalledBy(currentUser()); - } - SqlParameterSource beanPropertySqlParameterSource = new BeanPropertySqlParameterSource(schemaHistory); - Number installRank = simpleJdbcInsert.executeAndReturnKey(beanPropertySqlParameterSource); - schemaHistory.setInstallRank(installRank.longValue()); - log.info("schema history created, history={}", schemaHistory); - return schemaHistory; - } +public interface SchemaHistoryRepository { - private void initialize() throws IOException, ClassNotFoundException { - String content; - try (InputStream inputStream = ResourceUtils.getFileAsStream(TABLE_TEMPLATE_FILE_NAME)) { - content = IOUtils.toString(inputStream, Charsets.UTF_8); - } - String replaced = StringUtils.replace(content, "${schema_history}", table); - ByteArrayResource resource = new ByteArrayResource(replaced.getBytes(Charsets.UTF_8)); + List listAll(); - ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(resource); - databasePopulator.setSqlScriptEncoding("UTF-8"); - databasePopulator.execute(dataSource); - log.info("Schema history repository initialized."); - } + List listSuccess(); - String currentUser() { - String sql = "select CURRENT_USER() as user_name FROM DUAL"; - return jdbcTemplate.queryForObject(sql, String.class); - } + SchemaHistory create(SchemaHistory schemaHistory); } diff --git a/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/SchemaHistoryRepositoryTest.java b/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepositoryTest.java similarity index 94% rename from server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/SchemaHistoryRepositoryTest.java rename to server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepositoryTest.java index a3169c7911..d1bbb2436a 100644 --- a/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/SchemaHistoryRepositoryTest.java +++ b/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepositoryTest.java @@ -29,11 +29,11 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.SingleConnectionDataSource; -public class SchemaHistoryRepositoryTest { +public class BootstrapSchemaHistoryRepositoryTest { private static final String JDBC_URL = "jdbc:h2:mem:test;MODE=MySQL"; - private SchemaHistoryRepository repository; + private BootstrapSchemaHistoryRepository repository; private Timestamp now = Timestamp.from(Instant.now()); private DataSource dataSource; @@ -41,7 +41,7 @@ public class SchemaHistoryRepositoryTest { public void setUp() throws Exception { Class.forName("org.h2.Driver"); dataSource = new SingleConnectionDataSource(JDBC_URL, false); - repository = new SchemaHistoryRepository("migrate_schema_history", dataSource); + repository = new BootstrapSchemaHistoryRepository("migrate_schema_history", dataSource); } @After diff --git a/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/MigratesTest.java b/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/MigratesTest.java index 58cd11dbc1..22b151c101 100644 --- a/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/MigratesTest.java +++ b/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/MigratesTest.java @@ -58,7 +58,8 @@ public void migrate_Success() { .basePackages(Arrays.asList("com.oceanbase.odc.core.migrate")) .build(); - Migrates migrates = new Migrates(configuration); + Migrates migrates = new Migrates(configuration, + new BootstrapSchemaHistoryRepository(configuration.getDataSource())); migrates.migrate(); @@ -76,7 +77,7 @@ public void migrate_InitVersionEqualsMax_SkipExecuteButFillHistory() { .resourceLocations(Collections.singletonList("migrate/migrate")) .basePackages(Arrays.asList("com.oceanbase.odc.core.migrate")) .build(); - new Migrates(init).migrate(); + new Migrates(init, new BootstrapSchemaHistoryRepository(init.getDataSource())).migrate(); new JdbcTemplate(dataSource).execute("drop table migrate_schema_history"); MigrateConfiguration second = MigrateConfiguration.builder() @@ -86,7 +87,7 @@ public void migrate_InitVersionEqualsMax_SkipExecuteButFillHistory() { .initVersion("1.3.2") .build(); - new Migrates(second).migrate(); + new Migrates(second, new BootstrapSchemaHistoryRepository(second.getDataSource())).migrate(); Long rowCount = new JdbcTemplate(dataSource) .queryForObject("select count(*) from migrate_schema_history where script like '%V%'", Long.class); @@ -103,7 +104,8 @@ public void migrate_BasePackageContainsNoImplement_Exception() { thrown.expectMessage("no JdbcMigratable implementation found under basePackages"); - Migrates migrates = new Migrates(configuration); + Migrates migrates = new Migrates(configuration, + new BootstrapSchemaHistoryRepository(configuration.getDataSource())); migrates.migrate(); } @@ -116,8 +118,8 @@ public void migrate_Degrade_Exception() { .build(); // prepare - SchemaHistoryRepository repository = - new SchemaHistoryRepository(configuration.getHistoryTable(), configuration.getDataSource()); + BootstrapSchemaHistoryRepository repository = + new BootstrapSchemaHistoryRepository(configuration.getDataSource()); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update( "INSERT INTO `migrate_schema_history` (`install_rank`,`version`,`description`,`type`,`script`,`checksum`," @@ -137,7 +139,8 @@ public void migrate_Degrade_Exception() { thrown.expectMessage( "Software degrade is not allowed, please check your ODC version which should be greater than or equal to 3.4.0"); - Migrates migrates = new Migrates(configuration); + Migrates migrates = new Migrates(configuration, + new BootstrapSchemaHistoryRepository(configuration.getDataSource())); migrates.migrate(); } diff --git a/server/odc-migrate/src/main/java/com/oceanbase/odc/migrate/AbstractMetaDBMigrate.java b/server/odc-migrate/src/main/java/com/oceanbase/odc/migrate/AbstractMetaDBMigrate.java index d7f1df0798..d6df236c0c 100644 --- a/server/odc-migrate/src/main/java/com/oceanbase/odc/migrate/AbstractMetaDBMigrate.java +++ b/server/odc-migrate/src/main/java/com/oceanbase/odc/migrate/AbstractMetaDBMigrate.java @@ -35,6 +35,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import com.oceanbase.odc.common.lang.Holder; +import com.oceanbase.odc.core.migrate.BootstrapSchemaHistoryRepository; import com.oceanbase.odc.core.migrate.MigrateConfiguration; import com.oceanbase.odc.core.migrate.Migrates; @@ -71,7 +72,8 @@ public void migrate() throws InterruptedException { log.info("init configuration success, migrate starting, initVersion={}", configuration.getInitVersion()); - new Migrates(configuration).migrate(); + new Migrates(configuration, new BootstrapSchemaHistoryRepository( + configuration.getDataSource())).migrate(); log.info("migrate success"); } finally { lock.unlock(); From 9623326d3f83a63889939d39af0baa10d022b09e Mon Sep 17 00:00:00 2001 From: yh263208 Date: Fri, 8 Sep 2023 15:48:40 +0800 Subject: [PATCH 2/2] refactor(migrates): add some abstract methods for migrates --- ...ry.java => DefaultSchemaHistoryRepository.java} | 6 +++--- ...ava => DefaultSchemaHistoryRepositoryTest.java} | 6 +++--- .../oceanbase/odc/core/migrate/MigratesTest.java | 14 +++++++------- .../odc/migrate/AbstractMetaDBMigrate.java | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) rename server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/{BootstrapSchemaHistoryRepository.java => DefaultSchemaHistoryRepository.java} (96%) rename server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/{BootstrapSchemaHistoryRepositoryTest.java => DefaultSchemaHistoryRepositoryTest.java} (94%) diff --git a/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepository.java b/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/DefaultSchemaHistoryRepository.java similarity index 96% rename from server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepository.java rename to server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/DefaultSchemaHistoryRepository.java index 868d806f9e..d09fd12b25 100644 --- a/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepository.java +++ b/server/odc-core/src/main/java/com/oceanbase/odc/core/migrate/DefaultSchemaHistoryRepository.java @@ -48,7 +48,7 @@ * @version : SchemaHistoryRepository.java, v 0.1 2021-03-26 14:26 */ @Slf4j -public class BootstrapSchemaHistoryRepository implements SchemaHistoryRepository { +public class DefaultSchemaHistoryRepository implements SchemaHistoryRepository { private static final String DEFAULT_TABLE = "migrate_schema_history"; private final String TABLE_TEMPLATE_FILE_NAME = "migrate_schema_history_table_template.sql"; @@ -62,7 +62,7 @@ public class BootstrapSchemaHistoryRepository implements SchemaHistoryRepository private final SimpleJdbcInsert simpleJdbcInsert; private final String table; - public BootstrapSchemaHistoryRepository(String table, DataSource dataSource) { + public DefaultSchemaHistoryRepository(String table, DataSource dataSource) { Validate.notBlank(table, "parameter table may not be blank"); Validate.notNull(dataSource, "parameter dataSource may not be null"); @@ -80,7 +80,7 @@ public BootstrapSchemaHistoryRepository(String table, DataSource dataSource) { } } - public BootstrapSchemaHistoryRepository(DataSource dataSource) { + public DefaultSchemaHistoryRepository(DataSource dataSource) { this(DEFAULT_TABLE, dataSource); } diff --git a/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepositoryTest.java b/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/DefaultSchemaHistoryRepositoryTest.java similarity index 94% rename from server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepositoryTest.java rename to server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/DefaultSchemaHistoryRepositoryTest.java index d1bbb2436a..726960b5aa 100644 --- a/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/BootstrapSchemaHistoryRepositoryTest.java +++ b/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/DefaultSchemaHistoryRepositoryTest.java @@ -29,11 +29,11 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.SingleConnectionDataSource; -public class BootstrapSchemaHistoryRepositoryTest { +public class DefaultSchemaHistoryRepositoryTest { private static final String JDBC_URL = "jdbc:h2:mem:test;MODE=MySQL"; - private BootstrapSchemaHistoryRepository repository; + private DefaultSchemaHistoryRepository repository; private Timestamp now = Timestamp.from(Instant.now()); private DataSource dataSource; @@ -41,7 +41,7 @@ public class BootstrapSchemaHistoryRepositoryTest { public void setUp() throws Exception { Class.forName("org.h2.Driver"); dataSource = new SingleConnectionDataSource(JDBC_URL, false); - repository = new BootstrapSchemaHistoryRepository("migrate_schema_history", dataSource); + repository = new DefaultSchemaHistoryRepository("migrate_schema_history", dataSource); } @After diff --git a/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/MigratesTest.java b/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/MigratesTest.java index 22b151c101..e00ccf2e1d 100644 --- a/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/MigratesTest.java +++ b/server/odc-core/src/test/java/com/oceanbase/odc/core/migrate/MigratesTest.java @@ -59,7 +59,7 @@ public void migrate_Success() { .build(); Migrates migrates = new Migrates(configuration, - new BootstrapSchemaHistoryRepository(configuration.getDataSource())); + new DefaultSchemaHistoryRepository(configuration.getDataSource())); migrates.migrate(); @@ -77,7 +77,7 @@ public void migrate_InitVersionEqualsMax_SkipExecuteButFillHistory() { .resourceLocations(Collections.singletonList("migrate/migrate")) .basePackages(Arrays.asList("com.oceanbase.odc.core.migrate")) .build(); - new Migrates(init, new BootstrapSchemaHistoryRepository(init.getDataSource())).migrate(); + new Migrates(init, new DefaultSchemaHistoryRepository(init.getDataSource())).migrate(); new JdbcTemplate(dataSource).execute("drop table migrate_schema_history"); MigrateConfiguration second = MigrateConfiguration.builder() @@ -87,7 +87,7 @@ public void migrate_InitVersionEqualsMax_SkipExecuteButFillHistory() { .initVersion("1.3.2") .build(); - new Migrates(second, new BootstrapSchemaHistoryRepository(second.getDataSource())).migrate(); + new Migrates(second, new DefaultSchemaHistoryRepository(second.getDataSource())).migrate(); Long rowCount = new JdbcTemplate(dataSource) .queryForObject("select count(*) from migrate_schema_history where script like '%V%'", Long.class); @@ -105,7 +105,7 @@ public void migrate_BasePackageContainsNoImplement_Exception() { thrown.expectMessage("no JdbcMigratable implementation found under basePackages"); Migrates migrates = new Migrates(configuration, - new BootstrapSchemaHistoryRepository(configuration.getDataSource())); + new DefaultSchemaHistoryRepository(configuration.getDataSource())); migrates.migrate(); } @@ -118,8 +118,8 @@ public void migrate_Degrade_Exception() { .build(); // prepare - BootstrapSchemaHistoryRepository repository = - new BootstrapSchemaHistoryRepository(configuration.getDataSource()); + DefaultSchemaHistoryRepository repository = + new DefaultSchemaHistoryRepository(configuration.getDataSource()); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update( "INSERT INTO `migrate_schema_history` (`install_rank`,`version`,`description`,`type`,`script`,`checksum`," @@ -140,7 +140,7 @@ public void migrate_Degrade_Exception() { "Software degrade is not allowed, please check your ODC version which should be greater than or equal to 3.4.0"); Migrates migrates = new Migrates(configuration, - new BootstrapSchemaHistoryRepository(configuration.getDataSource())); + new DefaultSchemaHistoryRepository(configuration.getDataSource())); migrates.migrate(); } diff --git a/server/odc-migrate/src/main/java/com/oceanbase/odc/migrate/AbstractMetaDBMigrate.java b/server/odc-migrate/src/main/java/com/oceanbase/odc/migrate/AbstractMetaDBMigrate.java index d6df236c0c..1dd04e940d 100644 --- a/server/odc-migrate/src/main/java/com/oceanbase/odc/migrate/AbstractMetaDBMigrate.java +++ b/server/odc-migrate/src/main/java/com/oceanbase/odc/migrate/AbstractMetaDBMigrate.java @@ -35,7 +35,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import com.oceanbase.odc.common.lang.Holder; -import com.oceanbase.odc.core.migrate.BootstrapSchemaHistoryRepository; +import com.oceanbase.odc.core.migrate.DefaultSchemaHistoryRepository; import com.oceanbase.odc.core.migrate.MigrateConfiguration; import com.oceanbase.odc.core.migrate.Migrates; @@ -72,7 +72,7 @@ public void migrate() throws InterruptedException { log.info("init configuration success, migrate starting, initVersion={}", configuration.getInitVersion()); - new Migrates(configuration, new BootstrapSchemaHistoryRepository( + new Migrates(configuration, new DefaultSchemaHistoryRepository( configuration.getDataSource())).migrate(); log.info("migrate success"); } finally {