SlideShare a Scribd company logo
2
Most read
5
Most read
6
Most read
Core Systems Transformation Solutions
Database versioning with Liquibase
Maxim Bukov
Confidential 2
Agenda
In scope: What is liquibase?
How does liquibase database versioning works?
How to start using liquibase?
Liquibase main features.
Examples.
Confidential 3
Database Versioning: Problem
DEV
• Nick’s Database
• Andrew’s Database
• Michael’s Database
TEST
• Database 1
• Database 2
PROD
• Database
The questions are:
• What state is the database in on this machine?
• Has this script already been applied or not?
• Has the quick fix in production been applied in test afterwards?
• How do you set up a new database instance?
Confidential 4
Database Versioning: Solution
Defined Upgrade Path History Of Changes
Intelligent update Rollback ability
Database Versioning
Major benefits:
• Recreate a database from scratch.
• Make it clear at all times what state a database is in.
• Migrate in a deterministic way from your current version of the
database to a newer or even elder one
Confidential 5
Database Versioning: Tools
State-driven Migration-driven
Red Gate SQL Compare $
Visual Studio Database Projects $
Liquibase
Flyway
Datical $
Confidential 6
Liquibase: Intro
Liquibase is a open source database-independent tool for managing and
executing database changes.
Version Control
System
Continuous
Integration Tool
Liquibase Target
Database
Main features:
• Provides update / rollback / comparison capabilities.
• Supports multiple databases (Oracle, MySQL, MSSQL, etc.).
• Works via cmd, Ant, Maven, servlet container or Spring framework.
Confidential 7
Formats
XML
SQL
Oracle
MySQL
MSSQL
…
YAML
JSON
Liquibase: Change Set
Change Set a.k.a migration - atomic database change description.
Confidential 8
Liquibase: Change Set structure
<changeSet author="mbukov" id="lb-play-example-01-01">
<preConditions onFail="HALT">
<sqlCheck expectedResult="0">
SELECT SUM(DECODE(TABLE_NAME, 'EMPLOYEE',1, 0))
FROM dba_tables
WHERE owner = sys_context('USERENV','SESSION_SCHEMA')
GROUP BY OWNER;
</sqlCheck>
</preConditions>
<comment>table with data on each employee</comment>
<createTable tableName="EMPLOYEE">
<column name="EMPLOYEE_ID" type="NUMBER">
<constraints nullable="false"/>
</column>
<column name="NAME" type="VARCHAR2(50)"/>
<column name="HIRED_DATE" type="date"/>
<column name="IS_ACTIVE" type="NUMBER" defaultValueNumeric="1">
<constraints nullable="false"/>
</column>
</createTable>
<rollback>
drop table EMPLOYEE;
</rollback>
</changeSet>
Confidential 9
Liquibase: Change Log
Master Change Log
Change Log 1
Change Set 1
Change Set 2
Change Set 3
Change Log 2
Change Set 4
Change Set 5
Change Log 3 Change Set 6
Change Log - file with list of database changes to apply.
Confidential 10
java -jar liquibase.jar
--classpath=ojdbc.jar
--driver=oracle.jdbc.OracleDriver
--url=jdbc:oracle:thin:@test:1821:orcl
--username=schema_name
--password=p@ssw0rd
--logLevel=info
--changeLogFile=db.changelog.master.xml
--defaultsFile=./liquibase.properties
generateChangeLog update
rollbackToDate 2016-01-01T00:00:00
…
-Dchl_param=test_val
Liquibase: Run with cmd
Confidential 11
Liquibase: Generate change log
Data
Tables
Columns
Views
Primary keys
Unique constraints
Indexes
Foreign keys
Sequences
Included:
Procedures
Functions
Packages
Excluded:
generateChangeLog Generates change log to create the current database schema
Special parameters
diffTypes List of objects to take into account.
generateChangeLog Output file name. Format depends on file extension.
Example
#1
Confidential 12
Liquibase: Update
update Updates database to current version.
updateCount <value> Applies the next <value> change sets.
Special parameters
--changeLogFile=<path and filename> The changelog file to use.
DATABASECHANGELOG
ID
AUTHOR
FILENAME
DATEEXECUTED
ORDEREXECUTED
MD5SUM
DESCRIPTION
COMMENTS
TAG
CONTEXTS
DATABASECHANGELOGLOCK
ID
LOCKED
LOCKGRANTED
LOCKEDBY
Example
#2
Confidential 13
Liquibase: Rollback
updateTestingRollback Updates, then rolls changes back and updates again.
rollback <tag> Rolls back to the state when it was tagged.
rollbackCount <value> Rolls back the last <value> change sets.
rollbackToDate <date/time> Rolls back to the state it was in at the given date/time.
Special parameters
--changeLogFile=<path and filename> The changelog file to use.
Example
#3
Liquibase refactorings with auto generated rollback:
AddColumn
AddDefaultValue
AddForeignKeyConstraint
AddLookupTable
AddNotNullConstraint
AddPrimaryKey
AddUniqueConstraint
CreateIndex
CreateSequence
CreateTable
CreateView
DropNotNullConstraint
RenameColumn
RenameTable
RenameView
TagDatabase
Confidential 14
Liquibase: Checksum
Checksum is MD5 hash used to detect differences between what is
currently in the changelog and what was actually ran against the
database.
Checksum is individually calculated and stored for each changeset.
Check sum is affected by:
• Database change related tags
• SQL formatting
• Liquibase/changelog parameters
Check sum is not affected by:
• Non-database change related tags.
• XML formatting
Checksum fix tips:
• runOnChange
• validCheckSum
• clearCheckSums
Example
#4
Confidential 15
Liquibase: Other commands
status Outputs count (list if --verbose) of unrun change sets.
validate Checks the changelog for errors.
updateSQL Writes SQL to update database to current version.
futureRollbackSQL Writes SQL to roll back the database to the current state after the
changes in the changelog have been applied.
diff Writes description of differences to standard out.
dbDoc Generates Javadoc-like documentation based on current database
and change log.
dropAll Drops all database objects owned by the user.
Confidential 16
Conclusion
Questions?
TBC:
How to write change sets
Multiple database support
Making most out of XML
How to organize files
How to test scripts

