SlideShare a Scribd company logo
1 of 25
Case Study: Liquibase a
Schema Change Management
/ Migration Tool
Schema Migration
● Management of incremental, reversible changes to any relational database
schema
● Facilitate ways to fix mistakes and adapt to requirement changes
● Can be performed in newer or older versions
● Essential part of Software Evolution in today’s agile environment
Astonishment in Schema Migration
● Corrupt data that was written by old versions of the software and not cleaned
properly
● Implied dependencies in the data which no one knows about anymore
● People directly changing the database without using the designated tools /
scripts
● Bugs in the schema migration system
● Mistakes in assumptions how data should be migrated
Legacy Way (The Hard Way)
● DBA’s generally maintain two sets of scripts
○ Fresh installs
○ Upgrades
● Fresh Installs
○ Single script file will be used to handle single object in database
○ And separate scripts that will default data in master tables
● Upgrades
○ N-1 scripts would be maintained for a schema that has N versions
○ Will also include data migrations scripts for the said version X to Y
Snag In Hard Way
● How sure can we be that everything ran?
● If there’s a problem somewhere in the process, how do we rollback the
changes?
● Maintaining multiple scripts for various environments (Can I run some scripts
only for testing and not in production?)
Schema Change Management (SCM) Tool
● Every creation / change is defined in change log
● Start with create table in change log
● Followed by other DDL operations like adding or dropping column, index or
constraints in the table.
● SCM tools do support DML operations as well and can be part of change log
immediately after the DDL definitions
● SCM tools keeps track of what has or hasn’t been run and implement only the
new changes
● On a brand new DB SCM will run all the changes in change log.
Liquibase Features
● Update database to current version
● Rollback last X changes to database
● Rollback database changes to particular date/time or to a “tag”
● SQL for Database Updates and Rollbacks can be saved for manual review
● "Contexts" for including/excluding change sets to execute
● Database diff report & changelog generation
● Ability to create changelog to generate an existing database
● Database change documentation generation
● DBMS Check, user check, and SQL check preconditions
● Ability to split change log into multiple files for easier management
Features….
● Supports multiple developers
● Supports multiple formats (JSON, XML, YAML & SQL)
● Cluster safe database operations
● Can be run through the build process, embedded within the application or on
demand
● Out of the box support for 10+ DBs and 20+ DBs through the extensions
Appendix
We will be running through the XML format
Change Log File
● Root of all changes are recorded in the
databaseChangeLog file.
● In Liquibase migrator runs, the parser
parses the databaseChangeLog tag.
● databaseChangeLog tag can have the
following sub tags
○ preConditions
○ Property
○ changeSet
○ include
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
</databaseChangeLog>
Precondition
● Controls the execution of an update based
on the state of the database.
● Can be part of changelog (global) or
changeset
● Conditional logics like or, and & not can
also be applied to preconditions.
<databaseChangeLog ………...>
<preConditions> //part of change log
<dbms type="oracle" />
<runningAs username="SYSTEM" />
</preConditions>
<changeSet id="1" author="bob">
<preConditions onFail="WARN"> //part of change set
<sqlCheck expectedResult="0">select count(*) from
oldtable</sqlCheck>
</preConditions>
<dropTable tableName="oldtable"/>
</changeSet>
</databaseChangeLog>
Property
● Liquibase allows dynamic substitution of
parameters in a changelog.
● Parameter values are looked up on the
following order:
○ Passed as a parameter to your Liquibase
runner
○ As a JVM system property
○ In the parameters block (<property> Tag)
of the changelog file.
<property name="clob.type" value="clob" dbms="oracle"/>
<property name="clob.type" value="longtext"
dbms="mysql"/>
<changeSet id="1" author="joe">
<createTable tableName="${table.name}">
<column name="id" type="int"/>
<column name="${column1.name}"
type="${clob.type}"/>
<column name="${column2.name}" type="int"/>
</createTable>
</changeSet>
Include
● Include tag allows us to break up change-
logs into more manageable pieces.
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
<include file="com/example/news/news.changelog.xml"/>
<include file="com/example/directory/directory.changelog.xml"/>
</databaseChangeLog>
ChangeSet
● Tag in which we can group database
changes/refactoring together
● Attributes available for changeSet are
○ Id → ChangeSet unique identifier
○ Author → Creator of the changeSet
○ dbms → the database on which the
specified changeset has to be run
○ runAlways → executes a changeSet every
time even if it has been run before
○ runOnChange → executes on the first time
and every time when there is a change in
changeSet
○ failOnError → specify if the migration has
to be failed on Error
● Available sub tags of changeSet are:
○ Comment → generally used for
descriptions
○ preConditions → Controls the execution of
an update based on the state of the
database.
○ Any Refactoring tags
○ Rollback → SQL statements or refactoring
tags that describe on how rollback needs
to taken place.
CreateTable
<changeSet author="liquibase-docs" id="createTable-example">
<createTable catalogName="cat"
remarks="A String"
schemaName="public"
tableName="person"
tablespace="A String">
<column name="address" type="varchar(255)"/>
</createTable>
</changeSet>
AddColumn
<changeSet author="liquibase-docs" id="addColumn-example">
<addColumn catalogName="cat"
schemaName="public"
tableName="person">
<column name="address" type="varchar(255)"/>
</addColumn>
</changeSet>
AddAutoIncrement
<changeSet author="liquibase-docs" id="addAutoIncrement-example">
<addAutoIncrement catalogName="cat"
columnDataType="int"
columnName="id"
incrementBy="1"
schemaName="public"
startWith="100"
tableName="person"/>
</changeSet>
AddPrimaryKey
<changeSet author="liquibase-docs" id="addPrimaryKey-example">
<addPrimaryKey catalogName="cat"
columnNames="id, name"
constraintName="pk_person"
schemaName="public"
tableName="person"
tablespace="A String"/>
</changeSet>
AddForeignKeyConstraint
<changeSet author="liquibase-docs" id="addForeignKeyConstraint-example">
<addForeignKeyConstraint baseColumnNames="person_id"
baseTableName="address"
constraintName="fk_address_person"
deferrable="true"
initiallyDeferred="true"
onDelete="CASCADE"
onUpdate="RESTRICT"
referencedColumnNames="id"
referencedTableName="person"/>
</changeSet>
CreateIndex
<changeSet author="liquibase-docs" id="createIndex-example">
<createIndex catalogName="cat"
indexName="idx_address"
schemaName="public"
tableName="person"
tablespace="A String"
unique="true">
<column name="address" type="varchar(255)"/>
</createIndex>
</changeSet>
DropTable
<changeSet author="liquibase-docs" id="dropTable-example">
<dropTable cascadeConstraints="true"
catalogName="cat"
schemaName="public"
tableName="person"/>
</changeSet>
DropNotNullConstraint
<changeSet author="liquibase-docs" id="dropNotNullConstraint-example">
<dropNotNullConstraint catalogName="cat"
columnDataType="int"
columnName="id"
schemaName="public"
tableName="person"/>
</changeSet>
RenameColumn
<changeSet author="liquibase-docs" id="renameColumn-example">
<renameColumn catalogName="cat"
columnDataType="int"
newColumnName="id"
oldColumnName="uuid"
remarks="A String"
schemaName="public"
tableName="person"/>
</changeSet>
Insert
<changeSet author="demo" id="1527738217035-2">
<insert tableName="Table-1">
<column name="column-1" value="Closed"/>
<column name="column-2" value="y"/>
<column name="column-3" value="100"/>
<column name="column-4" type="nclob" valueClobFile="path/to/file.extension"/>
</insert>
</changeSet>
LoadData
<changeSet author="liquibase-docs" id="loadData-example">
<loadData catalogName="cat"
encoding="UTF-8"
file="com/example/users.csv"
quotchar="A String"
schemaName="public"
separator="A String"
tableName="person">
<column name="address" type="varchar(255)"/>
</loadData>
</changeSet>

More Related Content

What's hot

What's hot (20)

Database change management with Liquibase
Database change management with LiquibaseDatabase change management with Liquibase
Database change management with Liquibase
 
Successful DB migrations with Liquibase
 Successful DB migrations with Liquibase Successful DB migrations with Liquibase
Successful DB migrations with Liquibase
 
Liquibase for java developers
Liquibase for java developersLiquibase for java developers
Liquibase for java developers
 
Deep Dive into Azure Data Factory v2
Deep Dive into Azure Data Factory v2Deep Dive into Azure Data Factory v2
Deep Dive into Azure Data Factory v2
 
PostgreSQL for Oracle Developers and DBA's
PostgreSQL for Oracle Developers and DBA'sPostgreSQL for Oracle Developers and DBA's
PostgreSQL for Oracle Developers and DBA's
 
Hive Does ACID
Hive Does ACIDHive Does ACID
Hive Does ACID
 
MySQL InnoDB Cluster and NDB Cluster
MySQL InnoDB Cluster and NDB ClusterMySQL InnoDB Cluster and NDB Cluster
MySQL InnoDB Cluster and NDB Cluster
 
All of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperAll of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL Developer
 
MySQL Database Architectures - 2020-10
MySQL Database Architectures -  2020-10MySQL Database Architectures -  2020-10
MySQL Database Architectures - 2020-10
 
