EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials Spring Tutorial Spring Boot Flyway
 

Spring Boot Flyway

Updated March 15, 2023

spring boot flyway

 

 

Introduction to Spring Boot Flyway

Spring boot flyway is nothing but the application of version control, which was easily involved in our database schema in all instances of the database. Spring boot flyway is application software of database migration which was used to migrate, validate, undo, clean, repair, and baseline commands of SQL. Flyway framework is basically used to update the database version using migration tools. Spring boot flyway is the tool that allows incremental changes of version control in our database, so we can easily remodel our database into the new version.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

What is a spring boot flyway?

  • Using the spring boot flyway framework, we can easily remodel our database schema into a new version of the database.
  • We can write an SQL migration script by using the syntax of database-specific. Also, we can write the code in java language by using database transformation of advanced java.
  • We can say that database migration can be repeatable or it is versioned. The former contains the one unique version, and it is applied once.
  • At the time single migration run, repeated migration is always applied at last after executing the pending migration version.
  • Migration of repeatable is always applied at the time of their order description. To migrate using single migration, all database statement of database migration is run in a single database transaction.
  • To use the spring boot flyway in our project, we need to add the flyway maven plugin in the pom.xml file of our project.
  • The latest version of the flyway maven plugin is 8.0.0. Therefore, we can configure the flyway maven plugin in different ways.
  • We can configure the flyway plugin are as follows.
  1. Configure the flyway plugin using the configuration tag.
  2. Configure the flyway plugin by using the configuration properties of maven.
  3. Configure the flyway plugin by using an external configuration file.
  4. Configure the flyway plugin by using system properties.
  • We can configure the flyway plugin in our project by using the configuration tag in our definition file as pom.xml.
  • We can also configure the flyway plugin in our application by specifying the configuration properties in the file name as pom.xml.
  • Another way to configure the flyway plugin in our project is to create another configuration file and give a “.conf” extension to that file.

Database Spring Boot Flyway Project

  • To setup a database flyway project, first, we need to create a project template using spring initializer and need to add the following dependency to it.
  1. Spring boot starter web
  2. JDBC API
  3. PostgreSQL driver
  4. Spring web
  • In the below step, we provide the project group name as com. Examples include artifact name as spring-boot-flyway, project name as spring-boot-flyway, package as a jar file, and selecting java version as 11.
  • We also select the dependencies as spring web, flyway migration, PostgreSQL driver, and JDBC API.

spring boot flyway output 1

  • After creating the project, we are opening the same using the spring tool suite are as follows.

spring boot flyway output 2

  • After opening the project in the spring tool suite, we have already added the dependency at the time of creating the template, so we do not need to add the same one again.
  • After adding a dependency, we need to create an application.properties and application.yml file for the project; in this file, we have defined the database configuration.
  • Then we have created the SQL script in the migration directory. After creating a script, we have to create the main class file of our project.
  • After creating the main class file, we need to run our application. After the successful run, we can see all the statement is executed in a database which was we have created in an SQL file.

Spring Boot Flyway Examples

  • To configure the flyway project example, we also need to add dependency in our project; below are the steps to create a flyway project example.
  • Create project template using spring initializer –

Group – com.example
Artifact name – spring-boot- flyway
Name – spring-boot- flyway
Description - Project of spring-boot- flyway
Package name - com.example.spring-boot- flyway
Packaging – Jar
Java – 11
Dependencies – spring web, flyway migration, PostgreSQL driver, JDBC API

spring boot flyway output 3

  • After generating project extract files and open this project by using the spring tool suite 

spring boot flyway output 4

  • After opening the project using the spring tool suite, check the project and its files. 

spring boot flyway output 5

  • Add dependency 

Code –

<dependency>   -- Start of dependency tag.
<groupId>org.springframework.boot</groupId>   -- Start and end of groupId tag.
<artifactId>spring-boot-starter-web</artifactId>  -- Start and end of artifactId tag.
</dependency>    -- End of dependency tag.
<dependency>   -- Start of dependency tag.
<groupId>org.flywaydb</groupId>   -- Start and end of groupId tag.
<artifactId>flyway-core</artifactId>  -- Start and end of artifactId tag.
</dependency>    -- End of dependency tag.
<dependency>   -- Start of dependency tag.
<groupId>org.postgresql</groupId>   -- Start and end of groupId tag.
<artifactId>postgresql </artifactId>  -- Start and end of artifactId tag.
</dependency>    -- End of dependency tag.

spring boot flyway output 6

  • Configure the application.properties file 

Code –

spring.datasource.url = jdbc:postgresql://localhost:5432/springbootdb?createDatabaseIfNotExist=true
spring.datasource.username = postgres
spring.datasource.password = postgres
spring.datasource.platform = postgresql
spring.jpa.hibernate.ddl-auto = update

output 7

  • Configure the application.yml file 

Code –

spring:
application:
name: spring-boot-flyway
datasource:
driverClassName : com.postgresql.jdbc.Driver
url: "jdbc:postgresql://localhost:5432/springbootdb"
password: "postgres"
username: "postgres"

output 8

  • Create an SQL file in the migration directory 

Code –

CREATE TABLE springbootflyway (stud_id int, stud_name varchar(10), address varchar(10));
INSERT INTO springbootflyway (stud_id, stud_name, address) VALUES (1, 'ABC', ‘Pune’);

output 9

  • Create the main class for the flyway application 

Code –

@SpringBootTest
class SpringBootFlywayApplicationTests {
public static void main /* main method of spring boot flyway application */ (String[] args) {
SpringApplication.run (SpringBootFlywayApplicationTests.class, args);
}
}

output 10

  • Run the application –

output 11

  • Check the table is created, and data was inserted into the database 

After successfully running the application check, the springbootflyway table is created into the database, and data is inserted into the same table.

Code:

# select * from springbootflyway;

output 12

Conclusion

Spring boot flyway framework is basically used to update database versions using migration tools. We can write a flyway database migration script using SQL or a java programming language. Flyway is the tool which was allowing incremental changes of version control in our database.

Recommended Articles

This is a guide to the spring boot flyway. Here we discuss What is a spring boot flyway along with the examples and codes. You may also have a look at the following articles to learn more –

  1. Spring Boot Logging
  2. Spring Boot Banner
  3. Spring Boot Path Variable
  4. Spring Boot Run Command

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW