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:

Driver Information

To use Liquibase and Apache Cassandra, you need to have two jar files – JDBC and the Liquibase Cassandra extension:

  1. 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 named SimbaCassandraJDBC42-x.x.x.zip.
  2. Extract the CassandraJDBCxx.jar file and place it in the liquibase/lib directory.
  3. Go to the liquibase-cassandra repository and download the latest released Liquibase extension .jar file.
  4. Place the liquibase-cassandra-version.jar file in the liquibase/lib install directory.
  5. Open the Liquibase properties file and specify the driver, as follows:
  6. 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:

  1. 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”:
  2. # 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.

  1. Specify the database URL in the Liquibase properties file, as follows:
  2. 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>

  3. Create a text file called changelog (.xml, .sql, .json, or .yaml) in your project directory and add a changeset.

  1. 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.
  2. liquibase --username=test --password=test --changelog-file=<changelog.xml> status
  3. 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.
  4. 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:

Related Links