Skip to content

Commit

Permalink
refactor(migrates): add some abstract methods for migrates
Browse files Browse the repository at this point in the history
  • Loading branch information
yhilmare committed Sep 8, 2023
1 parent 169e311 commit 9623326
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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");

Expand All @@ -80,7 +80,7 @@ public BootstrapSchemaHistoryRepository(String table, DataSource dataSource) {
}
}

public BootstrapSchemaHistoryRepository(DataSource dataSource) {
public DefaultSchemaHistoryRepository(DataSource dataSource) {
this(DEFAULT_TABLE, dataSource);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
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;

@Before
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void migrate_Success() {
.build();

Migrates migrates = new Migrates(configuration,
new BootstrapSchemaHistoryRepository(configuration.getDataSource()));
new DefaultSchemaHistoryRepository(configuration.getDataSource()));

migrates.migrate();

Expand All @@ -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()
Expand All @@ -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);

Expand All @@ -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();
}

Expand All @@ -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`,"
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9623326

Please sign in to comment.