More Related Content

ODP
Liquibase & Flyway @ Baltic DevOps
PPTX
Continuous DB Changes Delivery With Liquibase
PPTX
Liquibase migration for data bases
PPT
LiquiBase
PPTX
Database change management with Liquibase
PDF
Introduction To Liquibase
PPTX
Liquibase
PPTX
Database Change Management as a Service
Liquibase & Flyway @ Baltic DevOps
Continuous DB Changes Delivery With Liquibase
Liquibase migration for data bases
LiquiBase
Database change management with Liquibase
Introduction To Liquibase
Liquibase
Database Change Management as a Service

What's hot (20)

PPTX
Liquibase
PDF
Gestión de Cambios de BBDD con LiquiBase
PPTX
Liquibase case study
PDF
Logging with Elasticsearch, Logstash & Kibana
PPTX
Flyway: The agile database migration framework for Java
PDF
Introduction to Testcontainers
PDF
InnoDB Locking Explained with Stick Figures
PDF
Event Driven-Architecture from a Scalability perspective
PPTX
Git 101 for Beginners
PDF
Database migrations with Flyway and Liquibase
PPTX
Apache NiFi Crash Course Intro
PDF
CDC patterns in Apache Kafka®
PDF
Performance Tuning RocksDB for Kafka Streams' State Stores (Dhruba Borthakur,...
KEY
Introduction To Git
PPTX
使用 Liquibase 發展資料庫結構
PPTX
Version control system
PPTX
Centralized log-management-with-elastic-stack
PDF
Postgresql database administration volume 1
PPTX
Successful DB migrations with Liquibase
Liquibase
Gestión de Cambios de BBDD con LiquiBase
Liquibase case study
Logging with Elasticsearch, Logstash & Kibana
Flyway: The agile database migration framework for Java
Introduction to Testcontainers
InnoDB Locking Explained with Stick Figures
Event Driven-Architecture from a Scalability perspective
Git 101 for Beginners
Database migrations with Flyway and Liquibase
Apache NiFi Crash Course Intro
CDC patterns in Apache Kafka®
Performance Tuning RocksDB for Kafka Streams' State Stores (Dhruba Borthakur,...
Introduction To Git
使用 Liquibase 發展資料庫結構
Version control system
Centralized log-management-with-elastic-stack
Postgresql database administration volume 1
Successful DB migrations with Liquibase
Ad

