Skip to content

Commit 9c0c1e7

Browse files
Merge pull request eugenp#3245 from chrisoberle/master
Add flyway-callback demo code per BAEL-1316
2 parents 057b410 + 8828d98 commit 9c0c1e7

12 files changed

Lines changed: 253 additions & 0 deletions

File tree

‎flyway/flyway-callbacks/.gitignore‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/

‎flyway/flyway-callbacks/pom.xml‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<artifactId>flyway-callbacks</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>flyway-callbacks</name>
11+
<description>Flyway Callbacks Demo</description>
12+
13+
<parent>
14+
<artifactId>flyway</artifactId>
15+
<groupId>com.baeldung</groupId>
16+
<version>1.0</version>
17+
<relativePath>../../flyway</relativePath>
18+
</parent>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.flywaydb</groupId>
29+
<artifactId>flyway-core</artifactId>
30+
<version>5.0.2</version>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-jdbc</artifactId>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>com.h2database</groupId>
40+
<artifactId>h2</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-test</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
58+
59+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.flywaycallbacks;
2+
3+
import java.sql.Connection;
4+
5+
import org.apache.commons.logging.Log;
6+
import org.apache.commons.logging.LogFactory;
7+
import org.flywaydb.core.api.MigrationInfo;
8+
import org.flywaydb.core.api.callback.BaseFlywayCallback;
9+
10+
public class ExampleFlywayCallback extends BaseFlywayCallback {
11+
12+
private Log log = LogFactory.getLog(getClass());
13+
14+
@Override
15+
public void afterEachMigrate(Connection connection, MigrationInfo info) {
16+
log.info("> afterEachMigrate");
17+
}
18+
19+
@Override
20+
public void afterMigrate(Connection connection) {
21+
log.info("> afterMigrate");
22+
}
23+
24+
@Override
25+
public void beforeEachMigrate(Connection connection, MigrationInfo info) {
26+
log.info("> beforeEachMigrate");
27+
}
28+
29+
@Override
30+
public void beforeMigrate(Connection connection) {
31+
log.info("> beforeMigrate");
32+
}
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.flywaycallbacks;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class FlywayApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(FlywayApplication.class, args);
11+
}
12+
13+
}

‎flyway/flyway-callbacks/src/main/resources/application.properties‎

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
create table table_one (
2+
id numeric,
3+
name varchar(50),
4+
constraint pk_table_one primary key (id)
5+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
create table table_two (
2+
id numeric,
3+
name varchar(50),
4+
constraint pk_table_two primary key (id)
5+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%date [%thread] %-5level %logger{36} - %message%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<logger name="org.springframework" level="WARN" />
11+
<logger name="org.springframework.transaction" level="WARN" />
12+
13+
<!-- in order to debug some marshalling issues, this needs to be TRACE -->
14+
<logger name="org.springframework.web.servlet.mvc" level="WARN" />
15+
16+
<root level="INFO">
17+
<appender-ref ref="STDOUT" />
18+
</root>
19+
</configuration>

0 commit comments

Comments
 (0)