Skip to content

Latest commit

 

History

History
175 lines (171 loc) · 7.84 KB

README.md

File metadata and controls

175 lines (171 loc) · 7.84 KB

Liquibase-and-Cassandra

In this repository, we will discuss how to connect Liquibase with Apache Cassandra and DataStax Astra.

We recommend first trying out the method with Gitpod and DataStax Astra as with this method you will not have to do any manual local installations and you can get a free managed Cassandra instance in the cloud. Hit the button below to get started!

Open in Gitpod

We will also cover how to use Liquibase locally with local Cassandra and Astra.

Additional Resources can be found at the end of the repo!

Gitpod and DataStax Astra

Gitpod Setup

  1. Open this repo in Gitpod
  2. Run the following commands to make a liquibase directory, download liquibase into it, and add liquibase to PATH
mkdir liquibase
curl -L -s https://github.com/liquibase/liquibase/releases/download/v4.2.2/liquibase-4.2.2.tar.gz | tar xvz -C /workspace/example-cassandra-liquibase/liquibase
export PATH=$PATH:/workspace/example-cassandra-liquibase/liquibase
  1. Run the following commands to change the Gitpod's Java version to 1.8. You may run into timeout errors using the latest Java version, so we will set it to 1.8, which was indicated by the Liquibase team. When prompted to set the installed java version as default, select YES.
sdk install java 8.0.275.open-adpt
  1. Confirm Java version is now 1.8
java -version
  1. Download prerequisite JARs to talk to Cassandra and store them in /liquibase/lib
wget -P /workspace/example-cassandra-liquibase/liquibase/lib https://github.com/liquibase/liquibase-cassandra/releases/download/liquibase-cassandra-4.2.2/liquibase-cassandra-4.2.2.jar
wget https://downloads.datastax.com/jdbc/cql/2.0.4.1004/SimbaCassandraJDBC42-2.0.4.1004.zip && unzip SimbaCassandraJDBC42-2.0.4.1004.zip -d /workspace/example-cassandra-liquibase/liquibase/lib && rm SimbaCassandraJDBC42-2.0.4.1004.zip

Using Liquibase with Astra on Gitpod

  1. Rename astra.liquibase.properties to liquibase.properties
mv astra.liquibase.properties liquibase.properties
  1. Download Secure Connect Bundle from DataStax Astra for your database and drag-and-drop it into the root level of the workspace
  2. Unzip a copy of the downloaded Secure Connect Bundle and open the config.json file in a code editor.
  3. Update host, keyspace and port with the values from your config.json file. Replace UID and PWD with the databases username and password that you set. Also update the database name for SecureConnectionBundlePath=secure-connect-<your-database>.zip to match the zip file you drag-and-dropped into Gitpod
vim liquibase.properties
  1. Run liquibase status to confirm that unadded changesets are being seen
liquibase status
  1. Run liquibase update to run changeset
liquibase update
  1. Open DataStax Astra Studio to confirm that there are 3 new tables
  • leaves_by_tag
  • databasechangelog
  • databasechangeloglock
  1. Change liquibase.properties file to now use dbchangelog.xml
vim liquibase.properties
  1. Run liquibase status again to confirm that there are now 2 new changesets that have not been run
liquibase status
  1. Run liquibase update to introduce the new changesets
liquibase update
  1. With Astra Studio, confirm there are now 3 records in the databasechangelog table and there is now a tags table
  2. Run a rollback to revert a migration using the tag we introduced in changeset 2
liquibase rollback version_1.0.1
  1. With Astra studio, confirm rollback occured by seeing that the tags table is now gone and the dbchangelog table has been updated.

Local Liquibase with Apache Cassadndra and DataStax Astra

Local setup

  1. Download Liquabase with the installer for your machine or use the tar.gz and then add liquibase to PATH
  2. Download the prerequisite JARs and place them into the path/to/liquibase/lib directory
  1. If you run into timeout errors, update your Java version to 1.8 from the version that it is currently on

Using Liquibase with Apahche Cassandra Locally

  1. Rename astra.liquibase.properties to liquibase.properties
mv cassandra.liquibase.properties liquibase.properties
  1. Update the keyspace placeholder value with your specific keyspace
vim liquibase.properties
  1. Run liquibase status to confirm that unadded changesets are being seen
liquibase status
  1. Run liquibase update to run changeset
liquibase update
  1. Open CQLSH to to confirm that there are 3 new tables
  • leaves_by_tag
  • databasechangelog
  • databasechangeloglock
  1. Change liquibase.properties file to now use dbchangelog.xml
vim liquibase.properties
  1. Run liquibase status again to confirm that there are now 2 new changesets that have not been run
liquibase status
  1. Run liquibase update to introduce the new changesets
liquibase update
  1. Using CQLSH, confirm there are now 3 records in the databasechangelog table and there is now a tags table
  2. Run a rollback to revert a migration using the tag we introduced in changeset 2
liquibase rollback version_1.0.1
  1. Confirm with CQLSH that the rollback occured by seeing that the tags table is now gone and the dbchangelog table has been updated.

Using Liquibase with Astra Locally

  1. Rename astra.liquibase.properties to liquibase.properties
mv astra.liquibase.properties liquibase.properties
  1. Download Secure Connect Bundle from DataStax Astra for your database and drag-and-drop it into the root level of the directory
  2. Unzip a copy of the downloaded Secure Connect Bundle and open the config.json file in a code editor.
  3. Update host, keyspace and port with the values from your config.json file. Replace UID and PWD with the databases username and password that you set. Also update the database name for SecureConnectionBundlePath=secure-connect-<your-database>.zip to match the zip file you drag-and-dropped into Gitpod
vim liquibase.properties
  1. Run liquibase status to confirm that unadded changesets are being seen
liquibase status
  1. Run liquibase update to run changeset
liquibase update
  1. Open DataStax Astra Studio to confirm that there are 3 new tables
  • leaves_by_tag
  • databasechangelog
  • databasechangeloglock
  1. Change liquibase.properties file to now use dbchangelog.xml
vim liquibase.properties
  1. Run liquibase status again to confirm that there are now 2 new changesets that have not been run
liquibase status
  1. Run liquibase update to introduce the new changesets
liquibase update
  1. With Astra Studio, confirm there are now 3 records in the databasechangelog table and there is now a tags table
  2. Run a rollback to revert a migration using the tag we introduced in changeset 2
liquibase rollback version_1.0.1
  1. With Astra studio, confirm rollback occured by seeing that the tags table is now gone and the dbchangelog table has been updated.

Additional Resources: