Welcome to Cassper, Cassandra migrations made easy

Overview

  • Cassper is a database migration tool. It strongly favors simplicity and convention over configuration.
  • Migrations can be written in CQL . All the CQL database syntax are supported. You can use the Maven plugin.
  • Supported database is Cassandra.
  • Written in Scala.

Migration

Cassper is supported for versioned migrations. Versioned migrations have a version, a checksum, a description and etc. The version must be unique.

The description is purely informative for you to be able to remember what each migration does.

The checksum is there to detect accidental changes.

They are applied in order exactly once.

Features

  • Creating/altering/dropping tables/UDT
  • Reference data updates
  • User data corrections

Samples

These are two samples we can do a migration using Cassper.

CREATE KEYSPACE IF NOT EXISTS mykeyspace
WITH replication = {
'class':'NetworkTopologyStrategy',
'DC1':'1'
};
CREATE TYPE IF NOT EXISTS mykeyspace.transaction (
execer TEXT,
id TEXT,
actor TEXT,
message_type TEXT,
message TEXT,
digsig TEXT,
timestamp TIMESTAMP
);

Naming

In order to be picked up by Cassper, CQL migrations must comply with the following naming pattern:

The file name consists of the following parts:

  • Prefix- V for versioned.
  • Version- Cassper has two versions.

Examples- 1_1 , 1_2, 2_1, 2_2 ………….. 400_1

  • Seperator1- This is used to seperate version and prefix.
  • Seperator2- This is used to seperate version and description.
  • Description- Underscores separate the words.

Examples- Add_new_keyspace, initialization, Create_table

  • Suffix- .cql

Examples for naming-

  • V_1_1__my_create_keyspace.cql
  • V_1_2__my_create_udt.cql
  • V_1_3__my_create_tables.cql

Discovery

Cassper discovers all the migration files within cassper directory inside resources.

Usage

Cassper can be used in Java and scala

  1. First add Cassper as dependency
  • Maven
<dependency>
<groupId>io.github.dataoperandz</groupId>
<artifactId>cassper</artifactId>
<version>0.3</version>
</dependency>
  • SBT
libraryDependencies += "io.github.dataoperandz" % "cassper" % "0.3"

https://mvnrepository.com/artifact/io.github.dataoperandz/cassper

2) Use keyspace name as parameter

val builder = new Cassper().build("keyspace", session)
builder.migrate("keyspace")
  • session- com.datastax.driver.core.Session
  • keyspace- keyspace name

3) Uses keyspace of session

val builder = new Cassper().build(session)
builder.migrate("keyspace")

How it works

When we use Cassper, it is created table called “schema_version”

Scripts are running ascending order by using version of the file. So we must use correct version when adding the new script file. Always it should be greater than existing latest version.

We can not change existing script files in Cassper. It will end up with exception because it is checked checksum of the all the files

Cassper Github repository

https://github.com/dataoperandz/cassper

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Install Discourse on Alibaba Cloud Using DirectMail and CDN

Renovate test-drive

Microsoft Shell For Windows 8

Cloud Native Architecture vs Conventional Architecture

Five steps become masters of web scraping in selenium(project walmart.com)

Ansible Tower

CORS Explained!

Time series databases vs OLAP

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pramod Shehan

Pramod Shehan

More from Medium

Apache Pulsar is #5 in Commits to ASF Projects

Qache — Your New Server-Side Caching Solution

How we leverage Elastic Reverse Search (Percolate) to power our coupons system

How to Handle s3:TestEvent with Lambda + SQS or SNS