Skip to content

Commit 01828e5

Browse files
committed
REFLECT-2 Integrating H2 with Flyway
1 parent a2bb00f commit 01828e5

7 files changed

Lines changed: 79 additions & 48 deletions

File tree

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
plugins {
2-
id 'org.springframework.boot' version '2.2.2.RELEASE'
2+
id 'org.springframework.boot' version '2.2.3.RELEASE'
33
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
44
id 'java'
5+
id "org.flywaydb.flyway" version "6.2.0"
56
}
67

78
group = 'io.reflectoring'
@@ -13,13 +14,34 @@ repositories {
1314
}
1415

1516
dependencies {
16-
implementation 'org.springframework.boot:spring-boot-starter'
17-
implementation 'org.flywaydb:flyway-core'
18-
testImplementation('org.springframework.boot:spring-boot-starter-test') {
19-
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
20-
}
17+
18+
compileOnly 'org.projectlombok:lombok'
19+
20+
// Spring
21+
implementation 'org.springframework.boot:spring-boot-starter-web'
22+
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
23+
24+
// Database
25+
implementation 'org.flywaydb:flyway-core'
26+
runtimeOnly 'com.h2database:h2:1.4.199'
27+
28+
// Add jaxb since it's no longer available in Java 11
29+
runtime 'javax.xml.bind:jaxb-api:2.3.1'
30+
31+
// Test
32+
testCompile 'org.assertj:assertj-core'
33+
testImplementation('org.springframework.boot:spring-boot-starter-test') {
34+
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
35+
}
36+
testImplementation('org.junit.jupiter:junit-jupiter:5.5.1')
2137
}
2238

2339
test {
2440
useJUnitPlatform()
2541
}
42+
43+
flyway {
44+
url = 'jdbc:h2:mem:'
45+
user = 'sa'
46+
password = ''
47+
}

spring-boot/data-migration/flyway/docker-compose.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Tue Jan 21 16:55:51 EET 2020
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
13
distributionBase=GRADLE_USER_HOME
24
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
4-
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6+
zipStoreBase=GRADLE_USER_HOME

spring-boot/data-migration/flyway/src/main/resources/application.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Init script
2+
3+
-- DDL
4+
CREATE TABLE auth_user(
5+
id INT AUTO_INCREMENT PRIMARY KEY,
6+
username VARCHAR(255) NOT NULL unique
7+
);

spring-boot/data-migration/flyway/src/test/java/io/reflectoring/flyway/FlywayApplicationTests.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package io.reflectoring.flyway;
2+
3+
import java.util.List;
4+
5+
import org.assertj.core.api.Assertions;
6+
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
9+
import org.springframework.jdbc.core.JdbcTemplate;
10+
11+
@DataJpaTest
12+
class FlywayWithH2Test {
13+
14+
@Autowired
15+
private JdbcTemplate jdbcTemplate;
16+
17+
@Test
18+
void databaseHasBeenInitialized() {
19+
20+
jdbcTemplate.execute("insert into auth_user values(1, 'reflectoring')");
21+
22+
final List<AuthUser> authUsers = jdbcTemplate
23+
.query("SELECT id, username FROM auth_user", (rs, rowNum) -> new AuthUser(
24+
rs.getString("id"),
25+
rs.getString("username")
26+
));
27+
28+
Assertions.assertThat(authUsers).isNotEmpty();
29+
}
30+
31+
private static class AuthUser {
32+
public String id;
33+
public String username;
34+
35+
public AuthUser(final String id, final String username) {
36+
37+
this.id = id;
38+
this.username = username;
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)