Code Monkey home page Code Monkey logo

example-cassandra-liquibase's Introduction

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:

example-cassandra-liquibase's People

Contributors

adp8ke avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.