Welcome to Cassper, Cassandra migrations made easy

Overview

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

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:

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

Examples- Add_new_keyspace, initialization, Create_table

Examples for naming-

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
<dependency>
<groupId>io.github.dataoperandz</groupId>
<artifactId>cassper</artifactId>
<version>0.3</version>
</dependency>
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")

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