Shay Shmeltzer's Oracle Development Tools Tips

Introduction to Liquibase and Managing Your Database Source Code

Shay Shmeltzer
Director of Product Management - Oracle

In previous posts I showed how you can manage SQL scripts lifecycle with the help of Oracle Developer Cloud Service (DevCS) as part of an overall Oracle DB DevOps solution. I wanted to add one more utility that might act as an alternative or addition to the SQL script managing - Liquibase.

Liquibase logo

Liquibase is an open source solution for managing revisions of your databse schema scripts. It works across various types of databases, and supports various file formats for defining the DB structure. The feature that is probably most attractive in Liquibase is its ability to roll changes back and forward from a specific point - saving you from the need to know what was the last change/script you ran on a specific DB instance.

Liquibase uses scripts - referred to as "changesets" - to manage the changes you do to your DB. The changesets files can be in various formats including XML, JSON, YAML, and SQL. In the examples below I'm using the XML format.

As you continue to change an enhance your DB structure through the development lifecycle you'll add more changesets. A master file lists all the changeset files (or the directories where they are). In parallel Liquibase tracks in your database which changesets have already run. 

When you issue a liquibase update command, liquibase looks at the current state of your DB, and identifies which changes have already happened. Then it run the rest of the changes - getting you to the latest revision of the structure you are defining.

By integrating Liquibase into your overall code version management system and continuous integration platform you can synch up your database versions with your app version. In my case this would of course mean integration with Oracle Developer Cloud Service (DevCS) - which you get for free with the Oracle Database Cloud Service. In the video below I show a flow that covers:

  • Tracking my DBA tasks in the issue system
  • Modifying a local MySQL DB with Liquibase (doing forward and backward rolls)
  • Adding a change set defining a new table
  • Committing to Git
  • Automatic build implementing the changes in Oracle Database Cloud Service
  • Automatic testing with UT/PLSQL

Here is a quick 10 minute demo:

[Update June 2020 - See this new blog entry that shows new features that simplify Liquibase interaction in the Oracle Cloud]

For those who want to try and replicate this, here are some resources:

A changeset that creates a "department" table with three columns:


A changeset that creates PL/SQL function, package and procedure. Note that in line 3 the dbms="oracle" means this script will only run when we are connected to an Oracle DB:

create or replace function betwnstr( a_string varchar2, a_start_pos integer, a_end_pos integer ) return varchar2
  return substr( a_string, a_start_pos, a_end_pos - a_start_pos+1 );

create or replace package test_betwnstr as
  -- %suite(Between string function)
  -- %test(Returns substring from start position to end position)
  procedure basic_usage;

create or replace package body test_betwnstr as
  procedure basic_usage is
    ut.expect( betwnstr( '1234567', 2, 5 ) ).to_equal('2345');

A changeset that adds a record to a table. Line 8 has the rollback tag that defines how to do a rollback for this insert:

    delete from department where id=20


A few tips about my DevCS project and build setup.

1. For the sake of simplicity, I loaded the liquibase and JDBC jar files into my git repository - this makes it easy for my build steps to find the files and execute them. I'm guessing you could also use Maven to host those.

2. I use a password parameter for my build so I don't need to hardcode the password adding a bit of security to my build. Reference teh parameter in your build with a $ sign - $password

3. Want to learn more about test automation with ut/PLSQL - check out this blog entry.



Join the discussion

Comments ( 5 )
  • Bui Chi Tai Thursday, May 10, 2018
    Thank you for your topic. But when I try to use changeSet with element "createprocedure" I got the below error. Please help me

    [ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.2:update
    (default-cli) on project liquibase-demo: Error setting up or running Liquibase:
    liquibase.exception.SetupException: Error parsing line 9 column 19 of liquibase
    /db-changelog-3.2.xml: cvc-complex-type.2.4.a: Invalid content was found startin
    g with element 'createprocedure'. One of '{"http://www.liquibase.org/xml/ns/dbch
    angelog":validCheckSum, "http://www.liquibase.org/xml/ns/dbchangelog":preConditi
  • Renat Shakerov Tuesday, August 14, 2018
    liquibase tag names should be written in camel case, e.g. databaseChangeLog
  • Srilakshmi Friday, May 24, 2019
    Good article. We are looking for options to automate the deployment and testing of new oracle DB upgrades/patches released by Oracle in the same lines as DB structure changes executed by the project team. Is this possible?
  • Shay Friday, May 24, 2019
    Srilakshmi, DevCS can also invoke shell scripts, OCI command lines and PSM command lines - so those can be used to automate the patching of your DB as part of the CI/CD flow.
  • michelle Wednesday, October 16, 2019
    I am trying to use liquibase with ATP db. I got this error. Any suggestions? Thanks.

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.LockException: liquibase.exception.DatabaseException: ORA-12838: cannot read/modify an object after modifying it in parallel
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.