Get Started with Liquibase
Let’s start with a quick tutorial that gets you up and running in minutes.
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
Download and extract Liquibase
Run the installer or 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 classpath, URL, and user authentication information for the database you want to capture.
You’ll also put your Liquibase Pro license key in this file.
Here’s 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
Configure Liquibase
Capture the current state of your database by creating a deployable Liquibase changelog.
liquibase --changeLogFile=mydatabase_changelog.xml generateChangeLog
Capture the current state of your database by creating a deployable Liquibase changelog.
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/
dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd
http://www.liquibase.org/xml/ns/pro http://
www.liquibase.org/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>