Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a0ad81a

Browse filesBrowse files
committed
REFLECT-2 Add missing bits
Add undo migration, add Jenkins files, add Java-base migration
1 parent 1809361 commit a0ad81a
Copy full SHA for a0ad81a

File tree

Expand file treeCollapse file tree

9 files changed

+88
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

9 files changed

+88
-19
lines changed
Open diff view settings
Collapse file
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pipeline {
2+
agent any
3+
4+
stages {
5+
checkout scm
6+
7+
stage('Gradle Build') {
8+
steps {
9+
script {
10+
if (isUnix()) {
11+
sh './gradlew clean build --info'
12+
} else {
13+
bat 'gradlew.bat clean build --info'
14+
}
15+
}
16+
}
17+
}
18+
}
19+
}
Collapse file
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pipeline {
2+
agent any
3+
4+
stages {
5+
checkout scm
6+
7+
stage('Apply Database Migrations') {
8+
steps {
9+
script {
10+
if (isUnix()) {
11+
sh '/gradlew flywayMigrate --info'
12+
} else {
13+
bat 'gradlew.bat flywayMigrate --info'
14+
}
15+
}
16+
}
17+
}
18+
}
19+
}
Collapse file

‎spring-boot/data-migration/flyway/build.gradle‎

Copy file name to clipboardExpand all lines: spring-boot/data-migration/flyway/build.gradle
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
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"
5+
id "org.flywaydb.flyway" version "6.2.3"
66
}
77

88
group = 'io.reflectoring'
@@ -23,7 +23,7 @@ dependencies {
2323

2424
// Database
2525
implementation 'org.flywaydb:flyway-core'
26-
runtimeOnly 'com.h2database:h2:1.4.199'
26+
runtimeOnly 'com.h2database:h2'
2727

2828
// Add jaxb since it's no longer available in Java 11
2929
runtime 'javax.xml.bind:jaxb-api:2.3.1'
@@ -41,5 +41,9 @@ test {
4141
}
4242

4343
flyway {
44-
url = 'jdbc:h2:mem:'
44+
url = 'jdbc:h2:mem:'
45+
locations = [
46+
// Add this if you have Java-based migrations
47+
'classpath:db/migration'
48+
]
4549
}
Collapse file
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package db.migration;
2+
3+
import org.flywaydb.core.api.migration.BaseJavaMigration;
4+
import org.flywaydb.core.api.migration.Context;
5+
import org.springframework.jdbc.core.JdbcTemplate;
6+
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
7+
8+
/**
9+
* Example of a Java-based migration using Spring {@link JdbcTemplate}.
10+
*/
11+
public class V2__InsertRandomUsers extends BaseJavaMigration {
12+
13+
public void migrate(Context context) {
14+
15+
final JdbcTemplate jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true));
16+
17+
// Create 10 random users
18+
for (int i = 1; i <= 10; i++) {
19+
jdbcTemplate.execute(String.format("insert into test_user(username, first_name, last_name) "
20+
+ "values('%d@reflectoring.io', 'Elvis_%d', 'Presley_%d')", i, i, i));
21+
}
22+
}
23+
}
Collapse file

‎spring-boot/data-migration/flyway/src/main/java/io/reflectoring/flyway/FlywayApplication.java‎

Copy file name to clipboardExpand all lines: spring-boot/data-migration/flyway/src/main/java/io/reflectoring/flyway/FlywayApplication.java
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ public class FlywayApplication {
99
public static void main(String[] args) {
1010
SpringApplication.run(FlywayApplication.class, args);
1111
}
12-
1312
}
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE test_user;
Collapse file
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Init script
2+
3+
-- DDL
4+
CREATE TABLE test_user(
5+
id INT AUTO_INCREMENT PRIMARY KEY,
6+
username VARCHAR(255) NOT NULL UNIQUE,
7+
first_name VARCHAR(255) NOT NULL,
8+
last_name VARCHAR(255) NOT NULL
9+
);
Collapse file

‎spring-boot/data-migration/flyway/src/main/resources/db/migration/V1__init.sql‎

Copy file name to clipboardExpand all lines: spring-boot/data-migration/flyway/src/main/resources/db/migration/V1__init.sql
-7Lines changed: 0 additions & 7 deletions
This file was deleted.
Collapse file
+10-8Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.reflectoring.flyway;
22

33
import java.util.List;
4-
54
import org.assertj.core.api.Assertions;
65
import org.junit.jupiter.api.Test;
76
import org.springframework.beans.factory.annotation.Autowired;
@@ -17,25 +16,28 @@ class FlywayWithH2Test {
1716
@Test
1817
void databaseHasBeenInitialized() {
1918

20-
jdbcTemplate.execute("insert into auth_user values(1, 'reflectoring')");
19+
jdbcTemplate.execute("insert into test_user (username, first_name, last_name) values('reflectoring', 'Elvis', 'Presley')");
2120

2221
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")
22+
.query("SELECT username, first_name, last_name FROM test_user", (rs, rowNum) -> new AuthUser(
23+
rs.getString("username"),
24+
rs.getString("first_name"),
25+
rs.getString("last_name")
2626
));
2727

2828
Assertions.assertThat(authUsers).isNotEmpty();
2929
}
3030

3131
private static class AuthUser {
32-
public String id;
3332
public String username;
33+
public String firstName;
34+
public String lastName;
3435

35-
public AuthUser(final String id, final String username) {
36+
public AuthUser(final String username, final String firstName, final String lastName) {
3637

37-
this.id = id;
3838
this.username = username;
39+
this.firstName = firstName;
40+
this.lastName = lastName;
3941
}
4042
}
4143
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.