Similar to Database versioning with liquibase (20)

PPTX
Liquibase for java developers
PPTX
Getting Started with MySQL II
PDF
Access Data from XPages with the Relational Controls
PPT
Liquibase – a time machine for your data
PPT
Evolutionary Database Design
PDF
Liquibase få kontroll på dina databasförändringar
PDF
Performance Stability, Tips and Tricks and Underscores
PPTX
Li liq liqui liquibase
PPT
Tauhid: SQL Server Database Change Automation
PPTX
Copy Data Management for the DBA
PPTX
Schema migration in agile environmnets
PPTX
Denver SQL Saturday The Next Frontier
ODP
Handling Database Deployments
PDF
Rolta’s application testing services for handling ever changing environment.
PPT
SQL Server Replication Transactional Replication from MSSQL 200x to MYSQL 5.x
PDF
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
PPTX
Confoo 2021 -- MySQL New Features
PDF
Databus - Abhishek Bhargava & Maheswaran Veluchamy - DevOps Bangalore Meetup...
PDF
SQLSaturday#290_Kiev_AdHocMaintenancePlansForBeginners
PDF
Modernizing SQL Server the Right Way
Liquibase for java developers
Getting Started with MySQL II
Access Data from XPages with the Relational Controls
Liquibase – a time machine for your data
Evolutionary Database Design
Liquibase få kontroll på dina databasförändringar
Performance Stability, Tips and Tricks and Underscores
Li liq liqui liquibase
Tauhid: SQL Server Database Change Automation
Copy Data Management for the DBA
Schema migration in agile environmnets
Denver SQL Saturday The Next Frontier
Handling Database Deployments
Rolta’s application testing services for handling ever changing environment.
SQL Server Replication Transactional Replication from MSSQL 200x to MYSQL 5.x
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
Confoo 2021 -- MySQL New Features
Databus - Abhishek Bhargava & Maheswaran Veluchamy - DevOps Bangalore Meetup...
SQLSaturday#290_Kiev_AdHocMaintenancePlansForBeginners
Modernizing SQL Server the Right Way
Ad

More from Return on Intelligence (20)

PPTX
Clean Code Approach
PPTX
Code Coverage
PPTX
Effective Communication in english
PPTX
Anti-patterns
PPTX
Conflicts Resolving
PPTX
Effective Feedback
PPTX
English for Negotiations 2016
PPTX
Lean Software Development
PPT
Unit Tests? It is Very Simple and Easy!
PPTX
Quick Start to AngularJS
PPTX
Introduction to Backbone.js & Marionette.js
PPTX
Types of testing and their classification
PPTX
Introduction to EJB
PPTX
Enterprise Service Bus
PPTX
Apache cassandra - future without boundaries (part3)
PPTX
Apache cassandra - future without boundaries (part2)
PPTX
Apache cassandra - future without boundaries (part1)
PPTX
Career development in exigen services
PPTX
Introduction to selenium web driver
PPTX
Enterprise service bus part 2
Clean Code Approach
Code Coverage
Effective Communication in english
Anti-patterns
Conflicts Resolving
Effective Feedback
English for Negotiations 2016
Lean Software Development
Unit Tests? It is Very Simple and Easy!
Quick Start to AngularJS
Introduction to Backbone.js & Marionette.js
Types of testing and their classification
Introduction to EJB
Enterprise Service Bus
Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part2)
Apache cassandra - future without boundaries (part1)
Career development in exigen services
Introduction to selenium web driver
Enterprise service bus part 2

