Liquibase

Introduction

  • Liquibase is an open-source database schema change management tool that works well with Java projects (and other technologies). It helps developers manage database changes over time, track them in version control, and apply them consistently across different environments.

Setup

  • To apply liquibase plugin to the maven / gradle commands

Gradle

build.gradle
buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'org.liquibase:liquibase-core:4.25.1'
  }
}

plugins {
	id 'java'
	id 'org.springframework.boot' version '4.0.2'
	id 'io.spring.dependency-management' version '1.1.7'
	// apply liquibase to the command list
	id 'org.liquibase.gradle' version '3.1.0'
}


group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Gradle Playground'

java {
	toolchain {
		languageVersion = JavaLanguageVersion.of(21)
	}
}

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

ext {
	set('springCloudVersion', "2025.1.0")
}


dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-webmvc'
	implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
	implementation 'org.liquibase:liquibase-core'
	compileOnly 'org.projectlombok:lombok'
	runtimeOnly 'org.postgresql:postgresql'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test'
	testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
	liquibaseRuntime 'org.liquibase:liquibase-core:4.25.1'
	liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:4.0.1'
	liquibaseRuntime 'org.postgresql:postgresql:42.7.1'
	liquibaseRuntime 'info.picocli:picocli:4.7.5'
}


dependencyManagement {
	imports {
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}

// Liquibase script setting
liquibase {
    activities {
        main {
            changelogFile 'src/main/resources/db/changelog/db.changelog-master.yaml'
            url 'jdbc:postgresql://localhost:5433/postgres'
            username 'postgres'
            password 'admin'
            driver 'org.postgresql.Driver'
        }
        // Activity for generateChangeLog - outputs current DB schema
        generate {
            changelogFile 'src/main/resources/db/changelog/changes/generated-changelog.yaml'
            url 'jdbc:postgresql://localhost:5433/postgres'
            username 'postgres'
            password 'admin'
            driver 'org.postgresql.Driver'
        }
    }
    runList = project.hasProperty('runList') ? project.runList : 'main'
}

tasks.named('test') {
	useJUnitPlatform()
}

Maven

Migration Script

  • The migration script will be on resources/db/changelog/changes folder

Master

Example Creation Script

Example Update Script

Commands

Last updated