Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy changes to a Cassandra CQL schema

We have an application which is using Cassandra for its database. How should we deploy schema changes in a live production environment.

In development we are just blowing the database away and recreating it with a 'database.cql' script kept in version control. This clearly isn't a solution in production.

In the relational world I would either use a sequence of upgrade scripts and apply them in order, or use a tool to interactively compare the staging and production databases and make the appropriate schema changes.

How do I solve the same problem in the Cassandra?

like image 592
Phil Avatar asked Oct 20 '14 08:10

Phil


2 Answers

Here's one I've started and have been using for a while.

https://github.com/heartysoft/aedes

It supports multiple environments, and versioning. Since we're Windows based, it's mainly powershell, but there's no reason a bash script couldn't be written to do the equivalent. The powershell script itself is extremely simple. It requires Powershell v3+. Usage is pretty easy:

aedes.ps1 192.168.40.4 [-u username -p password -env dev]

will look for schema files in the ..\schema folder. Schema files are expected to have a n_ prefix. Environment specific files have a .env.cql postfix. So, if the files are:

1_people.dev.cql
1_people.prod.cql
2_people_some_indexes.cql
3_jobs.dev.cql
3_jobs.prod.cql
4_jobs_something_changed.cql

And run it for prod, then the ones with .prod.cql and no "env" .cql will be applied in order. You can also specify a $start version that can be used to specify where to start applying from (e.g. if start is specified as 3, then anything with 1_ and 2_ will be skipped).

It's pretty basic but seems to work quite well. We just have Cassandra downloaded (not installed) on the "applier machine" (which could be your machine, i.e. not part of a cluster) and have cqlsh on the PATH for easier application. Did (and do) have plans for more features, but working nicely as is for the time being.

like image 178
ashic Avatar answered Nov 17 '22 04:11

ashic


Since there wasn't an existing tool, I ended up writing one.

It is called cql-migrate, and provides incremental updates to a deployed Cassandra schema.

[update] Since writing this, I have found a couple more options: one for for rails and another for go

like image 22
Phil Avatar answered Nov 17 '22 03:11

Phil