[2018] MySQL 이중화 진화기
[2018] MySQL 이중화 진화기[2018] MySQL 이중화 진화기
[2018] MySQL 이중화 진화기
 
MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTUREMS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
 
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
 
From my sql to postgresql using kafka+debezium
From my sql to postgresql using kafka+debeziumFrom my sql to postgresql using kafka+debezium
From my sql to postgresql using kafka+debezium
 
Databricks Delta Lake and Its Benefits
Databricks Delta Lake and Its BenefitsDatabricks Delta Lake and Its Benefits
Databricks Delta Lake and Its Benefits
 
Migrating Oracle database to PostgreSQL
Migrating Oracle database to PostgreSQLMigrating Oracle database to PostgreSQL
Migrating Oracle database to PostgreSQL
 
Best practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability TutorialBest practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability Tutorial
 
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best PracticesMySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
 
CDC patterns in Apache Kafka®
CDC patterns in Apache Kafka®CDC patterns in Apache Kafka®
CDC patterns in Apache Kafka®
 
MySQL Scalability and Reliability for Replicated Environment
MySQL Scalability and Reliability for Replicated EnvironmentMySQL Scalability and Reliability for Replicated Environment
MySQL Scalability and Reliability for Replicated Environment
 
Databus: LinkedIn's Change Data Capture Pipeline SOCC 2012
Databus: LinkedIn's Change Data Capture Pipeline SOCC 2012Databus: LinkedIn's Change Data Capture Pipeline SOCC 2012
Databus: LinkedIn's Change Data Capture Pipeline SOCC 2012
 

Similar to Liquibase case study

Oracle 12 c new-features
Oracle 12 c new-featuresOracle 12 c new-features
Oracle 12 c new-features
Navneet Upneja
 

Similar to Liquibase case study (20)

Schema migration in agile environmnets
Schema migration in agile environmnetsSchema migration in agile environmnets
Schema migration in agile environmnets
 
Liquibase få kontroll på dina databasförändringar
Liquibase   få kontroll på dina databasförändringarLiquibase   få kontroll på dina databasförändringar
Liquibase få kontroll på dina databasförändringar
 
Liquibase Integration with MuleSoft
Liquibase Integration with MuleSoftLiquibase Integration with MuleSoft
Liquibase Integration with MuleSoft
 
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3
MuleSoft integration with Liquibase | Mysore MuleSoft Meetup #3
 
Evolutionary database design
Evolutionary database designEvolutionary database design
Evolutionary database design
 
Liquibase – a time machine for your data
Liquibase – a time machine for your dataLiquibase – a time machine for your data
Liquibase – a time machine for your data
 
Ms sql server
Ms sql serverMs sql server
Ms sql server
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
KoprowskiT_Session2_SDNEvent_SourceControlForDBAKoprowskiT_Session2_SDNEvent_SourceControlForDBA
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
 
MOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical ExamplesMOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical Examples
 
MOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your DataMOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your Data
 
Rails DB migrations
Rails DB migrationsRails DB migrations
Rails DB migrations
 
Modern ETL Pipelines with Change Data Capture
Modern ETL Pipelines with Change Data CaptureModern ETL Pipelines with Change Data Capture
Modern ETL Pipelines with Change Data Capture
 
Database Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDatabase Migrations with Gradle and Liquibase
Database Migrations with Gradle and Liquibase
 
Remote DBA Experts 11g Features
Remote DBA Experts 11g FeaturesRemote DBA Experts 11g Features
Remote DBA Experts 11g Features
 
