Merge pull request #9723 from adrian-maghear/BAEL-4288#flyway-repair

[BAEL-4288] flyway repair
This commit is contained in:
Jonathan Cook 2020-07-25 14:56:26 +02:00 committed by GitHub
commit 9f5396e448
16 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1 @@
### Relevant Articles:

View File

@ -0,0 +1 @@
POSTGRES_PORT=5431

View File

@ -0,0 +1,15 @@
version: '3.0'
services:
postgres-test:
image: postgres:11.5
ports:
- ${POSTGRES_PORT}:5432
env_file: postgres.env
networks:
- baeldung
networks:
baeldung:
driver: bridge

View File

@ -0,0 +1,3 @@
POSTGRES_USER=testuser
POSTGRES_PASSWORD=password
POSTGRES_DB=testdb

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>flyway</artifactId>
<name>flyway-repair</name>
<packaging>jar</packaging>
<description>Flyway Repair Demo</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>h2</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring-boot.run.profiles>h2</spring-boot.run.profiles>
</properties>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>postgres</id>
<properties>
<spring-boot.run.profiles>postgres</spring-boot.run.profiles>
</properties>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<properties>
<flyway.configFiles>src/main/resources/application-${spring-boot.run.profiles}.properties</flyway.configFiles>
</properties>
</project>

View File

@ -0,0 +1,13 @@
package com.baeldung.flywaycallbacks;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FlywayApplication {
public static void main(String[] args) {
SpringApplication.run(FlywayApplication.class, args);
}
}

View File

@ -0,0 +1 @@
spring.flyway.locations=classpath:db/migration,classpath:db/callback

View File

@ -0,0 +1,3 @@
flyway.url=jdbc:h2:file:./testdb;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;MODE=MySQL;DATABASE_TO_UPPER=false;
flyway.user=testuser
flyway.password=password

View File

@ -0,0 +1,3 @@
flyway.url=jdbc:postgresql://127.0.0.1:5431/testdb
flyway.user=testuser
flyway.password=password

View File

@ -0,0 +1,3 @@
spring.datasource.url=${flyway.url}
spring.datasource.username=${flyway.user}
spring.datasource.password=${flyway.password}

View File

@ -0,0 +1 @@
DELETE FROM flyway_schema_history WHERE success=false;

View File

@ -0,0 +1,3 @@
create table table_one (
id numeric primary key
);

View File

@ -0,0 +1,3 @@
create table table_two (
id numeric primary key
);

View File

@ -0,0 +1,3 @@
create table table_three (
id numeric primary key
);

View File

@ -0,0 +1,3 @@
create table table_four (
id numeric primary key
);

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="WARN" />
<logger name="org.springframework.transaction" level="WARN" />
<!-- in order to debug some marshalling issues, this needs to be TRACE -->
<logger name="org.springframework.web.servlet.mvc" level="WARN" />
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>