Recently uploaded (20)

PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Become an Agentblazer Champion Challenge Kickoff
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PPTX
FLIGHT TICKET RESERVATION SYSTEM | FLIGHT BOOKING ENGINE API
PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
PDF
Digital Strategies for Manufacturing Companies
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
ai tools demonstartion for schools and inter college
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
Presentation of Computer CLASS 2 .pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
Become an Agentblazer Champion Challenge Kickoff
ISO 45001 Occupational Health and Safety Management System
How to Choose the Right IT Partner for Your Business in Malaysia
VVF-Customer-Presentation2025-Ver1.9.pptx
How Creative Agencies Leverage Project Management Software.pdf
Odoo POS Development Services by CandidRoot Solutions
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Materi-Enum-and-Record-Data-Type (1).pptx
FLIGHT TICKET RESERVATION SYSTEM | FLIGHT BOOKING ENGINE API
The Role of Automation and AI in EHS Management for Data Centers.pdf
Digital Strategies for Manufacturing Companies
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Upgrade and Innovation Strategies for SAP ERP Customers
ai tools demonstartion for schools and inter college
Online Work Permit System for Fast Permit Processing
Presentation of Computer CLASS 2 .pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx

Database versioning with liquibase

  • 1. Core Systems Transformation Solutions Database versioning with Liquibase Maxim Bukov
  • 2. Confidential 2 Agenda In scope: What is liquibase? How does liquibase database versioning works? How to start using liquibase? Liquibase main features. Examples.
  • 3. Confidential 3 Database Versioning: Problem DEV • Nick’s Database • Andrew’s Database • Michael’s Database TEST • Database 1 • Database 2 PROD • Database The questions are: • What state is the database in on this machine? • Has this script already been applied or not? • Has the quick fix in production been applied in test afterwards? • How do you set up a new database instance?
  • 4. Confidential 4 Database Versioning: Solution Defined Upgrade Path History Of Changes Intelligent update Rollback ability Database Versioning Major benefits: • Recreate a database from scratch. • Make it clear at all times what state a database is in. • Migrate in a deterministic way from your current version of the database to a newer or even elder one
  • 5. Confidential 5 Database Versioning: Tools State-driven Migration-driven Red Gate SQL Compare $ Visual Studio Database Projects $ Liquibase Flyway Datical $
  • 6. Confidential 6 Liquibase: Intro Liquibase is a open source database-independent tool for managing and executing database changes. Version Control System Continuous Integration Tool Liquibase Target Database Main features: • Provides update / rollback / comparison capabilities. • Supports multiple databases (Oracle, MySQL, MSSQL, etc.). • Works via cmd, Ant, Maven, servlet container or Spring framework.
  • 7. Confidential 7 Formats XML SQL Oracle MySQL MSSQL … YAML JSON Liquibase: Change Set Change Set a.k.a migration - atomic database change description.
  • 8. Confidential 8 Liquibase: Change Set structure <changeSet author="mbukov" id="lb-play-example-01-01"> <preConditions onFail="HALT"> <sqlCheck expectedResult="0"> SELECT SUM(DECODE(TABLE_NAME, 'EMPLOYEE',1, 0)) FROM dba_tables WHERE owner = sys_context('USERENV','SESSION_SCHEMA') GROUP BY OWNER; </sqlCheck> </preConditions> <comment>table with data on each employee</comment> <createTable tableName="EMPLOYEE"> <column name="EMPLOYEE_ID" type="NUMBER"> <constraints nullable="false"/> </column> <column name="NAME" type="VARCHAR2(50)"/> <column name="HIRED_DATE" type="date"/> <column name="IS_ACTIVE" type="NUMBER" defaultValueNumeric="1"> <constraints nullable="false"/> </column> </createTable> <rollback> drop table EMPLOYEE; </rollback> </changeSet>
  • 9. Confidential 9 Liquibase: Change Log Master Change Log Change Log 1 Change Set 1 Change Set 2 Change Set 3 Change Log 2 Change Set 4 Change Set 5 Change Log 3 Change Set 6 Change Log - file with list of database changes to apply.
  • 10. Confidential 10 java -jar liquibase.jar --classpath=ojdbc.jar --driver=oracle.jdbc.OracleDriver --url=jdbc:oracle:thin:@test:1821:orcl --username=schema_name --password=p@ssw0rd --logLevel=info --changeLogFile=db.changelog.master.xml --defaultsFile=./liquibase.properties generateChangeLog update rollbackToDate 2016-01-01T00:00:00 … -Dchl_param=test_val Liquibase: Run with cmd
  • 11. Confidential 11 Liquibase: Generate change log Data Tables Columns Views Primary keys Unique constraints Indexes Foreign keys Sequences Included: Procedures Functions Packages Excluded: generateChangeLog Generates change log to create the current database schema Special parameters diffTypes List of objects to take into account. generateChangeLog Output file name. Format depends on file extension. Example #1
  • 12. Confidential 12 Liquibase: Update update Updates database to current version. updateCount <value> Applies the next <value> change sets. Special parameters --changeLogFile=<path and filename> The changelog file to use. DATABASECHANGELOG ID AUTHOR FILENAME DATEEXECUTED ORDEREXECUTED MD5SUM DESCRIPTION COMMENTS TAG CONTEXTS DATABASECHANGELOGLOCK ID LOCKED LOCKGRANTED LOCKEDBY Example #2
  • 13. Confidential 13 Liquibase: Rollback updateTestingRollback Updates, then rolls changes back and updates again. rollback <tag> Rolls back to the state when it was tagged. rollbackCount <value> Rolls back the last <value> change sets. rollbackToDate <date/time> Rolls back to the state it was in at the given date/time. Special parameters --changeLogFile=<path and filename> The changelog file to use. Example #3 Liquibase refactorings with auto generated rollback: AddColumn AddDefaultValue AddForeignKeyConstraint AddLookupTable AddNotNullConstraint AddPrimaryKey AddUniqueConstraint CreateIndex CreateSequence CreateTable CreateView DropNotNullConstraint RenameColumn RenameTable RenameView TagDatabase
  • 14. Confidential 14 Liquibase: Checksum Checksum is MD5 hash used to detect differences between what is currently in the changelog and what was actually ran against the database. Checksum is individually calculated and stored for each changeset. Check sum is affected by: • Database change related tags • SQL formatting • Liquibase/changelog parameters Check sum is not affected by: • Non-database change related tags. • XML formatting Checksum fix tips: • runOnChange • validCheckSum • clearCheckSums Example #4
  • 15. Confidential 15 Liquibase: Other commands status Outputs count (list if --verbose) of unrun change sets. validate Checks the changelog for errors. updateSQL Writes SQL to update database to current version. futureRollbackSQL Writes SQL to roll back the database to the current state after the changes in the changelog have been applied. diff Writes description of differences to standard out. dbDoc Generates Javadoc-like documentation based on current database and change log. dropAll Drops all database objects owned by the user.
  • 16. Confidential 16 Conclusion Questions? TBC: How to write change sets Multiple database support Making most out of XML How to organize files How to test scripts

Editor's Notes

  • #7: All changes to the database are stored in XML files and identified by a combination of an "id" and "author" tag as well as the name of the file itself. A list of all applied changes is stored in each database which is consulted on all database updates to determine what new changes need to be applied. When executed liquibase tries to connect to database with specified url, schema name and password and execute command. All information about previous liquibase executions is stored in change log table. This table will be created automatically at first liquibase execution.