Tauhid: SQL Server Database Change Automation
Tauhid: SQL Server Database Change AutomationTauhid: SQL Server Database Change Automation
Tauhid: SQL Server Database Change Automation
 
Delivering changes for applications and databases
Delivering changes for applications and databasesDelivering changes for applications and databases
Delivering changes for applications and databases
 
Oracle to PostgreSQL migration
Oracle to PostgreSQL migrationOracle to PostgreSQL migration
Oracle to PostgreSQL migration
 
Rails DB migrate SAFE.pdf
Rails DB migrate SAFE.pdfRails DB migrate SAFE.pdf
Rails DB migrate SAFE.pdf
 
Oracle 12 c new-features
Oracle 12 c new-featuresOracle 12 c new-features
Oracle 12 c new-features
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Liquibase case study

  • 1. Case Study: Liquibase a Schema Change Management / Migration Tool
  • 2. Schema Migration ● Management of incremental, reversible changes to any relational database schema ● Facilitate ways to fix mistakes and adapt to requirement changes ● Can be performed in newer or older versions ● Essential part of Software Evolution in today’s agile environment
  • 3. Astonishment in Schema Migration ● Corrupt data that was written by old versions of the software and not cleaned properly ● Implied dependencies in the data which no one knows about anymore ● People directly changing the database without using the designated tools / scripts ● Bugs in the schema migration system ● Mistakes in assumptions how data should be migrated
  • 4. Legacy Way (The Hard Way) ● DBA’s generally maintain two sets of scripts ○ Fresh installs ○ Upgrades ● Fresh Installs ○ Single script file will be used to handle single object in database ○ And separate scripts that will default data in master tables ● Upgrades ○ N-1 scripts would be maintained for a schema that has N versions ○ Will also include data migrations scripts for the said version X to Y
  • 5. Snag In Hard Way ● How sure can we be that everything ran? ● If there’s a problem somewhere in the process, how do we rollback the changes? ● Maintaining multiple scripts for various environments (Can I run some scripts only for testing and not in production?)
  • 6. Schema Change Management (SCM) Tool ● Every creation / change is defined in change log ● Start with create table in change log ● Followed by other DDL operations like adding or dropping column, index or constraints in the table. ● SCM tools do support DML operations as well and can be part of change log immediately after the DDL definitions ● SCM tools keeps track of what has or hasn’t been run and implement only the new changes ● On a brand new DB SCM will run all the changes in change log.
  • 7. Liquibase Features ● Update database to current version ● Rollback last X changes to database ● Rollback database changes to particular date/time or to a “tag” ● SQL for Database Updates and Rollbacks can be saved for manual review ● "Contexts" for including/excluding change sets to execute ● Database diff report & changelog generation ● Ability to create changelog to generate an existing database ● Database change documentation generation ● DBMS Check, user check, and SQL check preconditions ● Ability to split change log into multiple files for easier management
  • 8. Features…. ● Supports multiple developers ● Supports multiple formats (JSON, XML, YAML & SQL) ● Cluster safe database operations ● Can be run through the build process, embedded within the application or on demand ● Out of the box support for 10+ DBs and 20+ DBs through the extensions
  • 9. Appendix We will be running through the XML format
  • 10. Change Log File ● Root of all changes are recorded in the databaseChangeLog file. ● In Liquibase migrator runs, the parser parses the databaseChangeLog tag. ● databaseChangeLog tag can have the following sub tags ○ preConditions ○ Property ○ changeSet ○ include <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> </databaseChangeLog>
  • 11. Precondition ● Controls the execution of an update based on the state of the database. ● Can be part of changelog (global) or changeset ● Conditional logics like or, and & not can also be applied to preconditions. <databaseChangeLog ………...> <preConditions> //part of change log <dbms type="oracle" /> <runningAs username="SYSTEM" /> </preConditions> <changeSet id="1" author="bob"> <preConditions onFail="WARN"> //part of change set <sqlCheck expectedResult="0">select count(*) from oldtable</sqlCheck> </preConditions> <dropTable tableName="oldtable"/> </changeSet> </databaseChangeLog>
  • 12. Property ● Liquibase allows dynamic substitution of parameters in a changelog. ● Parameter values are looked up on the following order: ○ Passed as a parameter to your Liquibase runner ○ As a JVM system property ○ In the parameters block (<property> Tag) of the changelog file. <property name="clob.type" value="clob" dbms="oracle"/> <property name="clob.type" value="longtext" dbms="mysql"/> <changeSet id="1" author="joe"> <createTable tableName="${table.name}"> <column name="id" type="int"/> <column name="${column1.name}" type="${clob.type}"/> <column name="${column2.name}" type="int"/> </createTable> </changeSet>
  • 13. Include ● Include tag allows us to break up change- logs into more manageable pieces. <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"> <include file="com/example/news/news.changelog.xml"/> <include file="com/example/directory/directory.changelog.xml"/> </databaseChangeLog>
  • 14. ChangeSet ● Tag in which we can group database changes/refactoring together ● Attributes available for changeSet are ○ Id → ChangeSet unique identifier ○ Author → Creator of the changeSet ○ dbms → the database on which the specified changeset has to be run ○ runAlways → executes a changeSet every time even if it has been run before ○ runOnChange → executes on the first time and every time when there is a change in changeSet ○ failOnError → specify if the migration has to be failed on Error ● Available sub tags of changeSet are: ○ Comment → generally used for descriptions ○ preConditions → Controls the execution of an update based on the state of the database. ○ Any Refactoring tags ○ Rollback → SQL statements or refactoring tags that describe on how rollback needs to taken place.
  • 15. CreateTable <changeSet author="liquibase-docs" id="createTable-example"> <createTable catalogName="cat" remarks="A String" schemaName="public" tableName="person" tablespace="A String"> <column name="address" type="varchar(255)"/> </createTable> </changeSet>
  • 16. AddColumn <changeSet author="liquibase-docs" id="addColumn-example"> <addColumn catalogName="cat" schemaName="public" tableName="person"> <column name="address" type="varchar(255)"/> </addColumn> </changeSet>
  • 17. AddAutoIncrement <changeSet author="liquibase-docs" id="addAutoIncrement-example"> <addAutoIncrement catalogName="cat" columnDataType="int" columnName="id" incrementBy="1" schemaName="public" startWith="100" tableName="person"/> </changeSet>
  • 18. AddPrimaryKey <changeSet author="liquibase-docs" id="addPrimaryKey-example"> <addPrimaryKey catalogName="cat" columnNames="id, name" constraintName="pk_person" schemaName="public" tableName="person" tablespace="A String"/> </changeSet>
  • 19. AddForeignKeyConstraint <changeSet author="liquibase-docs" id="addForeignKeyConstraint-example"> <addForeignKeyConstraint baseColumnNames="person_id" baseTableName="address" constraintName="fk_address_person" deferrable="true" initiallyDeferred="true" onDelete="CASCADE" onUpdate="RESTRICT" referencedColumnNames="id" referencedTableName="person"/> </changeSet>
  • 20. CreateIndex <changeSet author="liquibase-docs" id="createIndex-example"> <createIndex catalogName="cat" indexName="idx_address" schemaName="public" tableName="person" tablespace="A String" unique="true"> <column name="address" type="varchar(255)"/> </createIndex> </changeSet>
  • 21. DropTable <changeSet author="liquibase-docs" id="dropTable-example"> <dropTable cascadeConstraints="true" catalogName="cat" schemaName="public" tableName="person"/> </changeSet>
  • 22. DropNotNullConstraint <changeSet author="liquibase-docs" id="dropNotNullConstraint-example"> <dropNotNullConstraint catalogName="cat" columnDataType="int" columnName="id" schemaName="public" tableName="person"/> </changeSet>
  • 23. RenameColumn <changeSet author="liquibase-docs" id="renameColumn-example"> <renameColumn catalogName="cat" columnDataType="int" newColumnName="id" oldColumnName="uuid" remarks="A String" schemaName="public" tableName="person"/> </changeSet>
  • 24. Insert <changeSet author="demo" id="1527738217035-2"> <insert tableName="Table-1"> <column name="column-1" value="Closed"/> <column name="column-2" value="y"/> <column name="column-3" value="100"/> <column name="column-4" type="nclob" valueClobFile="path/to/file.extension"/> </insert> </changeSet>
  • 25. LoadData <changeSet author="liquibase-docs" id="loadData-example"> <loadData catalogName="cat" encoding="UTF-8" file="com/example/users.csv" quotchar="A String" schemaName="public" separator="A String" tableName="person"> <column name="address" type="varchar(255)"/> </loadData> </changeSet>