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!
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!
- Open this repo in Gitpod
- 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
- 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
- Confirm Java version is now 1.8
java -version
- 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
- Rename astra.liquibase.properties to liquibase.properties
mv astra.liquibase.properties liquibase.properties
- Download Secure Connect Bundle from DataStax Astra for your database and drag-and-drop it into the root level of the workspace
- Unzip a copy of the downloaded Secure Connect Bundle and open the config.json file in a code editor.
- 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
- Run liquibase status to confirm that unadded changesets are being seen
liquibase status
- Run liquibase update to run changeset
liquibase update
- Open DataStax Astra Studio to confirm that there are 3 new tables
- leaves_by_tag
- databasechangelog
- databasechangeloglock
- Change
liquibase.properties
file to now usedbchangelog.xml
vim liquibase.properties
- Run
liquibase status
again to confirm that there are now 2 new changesets that have not been run
liquibase status
- Run
liquibase update
to introduce the new changesets
liquibase update
- With Astra Studio, confirm there are now 3 records in the
databasechangelog
table and there is now atags
table - Run a rollback to revert a migration using the tag we introduced in changeset 2
liquibase rollback version_1.0.1
- With Astra studio, confirm rollback occured by seeing that the tags table is now gone and the dbchangelog table has been updated.
- Download Liquabase with the installer for your machine or use the tar.gz and then add liquibase to PATH
- Download the prerequisite JARs and place them into the
path/to/liquibase/lib
directory
- If you run into timeout errors, update your Java version to 1.8 from the version that it is currently on
- Rename astra.liquibase.properties to liquibase.properties
mv cassandra.liquibase.properties liquibase.properties
- Update the keyspace placeholder value with your specific keyspace
vim liquibase.properties
- Run liquibase status to confirm that unadded changesets are being seen
liquibase status
- Run liquibase update to run changeset
liquibase update
- Open CQLSH to to confirm that there are 3 new tables
- leaves_by_tag
- databasechangelog
- databasechangeloglock
- Change
liquibase.properties
file to now usedbchangelog.xml
vim liquibase.properties
- Run
liquibase status
again to confirm that there are now 2 new changesets that have not been run
liquibase status
- Run
liquibase update
to introduce the new changesets
liquibase update
- Using CQLSH, confirm there are now 3 records in the
databasechangelog
table and there is now atags
table - Run a rollback to revert a migration using the tag we introduced in changeset 2
liquibase rollback version_1.0.1
- Confirm with CQLSH that the rollback occured by seeing that the tags table is now gone and the dbchangelog table has been updated.
- Rename astra.liquibase.properties to liquibase.properties
mv astra.liquibase.properties liquibase.properties
- Download Secure Connect Bundle from DataStax Astra for your database and drag-and-drop it into the root level of the directory
- Unzip a copy of the downloaded Secure Connect Bundle and open the config.json file in a code editor.
- 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
- Run liquibase status to confirm that unadded changesets are being seen
liquibase status
- Run liquibase update to run changeset
liquibase update
- Open DataStax Astra Studio to confirm that there are 3 new tables
- leaves_by_tag
- databasechangelog
- databasechangeloglock
- Change
liquibase.properties
file to now usedbchangelog.xml
vim liquibase.properties
- Run
liquibase status
again to confirm that there are now 2 new changesets that have not been run
liquibase status
- Run
liquibase update
to introduce the new changesets
liquibase update
- With Astra Studio, confirm there are now 3 records in the
databasechangelog
table and there is now atags
table - Run a rollback to revert a migration using the tag we introduced in changeset 2
liquibase rollback version_1.0.1
- With Astra studio, confirm rollback occured by seeing that the tags table is now gone and the dbchangelog table has been updated.