SlideShare a Scribd company logo
FlywayDB Migration with Spring Boot
What is Flyway DB?
Flyway is an open-source database migration tool that helps you manage and version
your database schema changes across all your instances. It supports various
databases such as MySQL, Oracle, SQL Server, PostgreSQL, and many more. To learn
more about Flyway, you can use the flywaydb. Many software projects use relational
databases. This requires the handling of database migrations, also often called schema
migrations.
The first and most important practice is not to use “spring.jpa.hibernate.ddl-
auto=create/update/create-drop” in production. With these properties, you could update
and migrate your database schema with Hibernate directly. This might be a valid option
for pet projects, but not for enterprise applications in production as you can’t control the
automatic migration process in detail. You also won’t get information about the current
database schema version of an environment (e.g. staging, test, dev …), so thats why we
can use Flyway to resolve the above mentioned problems. In this blog, we will explore
how to use Flyway with Spring Boot in detail.
Configuring Flyway Database :
• Add below flyway-core dependancy to enable FlywayDB in springboot application
:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
• NOTE : For the spring-boot version 3.0.2 and greater, we have to use version 17
for JDK and for JDK17 flyway is not supported so we have to add one extra
dependency based on your database, Which is given below :
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-mysql</artifactId>
</dependency>
• It is based on just 7 basic commands:Migrate,Clean,Info,Validate,Undo,Baseline
andRepair (This is not supported in community version).
• Add below properties into the “application.properties” file :
# Flyway Configuration
spring.flyway.baseline-on-migrate=true
spring.flyway.enabled=true
spring.flyway.locations=classpath:db/migration
spring.jpa.hibernate.ddl-auto=validate
Creating Database Migrations :
Flyway requires you to create database migration scripts, under the path db/migration
folder specified as per in properties file, with filename in a specific format that includes
a version number & descriptive name, for e.g. “V[VERSION_NUMBER]__[NAME].sql” with
SQL statements to be executed/validated before starting the server.
For example, let’s say we want to create a table called users in our database. We can
create a migration script with the following name “V1__Create_User_Table.sql” with
below sql statements :
CREATE TABLE USERS (
ID INT AUTO_INCREMENT PRIMARY KEY,
USERID int,
Name varchar(20)
);
Running Database Migrations :
Now run the spring-boot application and check into your database, user table is created.
The ‘flyway_schema_history’ table is also created, with 1 record
“V1__Create_User_Table” executed successfully. This table tracks the changes in DB as
per the different versions are created.
As each migration gets applied, the schema history table is updated accordingly. When
the new file is added in flyway it will once again scan the filesystem or the classpath of
the application for migrations. The migrations are checked against the schema history
table. If their version number is lower or equal to the one of the version marked as
current, they are ignored.
Conclusion :
In conclusion, Flyway is a powerful tool that enables easy database migration
management in Spring Boot applications. With its seamless integration with Spring
Boot, developers can easily manage database schema changes and updates
throughout the application development lifecycle. The use of Flyway simplifies the
process of database migration, reduces the risk of data loss, and makes it easy to
maintain database versions in a structured manner. By adopting Flyway with Spring
Boot, developers can focus on building the core functionality of their application, while
Flyway takes care of the database migration process in a simple and efficient way.
Originally published by: FlywayDB Migration with Spring Boot

More Related Content

PPTX
Spring data jpa are used to develop spring applications
PDF
Борис Трофимов. Continuous Database migration-это просто!
PDF
Continuous DB migration based on carbon5 framework
DOCX
Web Sphere Application Server Features
PPTX
Database CI/CD Pipeline
PDF
FLOWER SHOP BILLING MANAGEMENT SYSTEM PROJECT REPORT
PPTX
Getting started with agile database migrations for java flywaydb
PDF
Using MS-SQL Server with Visual DataFlex
Spring data jpa are used to develop spring applications
Борис Трофимов. Continuous Database migration-это просто!
Continuous DB migration based on carbon5 framework
Web Sphere Application Server Features
Database CI/CD Pipeline
FLOWER SHOP BILLING MANAGEMENT SYSTEM PROJECT REPORT
Getting started with agile database migrations for java flywaydb
Using MS-SQL Server with Visual DataFlex

Similar to FlywayDB Migration with Spring Boot (20)

