cassandra-migration-tool

Cassandra schema migration tool

License

License

Categories

Categories

Cassandra Data Databases
GroupId

GroupId

io.smartcat
ArtifactId

ArtifactId

cassandra-migration-tool
Last Version

Last Version

3.1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

cassandra-migration-tool
Cassandra schema migration tool
Project URL

Project URL

https://github.com/smartcat-labs/cassandra-migration-tool-java
Source Code Management

Source Code Management

https://github.com/smartcat-labs/cassandra-migration-tool-java

Download cassandra-migration-tool

How to add to project

<!-- https://jarcasting.com/artifacts/io.smartcat/cassandra-migration-tool/ -->
<dependency>
    <groupId>io.smartcat</groupId>
    <artifactId>cassandra-migration-tool</artifactId>
    <version>3.1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.smartcat/cassandra-migration-tool/
implementation 'io.smartcat:cassandra-migration-tool:3.1.0.0'
// https://jarcasting.com/artifacts/io.smartcat/cassandra-migration-tool/
implementation ("io.smartcat:cassandra-migration-tool:3.1.0.0")
'io.smartcat:cassandra-migration-tool:jar:3.1.0.0'
<dependency org="io.smartcat" name="cassandra-migration-tool" rev="3.1.0.0">
  <artifact name="cassandra-migration-tool" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.smartcat', module='cassandra-migration-tool', version='3.1.0.0')
)
libraryDependencies += "io.smartcat" % "cassandra-migration-tool" % "3.1.0.0"
[io.smartcat/cassandra-migration-tool "3.1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.datastax.cassandra : cassandra-driver-core jar 3.1.0
org.slf4j : slf4j-api jar 1.7.7

test (5)

Group / Artifact Type Version
com.google.guava : guava jar 18.0
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19
org.cassandraunit : cassandra-unit jar 3.0.0.1
org.fusesource : sigar jar 1.6.4

Project Modules

There are no modules declared in this project.

cassandra-migration-tool-java

Build Status

Cassandra migration tool for java is a lightweight tool used to execute schema and data migration on Cassandra database. Schema versioning state is saved in schema_version table which stores name and description of migration along with type and timestamp.

There are two types of migrations:

  1. SCHEMA migrations, which alter database schema (add or remove column, change type of column, add table, etc)
  2. DATA migrations, which alter data (update, read from one table to another, calculate new fields based on existing data, etc).

Why we did it

The idea behind this project was born while working on a project with live data. Since the development required changes to the data model we had to figure out a way we can update the database schema while keeping the data. We ended up with a lightweight tool that versions database and enables us to change schema and transform data when and how we want (as a part of a build and deploy cycle or application itself). Since these changes are part of the codebase we could also test them before executing on a live cluster.

Versioning

We are going to follow the official DataStax Java driver versions and build our driver for each major, minor and patch version of the driver. We chose this path because of the simplicity to develop, test and deploy for different versions of the driver. This means that if you are using the driver version 2.1.9 you can add this dependency to your project:

<dependency>
    <groupId>io.smartcat</groupId>
    <artifactId>cassandra-migration-tool</artifactId>
    <version>2.1.9.0</version>
</dependency>

or whatever the latest build version of the migration tool is. Check the version at the Maven repository.

Examples

We have two test cases which explain common problems which migration tool can solve. This is only subset of use cases but we think these are most frequent once:

First use case touches problem of adding new field and populating historic data with value. Cassandra does not have DDL default attribute, so you must populate data on application level. MigrationEngineBooksTest can serve as an example of that use case which this tool can cover.

The initial table is simple (can be found in books.cql file) and we use migration classes to do the following:

  1. Populate data initially with first data migration InsertBooksMigration
  2. Add genre column with schema migration AddBookGenreFieldMigration
  3. Populate genre column with second data migration AddGenreMigration

Second use case touches problem of query based modeling. Cassandra has good performance because you model your data as you will query it. Often after initial modeling you have request to read it based on different criteria. In Cassandra you do this with another table which is optimized for new requirements. You need to populate this new table with existing data and you can solve this with migration tool. MigrationEngineItemsTest can serve as an example of that use case which this tool can cover.

The initial table is simple (can be found in items.cql file) and we use migration classes to do the following:

  1. Populate data initially with first data migration InsertInitialItemsMigration
  2. Add items_by_number_external_id table with schema migration CreateItemByNumberAndExternalIdMigration
  3. Populate items_by_number_external_id table with second data migration PopulateItemByNumberAndExternalIdMigration

Schema agreement

When executing schema migrations it is necessary to wait for cluster to propagate schema on all nodes. Schema agreement is implemented based on this fix and is exposed through Migration abstract class. To execute a statement with schema agreement you can use executeWithSchemaAgreement method.

io.smartcat

SmartCat Labs

SmartCat labs is our code playground with opensource products, libraries and examples.

Versions

Version
3.1.0.0
2.1.9.1
2.1.9.0
0.0.1