EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Spring Tutorial Spring Boot Liquibase
Secondary Sidebar
Spring Tutorial
  • Spring Boot
    • What is Spring Boot
    • Spring Boot flyway
    • Spring Boot framework
    • Spring Boot Logback
    • Spring Boot actuator endpoints
    • Spring Boot gRPC
    • Spring Boot jdbctemplate example
    • Spring Boot ehcache
    • Spring Boot Architecture
    • Spring Boot Port
    • Introduction of spring boot
    • Spring Boot ide
    • Spring Boot Netty
    • Spring Boot ORM
    • Spring Boot Versions
    • Spring Boot JUnit
    • Spring Boot Keycloak
    • Spring Boot gradle
    • Spring Boot Lombok
    • Spring Boot autowired
    • Spring Boot bean
    • Spring Boot hibernate
    • Spring Boot integration test
    • Spring Boot jdbc
    • Spring Boot MongoDB
    • Spring Boot postgresql
    • Spring Boot rest
    • Spring Boot swagger
    • Spring Boot thymeleaf
    • Spring Boot Unit Test
    • Spring Boot Webflux
    • Spring Boot webclient
    • Spring Boot kubernetes
    • Spring Boot Properties
    • Spring Boot Validation
    • Spring Boot Feature
    • Spring Boot Application
    • Spring Boot email
    • Spring Boot MVC
    • Spring Boot Exception Handling
    • Spring Boot Starter Parent
    • Spring Boot Docker
    • Spring Boot Logging
    • Spring Boot Query
    • Spring Boot Multiple Data Sources
    • Spring Boot Basic Authentication
    • Spring Boot Test
    • Spring Boot jwt
    • Spring Boot Liquibase
    • Spring Boot Prometheus
    • Spring Boot debug
    • Spring Boot GraalVM
    • Spring Boot Batch
    • Spring Boot controller
    • Spring Boot CLI
    • Spring Boot file upload
    • Spring Boot interceptor
    • Spring Boot Service
    • Spring Boot Configuration
    • Spring Boot Datasource Configuration
    • Spring Boot Annotations
    • Spring Boot Starter We
    • Spring Boot Actuator
    • Spring Boot DevTools
    • Spring Boot Repository
    • Spring Boot Dependencies
    • Spring Boot Path Variable
    • Spring Boot Microservices
    • Spring Boot Run Command
    • Spring Boot application.properties
    • Spring Boot Transaction Management
    • Spring Boot Banner
    • Spring Boot JPA
    • Spring Boot Change Port
    • Spring Boot RestTemplate
    • Spring Boot cors
    • Spring Boot HTTPS
    • Spring Boot OAuth2
    • Spring Boot Profiles
    • Spring Boot Interview Questions
    • Spring Boot filter
    • Spring boot logging level
    • Spring Boot Cache
    • Spring Boot Advantages
    • Spring Boot Scheduler
    • Spring Boot Initializr
    • Spring Boot Maven
    • Spring Boot Admin
    • Spring Boot Tomcat
    • Spring Boot WebSocket
    • Spring Boot Executable Jar
    • Spring Boot CommandLineRunner
    • Spring Boot DataSource
    • Spring Batch Scheduler
    • Spring Batch Example
    • Spring Batch Tasklet
    • Spring Batch Admin
    • Spring Batch
    • Spring Boot Qualifier
    • Spring Boot War
    • Spring Boot Test Configuration
  • Spring
    • What is Spring Framework?
    • Spring Architecture
    • What is Spring Integration?
    • IoC Containers
    • What is AOP?
    • Spring Modules
    • Spring Batch Processing
    • Spring Batch Partitioner
    • Spring Batch Job
    • Spring AOP
    • Spring Expression Language
    • Dependency Injection in Spring
    • Spring Batch Architecture
    • Spring framework Interview Questions
  • Spring Cloud Basics
    • What is Spring Cloud
    • Spring Cloud Contract
    • Spring Cloud Components
    • Spring Cloud Version
    • Spring Cloud Data Flow
    • Spring cloud stream
    • Spring Cloud Dependencies
    • Spring cloud microservices
    • spring cloud gateway
    • Spring Cloud Config
    • Spring Cloud Kubernetes
    • Spring Cloud Sleuth

Related Courses

Spring Boot Certification Course

Spring Framework Course Training

All in One Data Science Course

Spring Boot Liquibase

Spring Boot Liquibase

Definition of Spring Boot Liquibase

It is an open-source tool that was used for version control for databases and also used in database schema migration. This tool is supported in many RDBMS databases like MySQL, PostgreSQL, Oracle, and MSSQL, also it will supporting in different types of formats like SQL, XML, JSON, and YAML. It is also a vendor-independent database which means it will not depend on any database-specific syntax, it will also generate the change documentation of the database. Using this tool we can create a table and also do all the operations on the database server.

What is Spring Boot Liquibase?

  • It is used to keep track of script revision of database schema. It is working on many databases and accepting multiple file-formats to define the structure of the database.
  • Using this we can roll back our changes in the database also we can forward it to the given point. Also, we can remove the changes from the database to remember which script we have executed on the database instance.
  • It is used when it was necessary to revert or update the changes from the database server.
  • Also, we can use to migrate the database schema changes from one version to another version. It is similar to spring boot flyway both tools are used in database schema migration.
  • Using this tool it is possible to manage the change in a variety of files and use the monitoring and report the same it on the dashboard.

