SlideShare a Scribd company logo
source control for your DB
why
Data Base migration:
Data base structure:
- Tables, constrains, indexes;
Data base data:
- Initial data like list of post codes,
statuses for order, etc.
Data base logic:
- stored procedures, triggers, functions
why
Data Base migration:
Data base structure:
- Tables, constrains, indexes;
Data base data:
- Initial data like list of post codes,
statuses for order, etc.
Data base logic:
- stored procedures, triggers, functions
v1.0.0
why
Data Base migration:
Data base structure:
- Tables, constrains, indexes;
Data base data:
- Initial data like list of post codes,
statuses for order, etc.
Data base logic:
- stored procedures, triggers, functions
v1.2.1
v1.0.0
why
Data Base migration:
Data base structure:
- Tables, constrains, indexes;
Data base data:
- Initial data like list of post codes,
statuses for order, etc.
Data base logic:
- stored procedures, triggers, functions
v1.2.1
v1.6.0
v1.0.0
why
Data Base migration:
Data base structure:
- Tables, constrains, indexes;
Data base data:
- Initial data like list of post codes,
statuses for order, etc.
Data base logic:
- stored procedures, triggers, functions
v1.2.1
v1.6.0
v2.0.1
v1.0.0
why
Data Base migration:
Data base structure:
- Tables, constrains, indexes;
Data base data:
- Initial data like list of post codes,
statuses for order, etc.
Data base logic:
- stored procedures, triggers, functions
v1.2.1
v1.6.0
v2.0.1
v1.0.0
What
Liquibase :
•Apache license
•Started in 2006 (active)
What
Liquibase :
•Database migration for Java;
•Can be used as
•Ant, Maven or Gradle plugin,
•as CLI tool;
• as part of the system :
•Servlet Listener
•Spring Listener
•JEE CDI Listener
how it works
•Supports multiple database types:
MySQL, PostgreSQL, Oracle, MsSql,
Sybase_Enterprise, Sybase_Anywhere , DB2,
Apache_Derby, HSQL, H2, Informix, Firebird,
SQLite
how it works
Changes are grouped into changesets:
• Change(s) that should be applied
atomically
Changesets are grouped into
changelogs:
•Files managed in version control
how it works
Supports XML, YAML, JSON (DSL for database changes)
and SQL formats:
•Create Table, Add PK, Add FK, Add
Column, Add Index, …
•Drop Table, Drop PK, Drop FK, Drop
Column, Drop Index, …
•Insert, Update, Delete, …
how it works
•Changeslog (XML):
<databaseChangeLog xmlns=…>
<changeSet author="liquibase-docs“
id="addColumn-example">
<addColumn catalogName="cat“
schemaName="public"
tableName="person">
<column name="address"
type="varchar(255)"/> </addColumn>
</changeSet>
<changeSet> ….</changeset>
<changeSet> ….</changeset>
</databaseChangeLog>
how it works
•Changeslog (YAML):
databaseChangeLog:
changeSet:
id: addColumn-example
author: liquibase-docs
changes:
- addColumn:
catalogName: cat
columns:
- column:
name: address
type: varchar(255)
schemaName: public
tableName: person
how it works
•Changeslog (JSON){
databaseChangeLog: [
"changeSet": {
"id": "addColumn-example",
"author": "liquibase-docs",
"changes": [
{
"addColumn": {
"catalogName": "cat",
"columns": [
{
"column": {
"name": "address",
"type": "varchar(255)“
}
}]
,
"schemaName": "public",
"tableName": "person"
}
}]
}
how it works
- Changesets uniquely identified by [Author, ID, File path]
- Liquibase tracks changeset execution in a special table
- Lock table to prevent concurrent Liquibase invocations
- Modified changesets are detected via checksums
how it works
DatabaseChangelogLock:
DatabaseChangelog:
how it works
CLI commands:
update [Count, Tag]
rollback [Count, Data, Tag]
generateChangeLog --diffTypes=tables, views,
columns, indexes, foreignkeys, primarykeys,
uniqueconstraints, data
diff --referenceUrl=<value>
status --verbose
updateSQL ...
let us try it
DDLv1
DDL
v2
v1
Init data,
new column
(source)
let us try it
how it works
DDL
v2
v3
v1
Init data,
new column
(source)
Move values in
separate table
let us try it
let us try it
DDL
v2
v3
v1
Init data,
new column
(source)
Move values in
separate table
how it works
DEMO
how it works
Spring config (embedded in your
application):
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="myDataSource" />
<property name="changeLog" value="classpath:db-changelog.xml" />
<!-- contexts specifies the runtime contexts to use. -->
<property name="contexts" value="test, production" />
</bean>
how it works
Spring Boot config (embedded in your
application ):
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>
none
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-liquibase
how it works
•Also:
<changeSet id="4" dbms="oracle">
<sqlFile path="5.sql"/>
</changeSet>
<changeSet id="5" context="test">
<sqlFile path="5.sql"/>
</changeSet>
<changeSet id="6" failOnError="false">
<sqlFile path="6.sql"/>
</changeSet>
how it works
•Also:
<preConditions>
<dbms type="oracle" />
<runningAs username="SYSTEM" />
</preConditions>
<changeSet id="1" author="bob">
<preConditions onFail="WARN">
<sqlCheck expectedResult="0">
select count(*) from oldtable
</sqlCheck>
</preConditions>
<comment>Comments should go after preCondition. If they are before then
liquibase usually gives error.</comment>
<dropTable tableName="oldtable"/>
</changeSet>
recommendations
• it is better to have each change in separate changes ;
• Document changesets with <comment> tag;
• Folders structure should reflect migration structure
com
example
db
changelog
db.changelog-master.xml
db.changelog-1.0.xml
db.changelog-1.1.xml
db.changelog-2.0.xml
peculiarities
•if you do roll back, Liquibase deletes the log line about the update from
databasechangelog table, and after that Liguibase does not know any more
that this change was applied and reverted;
•all changes are applied sequentially, so we can not apply/rollback
separate mediate changes;
•no straightforward way of customizing warn/error messages;
peculiarities
•Each change set has an “id” and “author” attribute which, along with the directory
and file name of the the change log file, uniquely identifies it. Dark side of it is that
running the same change set using relative and absolute path will be considered
as different changesets!
For example we have file /home/user/changelog-0.1.0.xml
First we execute:
$ liquibase --changeLogFile=/home/user/changelog-0.1.0.xml
and then if we try to execute
$ liquibase --changeLogFile=changelog-0.1.0.xml
The end
Thank you for attention
Q & A
r.uholnikov@levi9.com

More Related Content

PPTX
Continuous DB Changes Delivery With Liquibase
PPTX
Database versioning with liquibase
PPT
LiquiBase
ODP
Liquibase & Flyway @ Baltic DevOps
PDF
Introduction To Liquibase
PPTX
Liquibase
PPTX
Database change management with Liquibase
PPTX
Liquibase
Continuous DB Changes Delivery With Liquibase
Database versioning with liquibase
LiquiBase
Liquibase & Flyway @ Baltic DevOps
Introduction To Liquibase
Liquibase
Database change management with Liquibase
Liquibase

What's hot (20)

PPTX
Liquibase case study
PPTX
Database Change Management as a Service
PPTX
Database Migrations with Gradle and Liquibase
PPTX
Liquibase for java developers
PDF
MySQL Performance Schema in 20 Minutes
PPTX
Successful DB migrations with Liquibase
PDF
Intro To MongoDB
PDF
Git - An Introduction
PDF
cours java complet-2.pdf
PDF
Spring Meetup Paris - Back to the basics of Spring (Boot)
PPTX
Présentation de git
PDF
git - eine praktische Einführung
PPTX
Capabilities for Resources and Effects
PDF
Always on 可用性グループ 構築時のポイント
PDF
PostgreSQL : Introduction
PDF
Introduzione a Git (ITA - 2017)
PDF
Get to know PostgreSQL!
PPTX
Maria db 이중화구성_고민하기
PDF
Altinity Quickstart for ClickHouse
PPTX
Tuning PostgreSQL for High Write Throughput
Liquibase case study
Database Change Management as a Service
Database Migrations with Gradle and Liquibase
Liquibase for java developers
MySQL Performance Schema in 20 Minutes
Successful DB migrations with Liquibase
Intro To MongoDB
Git - An Introduction
cours java complet-2.pdf
Spring Meetup Paris - Back to the basics of Spring (Boot)
Présentation de git
git - eine praktische Einführung
Capabilities for Resources and Effects
Always on 可用性グループ 構築時のポイント
PostgreSQL : Introduction
Introduzione a Git (ITA - 2017)
Get to know PostgreSQL!
Maria db 이중화구성_고민하기
Altinity Quickstart for ClickHouse
Tuning PostgreSQL for High Write Throughput
Ad

Viewers also liked (17)

KEY
Database Refactoring With Liquibase
PPT
Liquibase – a time machine for your data
PDF
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
PDF
Database migrations with Flyway and Liquibase
PDF
GWT widget development
PDF
Liquibase få kontroll på dina databasförändringar
PPTX
Architecting for continuous delivery (33rd Degree)
PDF
Last Month in PHP - February 2017
PDF
Continuous Delivery and Zero Downtime: What your architecture needs to succeed
PPTX
Flyway: The agile database migration framework for Java
PPTX
Flyway (33rd Degree)
PPTX
Refactoring domain driven design way
PPT
Unit Tests? It is Very Simple and Easy!
PPTX
Getting started with agile database migrations for java flywaydb
PDF
Database migration with flyway
KEY
Database Refactoring With Liquibase
Database Refactoring With Liquibase
Liquibase – a time machine for your data
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Database migrations with Flyway and Liquibase
GWT widget development
Liquibase få kontroll på dina databasförändringar
Architecting for continuous delivery (33rd Degree)
Last Month in PHP - February 2017
Continuous Delivery and Zero Downtime: What your architecture needs to succeed
Flyway: The agile database migration framework for Java
Flyway (33rd Degree)
Refactoring domain driven design way
Unit Tests? It is Very Simple and Easy!
Getting started with agile database migrations for java flywaydb
Database migration with flyway
Database Refactoring With Liquibase
Ad

Similar to Liquibase migration for data bases (20)

PDF
Roman Ugolnikov Migrationа and sourcecontrol for your db
PDF
SE2016 Java Roman Ugolnikov "Migration and source control for your DB"
PDF
Take your database source code and data under control
PPTX
ETL
PPTX
PostgreSQL Database Slides
PDF
Access Data from XPages with the Relational Controls
PPT
Optimizing Data Accessin Sq Lserver2005
PPTX
Advance Sql Server Store procedure Presentation
PPTX
ORACLE APPS DBA ONLINE TRAINING
PPTX
Day 1 - Technical Bootcamp azure synapse analytics
PPTX
Dynamic Publishing with Arbortext Data Merge
PPTX
Microsoft Data Integration Pipelines: Azure Data Factory and SSIS
PPT
Jsf2.0 -4
PPTX
Migrating to SharePoint 2013 - Business and Technical Perspective
PPT
Managing SQLserver
ODP
Handling Database Deployments
PPTX
SQL Server 2008 Development for Programmers
PDF
Lifecycle Management of SOA Artifacts for WSO2 Products
PDF
SQL Server 2014 Monitoring and Profiling
PPT
Sql Server 2005 Business Inteligence
Roman Ugolnikov Migrationа and sourcecontrol for your db
SE2016 Java Roman Ugolnikov "Migration and source control for your DB"
Take your database source code and data under control
ETL
PostgreSQL Database Slides
Access Data from XPages with the Relational Controls
Optimizing Data Accessin Sq Lserver2005
Advance Sql Server Store procedure Presentation
ORACLE APPS DBA ONLINE TRAINING
Day 1 - Technical Bootcamp azure synapse analytics
Dynamic Publishing with Arbortext Data Merge
Microsoft Data Integration Pipelines: Azure Data Factory and SSIS
Jsf2.0 -4
Migrating to SharePoint 2013 - Business and Technical Perspective
Managing SQLserver
Handling Database Deployments
SQL Server 2008 Development for Programmers
Lifecycle Management of SOA Artifacts for WSO2 Products
SQL Server 2014 Monitoring and Profiling
Sql Server 2005 Business Inteligence

Recently uploaded (20)

PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
composite construction of structures.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Digital Logic Computer Design lecture notes
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
web development for engineering and engineering
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Welding lecture in detail for understanding
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
additive manufacturing of ss316l using mig welding
PDF
PPT on Performance Review to get promotions
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPT
Project quality management in manufacturing
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Well-logging-methods_new................
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
composite construction of structures.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Digital Logic Computer Design lecture notes
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
web development for engineering and engineering
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Welding lecture in detail for understanding
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
additive manufacturing of ss316l using mig welding
PPT on Performance Review to get promotions
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Project quality management in manufacturing
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Well-logging-methods_new................
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Model Code of Practice - Construction Work - 21102022 .pdf

Liquibase migration for data bases

  • 2. why Data Base migration: Data base structure: - Tables, constrains, indexes; Data base data: - Initial data like list of post codes, statuses for order, etc. Data base logic: - stored procedures, triggers, functions
  • 3. why Data Base migration: Data base structure: - Tables, constrains, indexes; Data base data: - Initial data like list of post codes, statuses for order, etc. Data base logic: - stored procedures, triggers, functions v1.0.0
  • 4. why Data Base migration: Data base structure: - Tables, constrains, indexes; Data base data: - Initial data like list of post codes, statuses for order, etc. Data base logic: - stored procedures, triggers, functions v1.2.1 v1.0.0
  • 5. why Data Base migration: Data base structure: - Tables, constrains, indexes; Data base data: - Initial data like list of post codes, statuses for order, etc. Data base logic: - stored procedures, triggers, functions v1.2.1 v1.6.0 v1.0.0
  • 6. why Data Base migration: Data base structure: - Tables, constrains, indexes; Data base data: - Initial data like list of post codes, statuses for order, etc. Data base logic: - stored procedures, triggers, functions v1.2.1 v1.6.0 v2.0.1 v1.0.0
  • 7. why Data Base migration: Data base structure: - Tables, constrains, indexes; Data base data: - Initial data like list of post codes, statuses for order, etc. Data base logic: - stored procedures, triggers, functions v1.2.1 v1.6.0 v2.0.1 v1.0.0
  • 9. What Liquibase : •Database migration for Java; •Can be used as •Ant, Maven or Gradle plugin, •as CLI tool; • as part of the system : •Servlet Listener •Spring Listener •JEE CDI Listener
  • 10. how it works •Supports multiple database types: MySQL, PostgreSQL, Oracle, MsSql, Sybase_Enterprise, Sybase_Anywhere , DB2, Apache_Derby, HSQL, H2, Informix, Firebird, SQLite
  • 11. how it works Changes are grouped into changesets: • Change(s) that should be applied atomically Changesets are grouped into changelogs: •Files managed in version control
  • 12. how it works Supports XML, YAML, JSON (DSL for database changes) and SQL formats: •Create Table, Add PK, Add FK, Add Column, Add Index, … •Drop Table, Drop PK, Drop FK, Drop Column, Drop Index, … •Insert, Update, Delete, …
  • 13. how it works •Changeslog (XML): <databaseChangeLog xmlns=…> <changeSet author="liquibase-docs“ id="addColumn-example"> <addColumn catalogName="cat“ schemaName="public" tableName="person"> <column name="address" type="varchar(255)"/> </addColumn> </changeSet> <changeSet> ….</changeset> <changeSet> ….</changeset> </databaseChangeLog>
  • 14. how it works •Changeslog (YAML): databaseChangeLog: changeSet: id: addColumn-example author: liquibase-docs changes: - addColumn: catalogName: cat columns: - column: name: address type: varchar(255) schemaName: public tableName: person
  • 15. how it works •Changeslog (JSON){ databaseChangeLog: [ "changeSet": { "id": "addColumn-example", "author": "liquibase-docs", "changes": [ { "addColumn": { "catalogName": "cat", "columns": [ { "column": { "name": "address", "type": "varchar(255)“ } }] , "schemaName": "public", "tableName": "person" } }] }
  • 16. how it works - Changesets uniquely identified by [Author, ID, File path] - Liquibase tracks changeset execution in a special table - Lock table to prevent concurrent Liquibase invocations - Modified changesets are detected via checksums
  • 18. how it works CLI commands: update [Count, Tag] rollback [Count, Data, Tag] generateChangeLog --diffTypes=tables, views, columns, indexes, foreignkeys, primarykeys, uniqueconstraints, data diff --referenceUrl=<value> status --verbose updateSQL ...
  • 19. let us try it DDLv1
  • 21. how it works DDL v2 v3 v1 Init data, new column (source) Move values in separate table let us try it
  • 22. let us try it DDL v2 v3 v1 Init data, new column (source) Move values in separate table
  • 24. how it works Spring config (embedded in your application): <dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> <version>${liquibase.version}</version> </dependency> <bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase"> <property name="dataSource" ref="myDataSource" /> <property name="changeLog" value="classpath:db-changelog.xml" /> <!-- contexts specifies the runtime contexts to use. --> <property name="contexts" value="test, production" /> </bean>
  • 25. how it works Spring Boot config (embedded in your application ): <dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> <version>${liquibase.version}</version> </dependency> none https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-liquibase
  • 26. how it works •Also: <changeSet id="4" dbms="oracle"> <sqlFile path="5.sql"/> </changeSet> <changeSet id="5" context="test"> <sqlFile path="5.sql"/> </changeSet> <changeSet id="6" failOnError="false"> <sqlFile path="6.sql"/> </changeSet>
  • 27. how it works •Also: <preConditions> <dbms type="oracle" /> <runningAs username="SYSTEM" /> </preConditions> <changeSet id="1" author="bob"> <preConditions onFail="WARN"> <sqlCheck expectedResult="0"> select count(*) from oldtable </sqlCheck> </preConditions> <comment>Comments should go after preCondition. If they are before then liquibase usually gives error.</comment> <dropTable tableName="oldtable"/> </changeSet>
  • 28. recommendations • it is better to have each change in separate changes ; • Document changesets with <comment> tag; • Folders structure should reflect migration structure com example db changelog db.changelog-master.xml db.changelog-1.0.xml db.changelog-1.1.xml db.changelog-2.0.xml
  • 29. peculiarities •if you do roll back, Liquibase deletes the log line about the update from databasechangelog table, and after that Liguibase does not know any more that this change was applied and reverted; •all changes are applied sequentially, so we can not apply/rollback separate mediate changes; •no straightforward way of customizing warn/error messages;
  • 30. peculiarities •Each change set has an “id” and “author” attribute which, along with the directory and file name of the the change log file, uniquely identifies it. Dark side of it is that running the same change set using relative and absolute path will be considered as different changesets! For example we have file /home/user/changelog-0.1.0.xml First we execute: $ liquibase --changeLogFile=/home/user/changelog-0.1.0.xml and then if we try to execute $ liquibase --changeLogFile=changelog-0.1.0.xml
  • 31. The end Thank you for attention Q & A r.uholnikov@levi9.com

Editor's Notes