SlideShare a Scribd company logo
LIQUIDATING DATABASE
FRUSTRATIONS WITH
LIQUIBASE
Paul Churchward, FRM
September 23, 2016
THE OLD WAY
OF MANAGING DATABASE
CHANGES
 Database schema & reference data changes are applied manually to
each environment
local > DEV > SIT > PRE-PROD > PROD > DR
 SIT, and other production-like environments managed by DBA
 Nothing is kept in source control
 Highly manual. Highly error prone.
THE (SLIGHTLY BETTER) OLD WAY
 1 script per DB change
 Additional scripts for roll-back
 Scripts kept in source control
 Change existing scripts multiple times until they're right
 Scripts are applied manually to each environment
 SIT, and other production-like environments managed by DBA
 Still very manual. Still very error prone.
 Lots and lots of scripts
 Must keep track of the order of the scripts!
 Must keep track of which scripts to run on which deploys!
THE LIQUIBASE WAY
LIQUIBASE UPDATES THE DB
… NOT YOU
(MOST OF THE TIME)
 Each database schema & reference data change is added to source control
> developer choses how to organize them.
Examples:
One change log file per feature
One change log file
 Liquibase only executes new changes since last run
 Changes can be specified in database agnostic formats (XML, JSON) or SQL
 No merge conflicts.
 Never modify an existing change, always create a new one.
 Automatic rollback without a custom script (unless you want one)
 No more manual upgrades