PPT
Ajuby: Open Source Application Builder
PDF
Flower shop billing management system project.pdf
PPTX
Drupal migrations in 2018 - SFDUG, March 8, 2018
PDF
Drupal on windows azure
PDF
Schema migration (DB migration) with Phinx
ODP
Handling Database Deployments
PPTX
SpringBootCompleteBootcamp.pptx
PPT
New Enhancements + Upgrade Path to Oracle EBS R12.1.3
PPT
Liquibase – a time machine for your data
DOCX
App v 4.6 sp1 trial guide
PDF
dvprimer-architecture
PPT
Project seminar
DOC
Suresh Resume
PDF
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
PDF
Delivering changes for databases and applications
PPTX
Database Change Management as a Service
PDF
PDF
PPTX
Introduction to ejb and struts framework
PDF
FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...
Ajuby: Open Source Application Builder
Flower shop billing management system project.pdf
Drupal migrations in 2018 - SFDUG, March 8, 2018
Drupal on windows azure
Schema migration (DB migration) with Phinx
Handling Database Deployments
SpringBootCompleteBootcamp.pptx
New Enhancements + Upgrade Path to Oracle EBS R12.1.3
Liquibase – a time machine for your data
App v 4.6 sp1 trial guide
dvprimer-architecture
Project seminar
Suresh Resume
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Delivering changes for databases and applications
Database Change Management as a Service
Introduction to ejb and struts framework
FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...
Ad

More from Inexture Solutions (20)

PDF
AI-Powered Tutoring System_ A Step-by-Step Guide to Building It.pdf
PDF
AI Chatbot Development in 2025: Costs, Trends & Business Impact
PDF
Spring Boot for WebRTC Signaling Servers: A Comprehensive Guide
PDF
Mobile App Development Cost 2024 Budgeting Your Dream App
PDF
Data Serialization in Python JSON vs. Pickle
PDF
Best EV Charging App 2024 A Tutorial on Building Your Own
PDF
What is a WebSocket? Real-Time Communication in Applications
PDF
SaaS Application Development Explained in 10 mins
PDF
Best 7 SharePoint Migration Tools of 2024
PDF
Spring Boot with Microsoft Azure Integration.pdf
PDF
Best Features of Adobe Experience Manager (AEM).pdf
PDF
React Router Dom Integration Tutorial for Developers
PDF
Python Kafka Integration: Developers Guide
PDF
What is SaMD Model, Benefits, and Development Process.pdf
PDF
Unlocking the Potential of AI in Spring.pdf
PDF
Mobile Banking App Development Cost in 2024.pdf
PDF
Education App Development : Cost, Features and Example
PDF
Firebase Push Notification in JavaScript Apps
PDF
Micronaut Framework Guide Framework Basics and Fundamentals.pdf
PDF
Steps to Install NPM and Node.js on Windows and MAC
AI-Powered Tutoring System_ A Step-by-Step Guide to Building It.pdf
AI Chatbot Development in 2025: Costs, Trends & Business Impact
Spring Boot for WebRTC Signaling Servers: A Comprehensive Guide
Mobile App Development Cost 2024 Budgeting Your Dream App
Data Serialization in Python JSON vs. Pickle
Best EV Charging App 2024 A Tutorial on Building Your Own
What is a WebSocket? Real-Time Communication in Applications
SaaS Application Development Explained in 10 mins
Best 7 SharePoint Migration Tools of 2024
Spring Boot with Microsoft Azure Integration.pdf
Best Features of Adobe Experience Manager (AEM).pdf
React Router Dom Integration Tutorial for Developers
Python Kafka Integration: Developers Guide
What is SaMD Model, Benefits, and Development Process.pdf
Unlocking the Potential of AI in Spring.pdf
Mobile Banking App Development Cost in 2024.pdf
Education App Development : Cost, Features and Example
Firebase Push Notification in JavaScript Apps
Micronaut Framework Guide Framework Basics and Fundamentals.pdf
Steps to Install NPM and Node.js on Windows and MAC
Ad

Recently uploaded (20)

PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
STKI Israel Market Study 2025 version august
PPTX
1. Introduction to Computer Programming.pptx
PDF
project resource management chapter-09.pdf
PDF
August Patch Tuesday
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Web App vs Mobile App What Should You Build First.pdf
PPT
What is a Computer? Input Devices /output devices
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Hybrid model detection and classification of lung cancer
Univ-Connecticut-ChatGPT-Presentaion.pdf
Zenith AI: Advanced Artificial Intelligence
DP Operators-handbook-extract for the Mautical Institute
Group 1 Presentation -Planning and Decision Making .pptx
Hindi spoken digit analysis for native and non-native speakers
STKI Israel Market Study 2025 version august
1. Introduction to Computer Programming.pptx
project resource management chapter-09.pdf
August Patch Tuesday
Enhancing emotion recognition model for a student engagement use case through...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
cloud_computing_Infrastucture_as_cloud_p
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
A novel scalable deep ensemble learning framework for big data classification...
Web App vs Mobile App What Should You Build First.pdf
What is a Computer? Input Devices /output devices
OMC Textile Division Presentation 2021.pptx
Hybrid model detection and classification of lung cancer

FlywayDB Migration with Spring Boot

  • 1. FlywayDB Migration with Spring Boot What is Flyway DB? Flyway is an open-source database migration tool that helps you manage and version your database schema changes across all your instances. It supports various databases such as MySQL, Oracle, SQL Server, PostgreSQL, and many more. To learn more about Flyway, you can use the flywaydb. Many software projects use relational databases. This requires the handling of database migrations, also often called schema migrations. The first and most important practice is not to use “spring.jpa.hibernate.ddl- auto=create/update/create-drop” in production. With these properties, you could update and migrate your database schema with Hibernate directly. This might be a valid option for pet projects, but not for enterprise applications in production as you can’t control the automatic migration process in detail. You also won’t get information about the current database schema version of an environment (e.g. staging, test, dev …), so thats why we can use Flyway to resolve the above mentioned problems. In this blog, we will explore how to use Flyway with Spring Boot in detail.
  • 2. Configuring Flyway Database : • Add below flyway-core dependancy to enable FlywayDB in springboot application : <dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-core</artifactId> </dependency> • NOTE : For the spring-boot version 3.0.2 and greater, we have to use version 17 for JDK and for JDK17 flyway is not supported so we have to add one extra dependency based on your database, Which is given below : <dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-mysql</artifactId> </dependency> • It is based on just 7 basic commands:Migrate,Clean,Info,Validate,Undo,Baseline andRepair (This is not supported in community version). • Add below properties into the “application.properties” file : # Flyway Configuration spring.flyway.baseline-on-migrate=true spring.flyway.enabled=true spring.flyway.locations=classpath:db/migration spring.jpa.hibernate.ddl-auto=validate
  • 3. Creating Database Migrations : Flyway requires you to create database migration scripts, under the path db/migration folder specified as per in properties file, with filename in a specific format that includes a version number & descriptive name, for e.g. “V[VERSION_NUMBER]__[NAME].sql” with SQL statements to be executed/validated before starting the server. For example, let’s say we want to create a table called users in our database. We can create a migration script with the following name “V1__Create_User_Table.sql” with below sql statements : CREATE TABLE USERS ( ID INT AUTO_INCREMENT PRIMARY KEY, USERID int, Name varchar(20) ); Running Database Migrations : Now run the spring-boot application and check into your database, user table is created. The ‘flyway_schema_history’ table is also created, with 1 record “V1__Create_User_Table” executed successfully. This table tracks the changes in DB as per the different versions are created. As each migration gets applied, the schema history table is updated accordingly. When the new file is added in flyway it will once again scan the filesystem or the classpath of the application for migrations. The migrations are checked against the schema history table. If their version number is lower or equal to the one of the version marked as current, they are ignored.
  • 4. Conclusion : In conclusion, Flyway is a powerful tool that enables easy database migration management in Spring Boot applications. With its seamless integration with Spring Boot, developers can easily manage database schema changes and updates throughout the application development lifecycle. The use of Flyway simplifies the process of database migration, reduces the risk of data loss, and makes it easy to maintain database versions in a structured manner. By adopting Flyway with Spring Boot, developers can focus on building the core functionality of their application, while Flyway takes care of the database migration process in a simple and efficient way. Originally published by: FlywayDB Migration with Spring Boot