I fully and very strongly disagree with all the advice given above. The whole point of phantom is to never have to write CQL, and we have complete mechanisms that allow you to control how your schema gets initialised, inclusive of all possible properties.
Have a look at the tests here or at the default Cassandra initialisation, there's pretty much nothing you can't do.
Custom settings in autocreation
If you want to provide all those params instead of defaults during database.autocreate
, that's really simple too:
class MyTable extends CassandraTable[MyTable, MyRecord] {
override def autocreate(
keySpace: KeySpace
): CreateQuery.Default[T, R] = create.ifNotExists()(keySpace)
.`with`(compaction eqs LeveledCompactionStrategy.sstable_size_in_mb(50))
.and(compression eqs LZ4Compressor.crc_check_chance(0.5))
}
Later when you do this:
class MyDB(override val connector: KeySpaceDef) extends Database {
object myTable extends MyTable with connector.Connector
}
And you do:
val database = new MyDB(ContactPoint.local.keySpace("whatever")
When you run database.createAsync
or database.create
, all the settings you defined above will be respected.
Custom keyspace autocreation
Phantom also supports specifying custom keyspace initialisation queries during keyspace autogeneration.
val init = KeySpaceSerializer("my_app").ifNotExists()
.`with`(replication eqs SimpleStrategy.replication_factor(2))
.and(durable_writes eqs true)
val connector = ContactPoint.local.keySpace(
"my_app",
(session, space): (Session, KeySpace) => init.queryString
)
This way you can benefit from any known form of customisation you can think of while still not having to deal with CQL. If you use phantom-pro
which will shortly be available for subscription, there will also be automated schema migration capability, so holding your schema in any kind of CQL is a very big no no.
Phantom also transparently handles CQL variations between versions, I've never seen a bash script who does that, so you can get into unpleasantries quite quickly with a simple Cassandra upgrade/downgrade, and why would you if you can just automate things?