A rewrite of the plugin https://github.com/inoio/sbt-pillar-plugin and added:
- Allow use of Authentication credentials.
- Allow passing in hosts as a comma-separated string.
- Allow creating of cql migration files.
- Will allow use of NetworkTopologyStrategy for creating keyspaces.
This sbt plugin enables running Cassandra schema/data migrations from sbt (using pillar). For details on migration files check out the pillar documentation.
The plugin is built for sbt 0.13.6+.
To install the plugin you have to add it to project/plugins.sbt
:
addSbtPlugin("io.github.henders" %% "sbt-pillar" % "0.1.7")
Add appropriate configuration to build.sbt
like this:
pillarConfigFile in ThisBuild := file("db/pillar.conf")
pillarMigrationsDir in ThisBuild := file("db/migrations")
The shown configuration assumes that the settings for your cassandra are configured in db/pillar.conf
and that pillar migration files are kept in db/migrations
(regarding the format of migration files
check out the pillar documentation).
An example configuration file (based on typesafe-config) is:
development {
cassandra {
keyspace = "pigeon"
hosts = "localhost"
port = 9042
replicationFactor = 1
defaultConsistencyLevel = 1
replicationStrategy = "SimpleStrategy"
}
}
test = ${development}
test {
cassandra {
keyspace = "pigeon_test"
}
}
master {
cassandra {
hosts = ${?CASSANDRA_HOSTS}
port = 9042
keyspace = ${?CASSANDRA_KEYSPACE}
username = ${?CASSANDRA_USERNAME}
password = ${?CASSANDRA_PASSWORD}
replicationFactor = ${?CASSANDRA_REPLICATION_FACTOR}
defaultConsistencyLevel = ${?CASSANDRA_CONSISTENCY_LEVEL}
replicationStrategy = "SimpleStrategy"
}
}
staging = ${master}
production = ${master}
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)
- createMigration
- Create a new migration file from the name passed in.
e.g.
$ sbt 'createMigration create_user_settings'
[info] Loading config file: db/pillar.conf for environment: development
[info] Creating migration file: db/migrations/20160520105550_create_user_settings_timeseries.cql
[success] Created migration 'db/migrations/20160520105550_create_user_settings_timeseries.cql'
$ sbt cleanMigrate
[info] Loading config file: db/pillar.conf for environment: development
[info] Dropping keyspace pigeon at 192.168.42.45:9042
[info] Creating keyspace pigeon at 192.168.42.45:9042
[info] Migrating keyspace pigeon at 192.168.42.45:9042
[success] Total time: 10 s, completed 20-May-2016 11:07:05
Currently only the replication strategy 'SimpleStrategy' works. This will be resolved in next version.
The license is MIT (https://opensource.org/licenses/MIT), have at it!