Using Liquibase with Cassandra
Apache Cassandra is an open source, distributed, NoSQL database. It presents a partitioned wide column storage model with consistent semantics.
Note: For more information, see the Apache Cassandra page.
Supported Versions
- 3.11
Prerequisites
Before using Liquibase with your database, ensure you have:
- Installed Liquibase.
- Created a Liquibase project folder to store all Liquibase files.
- Created a new Liquibase properties file or are using the existing
liquibase.properties
file included in the installation package. For more information, see Specifying Properties in a Connection Profile.
Driver Information
To use Liquibase and Apache Cassandra, you need to have two jar files – JDBC and the Liquibase Cassandra extension:
- Ensure you have downloaded the Simba JDBC jar driver file. To download it, go to the DataStax ODBC/JDBC Drivers page and select Simba JDBC Driver for Apache Cassandra from the dropdown menu. Also, select the default package option unless you need a specific package. The driver downloads as a
.zip
file namedSimbaCassandraJDBC42-x.x.x.zip
. - Extract the
CassandraJDBCxx.jar
file and place it in theliquibase/lib
directory. - Go to the liquibase-cassandra repository and download the latest released Liquibase extension
.jar
file. - Place the
liquibase-cassandra-version.jar
file in theliquibase/lib
install directory. - Open the Liquibase properties file and specify the driver, as follows:
driver: com.simba.cassandra.jdbc42.Driver
Note: If you put the CassandraJDBCxx.jar
and liquibase-cassandra-version.jar
files in a different directory, specify the path in the Liquibase properties file, as follows: classpath:../path_to_drivers/CassandraJDBCxx.jar; liquibase-cassandra-version.jar
.
If you use Maven, you also need to download the Simba JDBC driver for Cassandra and put the driver in a location that your Maven build can access. Configure the Maven pom.xml
file to use the local copy of the driver jar file. For example:
<dependency>
<groupId>com.datastax.jdbc</groupId>
<artifactId>CassandraJDBC42</artifactId>
<version>4.2</version>
<scope>system</scope>
<systemPath>${basedir}/lib/CassandraJDBC42.jar</systemPath>
</dependency>
You need to specify that the scope is system
and provide the systemPath
in pom.xml
. In the example, the ${basedir}/lib
is the location of the driver jar file.
Testing Your Connection
For Liquibase and Apache Cassandra to work, you need to:
- Ensure your Cassandra database is configured. If you have Cassandra tools locally and want to check the status of Cassandra, run
$ bin/nodetool
status. The status column in the output should report UN which stands for “Up/Normal”:
# nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load | Tokens | Owns (effective) | Host ID | Rack |
---|---|---|---|---|
UN 172.18.0.6 198.61 KiB | 276 | 100.0% | 5rtc74d1-237f-87c0-88eb-72643bd0a8t7 | rack1 |
Note: For more information, see the Installing Cassandra documentation.
- Specify the database URL in the Liquibase properties file, as follows:
-
Create a text file called changelog (
.xml
,.sql
,.json
, or.yaml
) in your project directory and add a changeset.
url: jdbc:cassandra://localhost:9042/myKeyspace;DefaultKeyspace=myKeyspace
Tip: To apply a Liquibase Pro key to your project, add the following property to the Liquibase properties file: liquibaseProLicenseKey: <paste code here>

<?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:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
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.9.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.9.xsd">
<changeSet id="1" author="Liquibase">
<createTable tableName="test_table">
<column name="test_id" type="int">
<constraints primaryKey="true"/>
</column>
<column name="test_column" type="varchar"/>
</createTable>
</changeSet>
</databaseChangeLog>

-- liquibase formatted sql
-- changeset liquibase:1
CREATE TABLE test_table (test_id INT, test_column VARCHAR, PRIMARY KEY (test_id))
Note: Formatted SQL changelogs generated by using Liquibase versions previous to 4.2 might cause issues because of the lack of space after a double dash ( -- ).
Tip: To fix those issues, add a space after the double dash. For example: -- liquibase formatted sql
instead of --liquibase formatted sql
and -- changeset myname:create-table
instead of --changeset myname:create-table

databaseChangeLog:
- changeSet:
id: 1
author: Liquibase
changes:
- createTable:
columns:
- column:
name: test_column
type: INT
constraints:
primaryKey: true
nullable: false
tableName: test_table

{
"databaseChangeLog": [
{
"changeSet": {
"id": "1",
"author": "Liquibase",
"changes": [
{
"createTable": {
"columns": [
{
"column":
{
"name": "test_column",
"type": "INT",
"constraints":
{
"primaryKey": true,
"nullable": false
}
}
}]
,
"tableName": "test_table"
}
}]
}
}]
}
- Navigate to your project folder in the CLI and run the Liquibase status command to see whether the connection is successful. You can pass arguments in the CLI or keep them in the Liquibase properties file.
- Run your first update with the update command, which makes changes to your database. You can also run the update-sql command to inspect the SQL before running the
update
command.
liquibase --username=test --password=test --changelog-file=<changelog.xml> status
liquibase --changelog-file=<changelog.xml> update-sql
liquibase --changelog-file=<changelog.xml> update
From a database UI tool, ensure that your database contains the table you added along with the DATABASECHANGELOG table and DATABASECHANGELOGLOCK table.
Supported Commands and Change Types
The supported Change Types for Cassandra are:
You can use all the commands with Liquibase and Cassandra, except for: