Skip to content

Flyway migration library with usefull configurations cross different environments on Spring-boot.

License

Notifications You must be signed in to change notification settings

peterszatmary/flyway-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flyway-demo

Build Status Codacy Badge

Flyway migration and database evolving library with useful configurations cross different environments on Spring-boot.

Whats interesting here

SpringBoot with

Flyway is configured via flyway-maven-plugin to simply switch between different environments. In this example we have 3 environments dev, test and preprod. All of them have separate configurations. So in theory they can have different data structure, different data, different db drivers.

More obvious is to have same data structures cross environments but different data. Same like in this Spring Boot application example.

1. Migration / evolving with Flyway through different environments

For each environment we create maven profile. Profiles will just set properties for main plugin build.

In whole solution i am using vagrant-mysql database.Feel free to use your own.

Main plugin configuration looks like following

<plugin>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>4.0.3</version>
    <configuration>
        <driver>${db.driver}</driver>
        <url>${db.url}</url>
        <user>${db.user}</user>
        <password>${db.password}</password>
        <locations>
            <location>${flyway.location}</location>
        </locations>
    </configuration>
</plugin>

DEV environment profile

<profile>
    <id>DEV-environment</id>
    <properties>
        <db.driver>com.mysql.jdbc.Driver</db.driver>
        <db.url>jdbc:mysql://33.33.33.1/flywaydemodev</db.url>
        <db.user>root</db.user>
        <db.password>root</db.password>
        <flyway.location>filesystem:src/main/resources/db/migration/dev</flyway.location>
    </properties>
</profile>

How to run the dev migration

mvn flyway:migrate -P DEV-environment

test migration run

After that is database prepared for application run. Database has schema and inserted data.

How to run app with dev database

For app run you need just change in application.properties following

environment=dev

After that you can see application with dev database and data in it.

dev app

TEST environment profile

<profile>
    <id>TEST-environment</id>
    <properties>
        <db.driver>com.mysql.jdbc.Driver</db.driver>
        <db.url>jdbc:mysql://33.33.33.1/flywaydemotest</db.url>
        <db.user>root</db.user>
        <db.password>root</db.password>
        <flyway.location>filesystem:src/main/resources/db/migration/test</flyway.location>
    </properties>
</profile>

How to run the test migration

mvn flyway:migrate -P TEST-environment

test migration run

Before this step the database is empty. After that is database prepared for application run. Database has schema and inserted data.

How to run app with test database

For app run you need just change in application.properties following

environment=test

Before this step the database is empty. After that you can see application with test database and data in it.

test app

PREPROD environment profile

<profile>
    <id>PREPROD-environment</id>
    <properties>
        <db.driver>com.mysql.jdbc.Driver</db.driver>
        <db.url>jdbc:mysql://33.33.33.1/flywaydemopreprod</db.url>
        <db.user>root</db.user>
        <db.password>root</db.password>
        <flyway.location>filesystem:src/main/resources/db/migration/preprod</flyway.location>
    </properties>
</profile>

How to run the preprod migration

mvn flyway:migrate -P PREPROD-environment

preprod migration run

After that is database prepared for application run. Database has schema and inserted data.

How to run app with preprod database

For app run you need just change in application.properties following

environment=preprod

preprod app

Project structure for flyway multi environment support

project structure

About

Flyway migration library with usefull configurations cross different environments on Spring-boot.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published