Configuring Liquibase in Spring Boot

Configuring Liquibase in Spring Boot

Liquibase is a powerful database schema evolution tool that integrates excellent with Spring Boot projects. In this guide, we'll walk through the process of configuring Liquibase in a Spring Boot application using Kotlin and Gradle.

Step 1: Add Dependencies
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.liquibase:liquibase-core")

// Add your PostgreSQL dependency
implementation("org.postgresql:postgresql")
}

Run `./gradlew build` to fetch the updated dependencies.

Step 2: Create Liquibase Configuration

create a `liquibase.properties` file in `src/main/resources` with your postgreSQL database connection details and Liquibase settings:

Step 3: Create Liquibase Change Log

In the `src/main/resources/db/changelog` directory, create a `db.changelog-master.xml` file. This file will contain your database changes sets:

<!-- db.changelog-master.xml -->

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                            http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">

    <!-- Add your change sets here -->

</databaseChangeLog>
Step 4: Configure Liquibase in `application.properties`

Open your `application.properties` file and configure liquibase :

# application.properties

spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml

Step 5: Run Your Application

Exceute the following Gradle command to run your Spring Boot application:

./gradlew bootRun

Liquibase will automatically apply the database changes during the application startup.

Congratulations! You've successfully configured Liquibase in your Spring Boot project , with PostgreSQL as the database. Customize the database connection properties and change sets based on your project requirements.
NOTE: Adjust the PostgreSQL connection details according to your setup.

Read more

Retrieval-Augmented Generation (RAG): A Complete Guide to Architecture, Workflow, Use Cases, and Implementation

Retrieval-Augmented Generation (RAG): A Complete Guide to Architecture, Workflow, Use Cases, and Implementation

Category: Artificial Intelligence | Generative AI | Software Engineering 1. Introduction Large Language Models (LLMs) have transformed how applications interact with users by enabling natural language understanding, content generation, summarization, and conversational experiences. However, traditional LLMs have limitations. They may not know an organization's private information, may lack access to

By Sangram Ekshinge