Using spring boot liquibase

  • We can use to develop the java application which was started by using a jar file.
  • We can do a migration of schema changed from the database server.
  • Also, spring boot features are include logging, profiles, security, integration, testing, and many more.
  • Below are the prerequisites which were we required at the time of developing the project.

Pre-requisites

1) Project – Maven Project
2) Spring boot version – 2.6.0
3) Packaging – Jar
4) Java – 11
5) Dependencies – PostgreSQL driver, Spring data JPA, liquibase migration
6) Spring tool suite

It has some important properties which were we have defined in the application.properties file.

1) Spring.liquibase.change-log –

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

This is the change log configuration path.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,818 ratings)

2) Spring.liquibase.url –

This is the database migration URL.

3) Spring.liquibase.user –

This is the database migration user.

4) Spring.liquibase.password –

This is the database migration password.

5) Spring.liquibase.liquibase-tablespace –

This is liquibase object tablespace.

6) Spring.liquibase.default-schema –

It is a database default schema.

7) Spring.liquibase.database-change-log-table –

This is the table name of change history.

8) Spring.liquibase.context –

It is the runtime context of comma-separated list.

9) Spring.liquibase.database-change-log-lock-table –

This is table name that was used to track the liquibase activities.

10) Spring.liquibase.labels –

It is runtime labels of the comma-separated list.

Create the project

Below is the example of creating the spring boot liquibase project are as follows.

1) Create a project template using spring initializer and give the following name to the project.

In the below step we have provided project group name as com. example, artifact name as spring-boot-liquibase, project name as spring-boot-liquibase, package as a jar file, and selecting java version as 11.

Group – com. example
Artifact name – spring-boot-liquibase
Name – spring-boot-liquibase
Description - Project for spring-boot-liquibase
Package name - com.example.spring-boot-liquibase
Packaging – Jar
Java – 11
Dependencies – spring web, PostgreSQL driver, spring data JPA and liquibase migration

Spring Boot Liquibase 1-1

2) After generating project extract files and open this project by using spring tool suite –

Spring Boot Liquibase 1-2

3) After opening the project using the spring tool suite check the project and its files –

Spring Boot Liquibase 1-3

Examples

Below is the example of spring boot liquibase are as follows.

1) Add dependency packages –

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.liquibase</groupId> -- Start and end of groupId tag.
<artifactId>liquibase-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 Liquibase 1-4

2) Configure the application.properties file –

Code:

spring.datasource.url = jdbc:postgresql://localhost/spring_boot_liquibase
spring.datasource.username = postgresql
spring.datasource.password = postgresql
spring.datasource.platform = postgresql
spring.jpa.hibernate.ddl-auto=update

Spring Boot Liquibase 1-5

3) Create liquibase change log file –

Code:

databaseChangeLog:
- include:
file: db/changelog/stud-schema.xml
- include:
file: db/changelog/stud-data.xml

Spring Boot Liquibase o

4) Create stud-schema.xml file –

Code:

<createTable tableName="stud" --- Create table name as stud.
Remarks ="stud Data">
<column name="stud_id" type="int" autoIncrement="true">
</column> -- End of column tag
<column name="stud_name" type="varchar (10)"> -- Start of column name tag.
</column> -- End of column tag
</createTable>

p

5) Create stud-data.xml file –

Code:

<comment> Inserting stud records</comment> -- Start and end of comment tag.
<insert tableName="stud">
<column name="stud_id" valueNumeric="1"/>
<column name="stud_name" value="ABC"/>
</insert> -- End of insert tag.
<insert tableName="stud">
<column name="stud_id" valueNumeric="2"/>
<column name="stud_name" value="PQR"/>
</insert> -- End of insert tag.
<insert tableName="company">
<column name="stud_id" valueNumeric="3"/>
<column name="stud_name" value="XYZ"/>
</insert> -- End of insert tag.

k

6) Run the application –

l

7) Check the table is created and data is inserted into stud table –

Code:

Select * from stud;

f

Important spring boot liquibase

  • It is a very important migration tool that was used and helps us to create the database schema, after creating schema it will run deployment of database server also it will do some sanity check to ensure that all changes which were we have done are properly working or not.
  • It provides a good starting point to address the team which came to manage the schema changes of the database.
  • It has the ability to roll back and forward our database changes to a specific point. To use spring boot liquibase in our project we need to add the liquibase dependency.

Conclusion

Spring boot liquibase has the ability to manage and revision of our database schema scripts. Spring boot liquibase is an open-source tool that was used for version control for databases. We can run liquibase on a spring boot environment by using the liquibase spring bean.

Recommended Articles

This is a guide to Spring Boot Liquibase. Here we discuss the Definition, What is Spring Boot Liquibase, Prerequisites, examples. You may also have a look at the following articles to learn more –

  1. Spring Boot Validation
  2. Spring Boot Properties
  3. Spring Boot Exception Handling
  4. Spring Boot Logging
Popular Course in this category
Spring Boot Training Program (2 Courses, 3 Project)
  2 Online Courses |  3 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Spring Framework Training (4 Courses, 6 Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

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

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more