EXAMPLE
A sample JSON changelog file
Each DB changes is added to a changeset, and
multiple change sets are added to a
changelog.
Each changeset has an author ID and an ID
that is unique to that author within the
changelog file
This create table change could have been
expressed in XML (also DB agnostic) or in
plain SQL with metadata in SQL comments
A project can support any number of
changelog files
Always create a new changeset, never alter an
existing one (except for stored procedures
and then use runOnChange attribute)
{
"databaseChangeLog": [
{
"changeSet": {
"id": "1",
"author": "Foo",
"changes": [
{
"createTable": {
"tableName": "person",
"columns": [
{
"column": {
"name": "id",
"type": "int",
"autoIncrement": true,
"constraints": {
"primaryKey": true,
"nullable": false
},
}
},
{
"column": {
"name": "firstname",
"type": "varchar(50)"
}
},
{
"column": {
"name": "lastname",
"type": "varchar(50)",
"constraints": {
"nullable": false
}
}
}
…
A sample SQL changelog file
SQL changesets are DBMS platform
dependent unlike XML and JSON formats
that are converted into platform
dependent SQL
Metadata is defined in SQL comments
Must provide your own rollback scripts
--liquibase formatted sql
--changeset Foo:1
create table test1 (
id int primary key,
name varchar(255)
);
--rollback drop table test1;
--changeset Foo:2
insert into test1 (id, name) values (1, ‘name 1′);
insert into test1 (id, name) values (2, ‘name 2′);
--changeset Foo:3 dbms:oracle
create sequence seq_test;
RUNNING LIQUIBASE
Automatically
On Web App
Startup
Continuous
Integration
Job via
Maven Goal
Liquibase
commandline
Liquibase
generated
SQL delta
script
Ideal for paranoid DBAs
 Automatically on web app startup
> Depend on liquibase-core artifact
> Add a servlet listener
 Run from Maven via plugin:
 Run from Liquibase jar
> Download from liquibase.org
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.5.2</version>
</dependency>
ROLLBACK
 Rolling back changes is only possible with Maven or Liquibase commandline
 Provide count of changesets to rollback or a liquibase database tag
 Rolling back and creating a checkpoint
 Rolling back to a previous checkpoint
mvn liquibase:rollback -Dliquibase.rollbackCount=3
mvn liquibase:rollback -Dliquibase.rollbackCount=3
mvn liquibase:tag -Dliquibase.tag=checkpoint
mvn liquibase:rollbackSQL -Dliquibase.rollbackTag=checkpoint

More Related Content

What's hot (19)

PPTX
Database versioning with liquibase
Return on Intelligence
 
PPT
LiquiBase
Mike Willbanks
 
PPT
Liquibase – a time machine for your data
Neev Technologies
 
PPTX
Liquibase case study
Vivek Dhayalan
 
ODP
Handling Database Deployments
Mike Willbanks
 
PPTX
Li liq liqui liquibase
Yoram Michaeli
 
PPTX
Database Change Management as a Service
Andrew Solomon
 
PDF
Liquibase få kontroll på dina databasförändringar
Squeed
 
PPTX
Continuous DB Changes Delivery With Liquibase
Aidas Dragūnas
 
ODP
Liquibase & Flyway @ Baltic DevOps
Andrei Solntsev
 
PPT
Evolutionary Database Design
Andrei Solntsev
 
PDF
Database migration with flyway
Jonathan Holloway
 
PPTX
Ogh Ace Case, Part 1 and 2, Oracle Xml Database, Marco Gralike
Marco Gralike
 
PPTX
Silicon Valley JUG - How to generate customized java 8 code from your database
Speedment, Inc.
 
PDF
Valerii Moisieienko Apache hbase workshop
Аліна Шепшелей
 
PDF
Roman Ugolnikov Migrationа and sourcecontrol for your db
Аліна Шепшелей
 
PPTX
JBoss Data Virtualization (JDV) Sample Physical Deployment Architecture
ejlp12
 
PDF
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
Equnix Business Solutions
 
PPTX
Partially Contained Databases
Microsoft TechNet - Belgium and Luxembourg
 
Database versioning with liquibase
Return on Intelligence
 
LiquiBase
Mike Willbanks
 
Liquibase – a time machine for your data
Neev Technologies
 
Liquibase case study
Vivek Dhayalan
 
Handling Database Deployments
Mike Willbanks
 
Li liq liqui liquibase
Yoram Michaeli
 
Database Change Management as a Service
Andrew Solomon
 
Liquibase få kontroll på dina databasförändringar
Squeed
 
Continuous DB Changes Delivery With Liquibase
Aidas Dragūnas
 
Liquibase & Flyway @ Baltic DevOps
Andrei Solntsev
 
Evolutionary Database Design
Andrei Solntsev
 
Database migration with flyway
Jonathan Holloway
 
Ogh Ace Case, Part 1 and 2, Oracle Xml Database, Marco Gralike
Marco Gralike
 
Silicon Valley JUG - How to generate customized java 8 code from your database
Speedment, Inc.
 
Valerii Moisieienko Apache hbase workshop
Аліна Шепшелей
 
Roman Ugolnikov Migrationа and sourcecontrol for your db
Аліна Шепшелей
 
JBoss Data Virtualization (JDV) Sample Physical Deployment Architecture
ejlp12
 
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
Equnix Business Solutions
 
Partially Contained Databases
Microsoft TechNet - Belgium and Luxembourg
 

Similar to Liquidating database frustrations with liquibase (20)

PPTX
Liquibase Integration with MuleSoft
NeerajKumar1965
 
PPTX
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3
MysoreMuleSoftMeetup
 
PPTX
Schema migration in agile environmnets
Vivek Dhayalan
 
PDF
Leveraging Open Source for Database Development: Database Version Control wit...
All Things Open
 
PDF
Introduction To Liquibase
Knoldus Inc.
 
PPTX
Change Management for Oracle Database with SQLcl
Jeff Smith
 
PDF
Take your database source code and data under control
Marcin Przepiórowski
 
PPTX
Database Migrations with Gradle and Liquibase
Dan Stine
 
KEY
Simple SQL Change Management with Sqitch
David Wheeler
 
KEY
Sane SQL Change Management with Sqitch
David Wheeler
 
KEY
Database Refactoring With Liquibase
IASA
 
PPTX
Evolutionary database design
Salehein Syed
 
PDF
KYSUC - Keep Your Schema Under Control
Coimbra JUG
 
PDF
Gaelyk - Web Apps In Practically No Time
Saltmarch Media
 
PDF
Javaone 2014
Rikard Thulin
 
PDF
Database Schema Evolution
Lars Thorup
 
PDF
Database management-system
kalasalingam
 
PPTX
Revision
David Sherlock
 
PDF
Delivering changes for applications and databases
Eduardo Piairo
 
PPT
Evolutionary db development
Open Party
 
Liquibase Integration with MuleSoft
NeerajKumar1965
 
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3
MysoreMuleSoftMeetup
 
Schema migration in agile environmnets
Vivek Dhayalan
 
Leveraging Open Source for Database Development: Database Version Control wit...
All Things Open
 
Introduction To Liquibase
Knoldus Inc.
 
Change Management for Oracle Database with SQLcl
Jeff Smith
 
Take your database source code and data under control
Marcin Przepiórowski
 
Database Migrations with Gradle and Liquibase
Dan Stine
 
Simple SQL Change Management with Sqitch
David Wheeler
 
Sane SQL Change Management with Sqitch
David Wheeler
 
Database Refactoring With Liquibase
IASA
 
Evolutionary database design
Salehein Syed
 
KYSUC - Keep Your Schema Under Control
Coimbra JUG
 
Gaelyk - Web Apps In Practically No Time
Saltmarch Media
 
Javaone 2014
Rikard Thulin
 
Database Schema Evolution
Lars Thorup
 
Database management-system
kalasalingam
 
Revision
David Sherlock
 
Delivering changes for applications and databases
Eduardo Piairo
 
Evolutionary db development
Open Party
 
Ad

Liquidating database frustrations with liquibase

  • 1. LIQUIDATING DATABASE FRUSTRATIONS WITH LIQUIBASE Paul Churchward, FRM September 23, 2016
  • 2. THE OLD WAY OF MANAGING DATABASE CHANGES
  • 3.  Database schema & reference data changes are applied manually to each environment local > DEV > SIT > PRE-PROD > PROD > DR  SIT, and other production-like environments managed by DBA  Nothing is kept in source control  Highly manual. Highly error prone.
  • 5.  1 script per DB change  Additional scripts for roll-back  Scripts kept in source control  Change existing scripts multiple times until they're right  Scripts are applied manually to each environment  SIT, and other production-like environments managed by DBA  Still very manual. Still very error prone.  Lots and lots of scripts  Must keep track of the order of the scripts!  Must keep track of which scripts to run on which deploys!
  • 7. LIQUIBASE UPDATES THE DB … NOT YOU (MOST OF THE TIME)
  • 8.  Each database schema & reference data change is added to source control > developer choses how to organize them. Examples: One change log file per feature One change log file  Liquibase only executes new changes since last run  Changes can be specified in database agnostic formats (XML, JSON) or SQL  No merge conflicts.  Never modify an existing change, always create a new one.  Automatic rollback without a custom script (unless you want one)  No more manual upgrades
  • 10. A sample JSON changelog file Each DB changes is added to a changeset, and multiple change sets are added to a changelog. Each changeset has an author ID and an ID that is unique to that author within the changelog file This create table change could have been expressed in XML (also DB agnostic) or in plain SQL with metadata in SQL comments A project can support any number of changelog files Always create a new changeset, never alter an existing one (except for stored procedures and then use runOnChange attribute) { "databaseChangeLog": [ { "changeSet": { "id": "1", "author": "Foo", "changes": [ { "createTable": { "tableName": "person", "columns": [ { "column": { "name": "id", "type": "int", "autoIncrement": true, "constraints": { "primaryKey": true, "nullable": false }, } }, { "column": { "name": "firstname", "type": "varchar(50)" } }, { "column": { "name": "lastname", "type": "varchar(50)", "constraints": { "nullable": false } } } …
  • 11. A sample SQL changelog file SQL changesets are DBMS platform dependent unlike XML and JSON formats that are converted into platform dependent SQL Metadata is defined in SQL comments Must provide your own rollback scripts --liquibase formatted sql --changeset Foo:1 create table test1 ( id int primary key, name varchar(255) ); --rollback drop table test1; --changeset Foo:2 insert into test1 (id, name) values (1, ‘name 1′); insert into test1 (id, name) values (2, ‘name 2′); --changeset Foo:3 dbms:oracle create sequence seq_test;
  • 13. Automatically On Web App Startup Continuous Integration Job via Maven Goal Liquibase commandline Liquibase generated SQL delta script Ideal for paranoid DBAs
  • 14.  Automatically on web app startup > Depend on liquibase-core artifact > Add a servlet listener  Run from Maven via plugin:  Run from Liquibase jar > Download from liquibase.org <dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-maven-plugin</artifactId> <version>3.5.2</version> </dependency> <dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> <version>3.5.2</version> </dependency>
  • 16.  Rolling back changes is only possible with Maven or Liquibase commandline  Provide count of changesets to rollback or a liquibase database tag  Rolling back and creating a checkpoint  Rolling back to a previous checkpoint mvn liquibase:rollback -Dliquibase.rollbackCount=3 mvn liquibase:rollback -Dliquibase.rollbackCount=3 mvn liquibase:tag -Dliquibase.tag=checkpoint mvn liquibase:rollbackSQL -Dliquibase.rollbackTag=checkpoint