Covered in this quickstart:

  • Installing Liquibase and using it on the command line
  • Configuring Liquibase so it can talk to your database
  • Capturing your existing database schema
  • Creating your first database change
  • Executing your database change
  • Rolling back a change
  • Viewing your changes on your dashboard in Liquibase Hub

Before you begin

If you haven’t already, create your Liquibase Hub account.

Download and extract Liquibase

Download Liquibase. On the download page, check the “Send me a trial license key for Liquibase Pro” box to get a license key for advanced features and support. You’ll receive an email with a license key.

Extract the Liquibase files you downloaded.

Open a command prompt to view your new directory:

$ cd liquibase-4.5.0

Configure Liquibase

Create a liquibase.properties text file to specify your driver class path, URL, and user authentication information for the database you want to capture.

You’ll also put your Liquibase Pro license key and your Liquibase Hub API key in this file.

Here’s an example an example of a properties file for a PostgreSQL database:

changeLogFile:dbchangelog.xml  
url:  jdbc:postgresql://localhost:5432/mydatabase
username:  postgres  
password:  password 
classpath:  postgresql-42.2.8.jar
liquibaseProLicenseKey:  licensekey
liquibase.hub.ApiKey:  APIkey

Take a snapshot of your existing database

Capture the current state of your database by creating a deployable Liquibase changelog.

liquibase --changeLogFile=mydatabase_changelog.xml generateChangeLog

You’ll get a changelog for your database that looks something like this:

<?xml version="1.0" encoding="UTF-8"?>  
<databaseChangeLog  
  xmlns="http://dtorg.liquibase.com/xml/ns/dbchangelog"  
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  xmlns:pro="http://dtorg.liquibase.com/xml/ns/pro"  
  xsi:schemaLocation="http://dtorg.liquibase.com/xml/ns/dbchangelog http://dtorg.liquibase.com/xml/ns/dbchangelog/dbchangelog-4.4.xsd
      http://dtorg.liquibase.com/xml/ns/pro http://dtorg.liquibase.com/xml/ns/pro/liquibase-pro-4.5.xsd">  
    <changeSet  author="lb-generated"  id="1185214997195-1">  
        <createTable  name="BONUS">  
            <column  name="NAME"  type="VARCHAR2(15)"/>  
            <column  name="JOB"  type="VARCHAR2(255)"/>  
            <column  name="SAL"  type="NUMBER(255)"/>
        </createTable>  
    </changeSet>
    <changeSet  author="lb-generated"  id="1185214997195-2">  
        <createTable  name="DEPT">  
            <column  name="DEPTNO"  type="INTEGER"/>  
            <column  name="DNAME"  type="VARCHAR2(15)"/>  
            <column  name="LOC"  type="VARCHAR2(255)"/>  
        </createTable>  
    </changeSet>
    <changeSet  author="lb-generated"  id="1185214997195-3">
    	   <createView fullDefinition="false" viewName="myView2">SELECT "DEPT".DEPTNO,
    "DEPT".DNAME
   FROM "DEPT";</createView>
    </changeSet>
    <changeSet  author="lb-generated"  id="1185214997195-4">  
        <pro:createFunction functionName="myFunction" path="objects/function/myFunction.sql" relativeToChangelogFile="true"/>  
    </changeSet>
</databaseChangeLog>

Create your first database schema change

Now you can start to make database changes by creating your first changeset in your dbchangelog.xml changelog like this:

<?xml version="1.0" encoding="UTF-8"?>  
<databaseChangeLog  
  xmlns="http://dtorg.liquibase.com/xml/ns/dbchangelog"  
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  xmlns:pro="http://dtorg.liquibase.com/xml/ns/pro"  
  xsi:schemaLocation="http://dtorg.liquibase.com/xml/ns/dbchangelog http://dtorg.liquibase.com/xml/ns/dbchangelog/dbchangelog-4.4.xsd
      http://dtorg.liquibase.com/xml/ns/pro http://dtorg.liquibase.com/xml/ns/pro/liquibase-pro-4.5.xsd">

    <changeSet author="BobR" id="myIDNumber123">
        <createTable tableName="actor">
            <column autoIncrement="true" name="id" type="INTEGER">
                <constraints nullable="false" primaryKey="true" primaryKeyName="actor_pkey"/>
            </column>
            <column name="firstname" type="VARCHAR(255)"/>
            <column name="lastname" type="VARCHAR(255)"/>
            <column name="twitter" type="VARCHAR(15)"/>
        </createTable>
    </changeSet>

</databaseChangeLog>

Register your changelog

Register your changelog with the following command so you can view details in Liquibase Hub.

liquibase-4.5.0$ liquibase registerChangeLog

Deploy your database change

Now you can deploy your database change by running the update command like this:

liquibase-4.5.0$ liquibase update

If all went well, you’ll see the following output:

Liquibase: Update has been successful.

Now you can automatically roll back your database last change by running the Liquibase rollback command like this:

liquibase-4.5.0$ liquibase rollbackCount 1

If all went well, you’ll see the following output:

Rolling Back Changeset:dbchangelog.xml::myIDNumber123::BobR
Liquibase: Rollback has been successful.

View your project

Register your changelog with the following command so you can view details in Liquibase Hub.

liquibase-4.5.0$ liquibase registerChangeLog

View your project in Liquibase Hub.

Liquibase Hub Operations Report

There’s a lot more Liquibase can do!

For starters, you can create database changes with Liquibase using plain SQL, XML, JSON, or YAML. You can also embed Liquibase in your application or in automation. 

View our documentation or follow our specific database tutorials for more in-depth information on using Liquibase with your stack.