This sbt plugin allows to run Cassandra schema/data migrations from sbt (using pillar). For details on migration files check out the pillar documentation. The cassandra connection configuration is not based on pillar but we're using our own format (see Configuration).
The plugin is built for sbt 0.13.
To install the plugin you have to add it to project/plugins.sbt
:
addSbtPlugin("io.ino" %% "sbt-pillar-plugin" % "2.1.2")
Add appropriate configuration to build.sbt
like this:
import io.ino.sbtpillar.Plugin.PillarKeys._
...
pillarSettings
pillarConfigFile := file("conf/application.conf")
pillarConfigKey := "cassandra.url"
pillarReplicationStrategyConfigKey := "cassandra.replicationStrategy"
pillarReplicationFactorConfigKey := "cassandra.replicationFactor"
pillarDefaultConsistencyLevelConfigKey := "cassandra.defaultConsistencyLevel"
pillarMigrationsDir := file("conf/migrations")
//optionally:
pillarExtraMigrationsDirs := Seq(file("conf/extra-migrations"))
The shown configuration assumes that the url for your cassandra is configured in conf/application.conf
under the key
cassandra.url
and that pillar migration files are kept in conf/migrations
(regarding the format of migration files
check out the pillar documentation).
The cassandra.url
has to follow the format cassandra://<host>:<port>/<keyspace>?host=<host>&host=<host>
, e.g. it would be
cassandra.url="cassandra://192.168.0.10:9042/my_keyspace?host=192.168.0.11&host=192.168.0.12"
.
The pillarMigrationsDir
contains the directory with the cql-files to process. It's processed recursively, therefore files in subfolders are picked up as well.
The pillarReplicationStrategyConfigKey
is optional, the default value is SimpleStrategy
.
The pillarReplicationFactorConfigKey
is optional, the default value is 3
.
The pillarDefaultConsistencyLevelConfigKey
is optional, the default value is QUORUM
.
The pillarExtraMigrationsDirs
is optional, the default is Seq.empty
. Here you can add directories containing extra migration files, which will be processed in addition to the ones in pillarMigrationsDir
.
The sbt pillar plugin provides the following tasks:
- createKeyspace
- Creates the keyspace (and creates pillar's
applied_migrations
table) - dropKeyspace
- Drops the keyspace
- migrate
- Runs pillar migrations (assumes
createKeyspace
was run before) - cleanMigrate
- Recreates the keyspace (drops if exists && creates) and runs pillar migrations (useful for continuous integration scenarios)
The license is Apache 2.0, see LICENSE.txt.