Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade db-migration to use Spring 5 and other libraries version #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions db-migration-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.3</version>
<scope>test</scope>
</dependency>

Expand All @@ -24,8 +25,8 @@
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand All @@ -42,8 +43,8 @@
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand All @@ -57,7 +58,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
<version>5.3.27</version>
</dependency>

<dependency>
Expand All @@ -69,11 +70,13 @@
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>2.0.7</version>
</dependency>
</dependencies>
</project>
6 changes: 3 additions & 3 deletions db-migration-maven-plugin/src/test/test-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<version>1.1.111</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
<groupId>org.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.33</version>
</dependency>
</dependencies>
</plugin>
Expand Down
32 changes: 24 additions & 8 deletions db-migration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,37 @@
- Test
-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.214</version>
<scope>test</scope>
</dependency>

Expand All @@ -52,8 +57,8 @@
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -84,37 +89,42 @@
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<!-- Spring and Related -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<optional>true</optional>
</dependency>

Expand All @@ -124,6 +134,12 @@
<artifactId>groovy-all</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.carbonfive.db.migration;

import org.apache.commons.lang.Validate;
import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.carbonfive.db.jdbc.DatabaseType;
import com.carbonfive.db.jdbc.DatabaseUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public class DriverManagerMigrationManager extends DataSourceMigrationManager
{
public DriverManagerMigrationManager(String driver, String url, String username, String password)
{
super(new DriverManagerDataSource(driver, url, username, password));
super(new DriverManagerDataSource(url, username, password));
}

public DriverManagerMigrationManager(String driver, String url, String username, String password, DatabaseType dbType)
{
super(new DriverManagerDataSource(driver, url, username, password), dbType);
super(new DriverManagerDataSource(url, username, password), dbType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,35 @@
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang3.Validate;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;

public class GroovyMigration extends AbstractMigration
{
public class GroovyMigration extends AbstractMigration {
private final Resource script;

public GroovyMigration(String version, Resource script)
{
public GroovyMigration(String version, Resource script) {
super(version, script.getFilename());
this.script = script;
}

public void migrate(DatabaseType dbType, Connection connection)
{
public void migrate(DatabaseType dbType, Connection connection) {
Binding binding = new Binding();
binding.setVariable("connection", connection);
GroovyShell shell = new GroovyShell(binding);

InputStream inputStream = null;
try
{
try {
inputStream = script.getInputStream();
shell.evaluate(IOUtils.toString(inputStream));
Validate.isTrue(!connection.isClosed(), "JDBC Connection should not be closed.");
}
catch (IOException e)
{
throw new MigrationException(e);
}
catch (SQLException e)
{
} catch (IOException | SQLException e) {
throw new MigrationException(e);
}
finally
{
} finally {
IOUtils.closeQuietly(inputStream);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.carbonfive.db.migration;

import com.carbonfive.db.jdbc.DatabaseType;
import org.apache.commons.collections.Predicate;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang3.StringUtils;

import java.sql.Connection;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.carbonfive.db.migration;

import com.carbonfive.db.jdbc.DatabaseType;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -12,8 +12,8 @@
import java.io.IOException;
import java.util.*;

import static org.apache.commons.collections.CollectionUtils.find;
import static org.apache.commons.lang.StringUtils.isBlank;
import static org.apache.commons.collections4.CollectionUtils.find;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.springframework.util.StringUtils.collectionToCommaDelimitedString;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.carbonfive.db.jdbc.DatabaseType;
import com.carbonfive.db.jdbc.ScriptRunner;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang3.Validate;
import org.springframework.core.io.Resource;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.carbonfive.db.migration;

import com.carbonfive.db.jdbc.DatabaseType;
import org.apache.commons.collections.map.DefaultedMap;
import org.apache.commons.collections4.map.DefaultedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.junit.Before;
import org.junit.Test;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

Expand All @@ -18,22 +18,22 @@ public class DataSourceMigrationManagerTest
static final String BAD_SCRIPT = "classpath:/test_migrations/bad_script_1/";

private DataSourceMigrationManager migrationManager;
private SimpleJdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;

@Before
public void setup()
{
DataSource dataSource = DatabaseTestUtils.createUniqueDataSource();
migrationManager = new DataSourceMigrationManager(dataSource);

jdbcTemplate = new SimpleJdbcTemplate(dataSource);
jdbcTemplate = new JdbcTemplate(dataSource);
}

@Test
public void enableMigrationsShouldCreateSchemaTrackingTable()
{
migrationManager.enableMigrations();
jdbcTemplate.queryForInt("select count(*) from schema_version"); // Throws exception if table doesn't exist.
jdbcTemplate.queryForObject("select count(*) from schema_version", Integer.class); // Throws exception if table doesn't exist.
}

@Test
Expand All @@ -44,7 +44,7 @@ public void migrateShouldApplyOneMigration()
migrationManager.migrate();
assertThat(migrationManager.validate(), is(true));

assertThat(jdbcTemplate.queryForInt("select count(*) from users"), is(3));
assertThat(jdbcTemplate.queryForObject("select count(*) from users", Integer.class), is(3));
}

@Test
Expand All @@ -62,8 +62,8 @@ public void migrateShouldApplyMultipleMigrations()
migrationManager.migrate();
assertThat(migrationManager.validate(), is(true));

assertThat(jdbcTemplate.queryForInt("select count(*) from users"), is(3));
assertThat(jdbcTemplate.queryForInt("select count(*) from trips"), is(3));
assertThat(jdbcTemplate.queryForObject("select count(*) from users", Integer.class), is(3));
assertThat(jdbcTemplate.queryForObject("select count(*) from trips", Integer.class), is(3));
}

@Test
Expand Down Expand Up @@ -94,7 +94,7 @@ public void migrateShouldHandleInvalidSql()
{
}

assertThat(jdbcTemplate.queryForInt("select count(*) from trips"), is(2));
assertThat(jdbcTemplate.queryForObject("select count(*) from trips", Integer.class), is(2));
assertThat(migrationManager.validate(), is(false));
}
}
Loading