cqlsh Keyspaces: CREATE, USE and DESCRIBE in CI
A keyspace is Cassandra's top-level container; in CI you create one with SimpleStrategy and replication_factor 1, then point the session at it with USE or -k.
Every Cassandra table lives in a keyspace. A single-node CI cluster needs SimpleStrategy with replication_factor 1, or writes and reads fail consistency.
What it does
CREATE KEYSPACE defines a namespace and its replication strategy. On a one-node test cluster, SimpleStrategy with replication_factor 1 is the correct choice; higher factors cannot be satisfied and queries error at quorum. USE or cqlsh -k selects the active keyspace for subsequent statements.
Common usage
cqlsh -e "CREATE KEYSPACE IF NOT EXISTS app WITH replication = \
{'class':'SimpleStrategy','replication_factor':1}"
cqlsh -e "USE app; CREATE TABLE IF NOT EXISTS users (id uuid PRIMARY KEY, name text)"
cqlsh -e "DESCRIBE KEYSPACES"Options
| Statement / flag | What it does |
|---|---|
| CREATE KEYSPACE ... IF NOT EXISTS | Create a keyspace if absent (idempotent) |
| {'class':'SimpleStrategy','replication_factor':1} | Single-node replication for tests |
| USE <keyspace> | Set the active keyspace for the session |
| -k <keyspace> | Select a keyspace from the cqlsh command line |
| DESCRIBE KEYSPACES | List keyspaces to confirm creation |
| DROP KEYSPACE IF EXISTS | Tear down between test runs |
In CI
Use IF NOT EXISTS on creation and IF EXISTS on teardown so a rerun does not fail. Keep replication_factor at 1 for a single container; NetworkTopologyStrategy needs named datacenters that a default test node does not have. After a CREATE on a multi-node cluster, allow for schema agreement before dependent DDL.
Common errors in CI
"ConfigurationException: Unable to find replication strategy class ..." means a typo in the class name. "Cannot achieve consistency level ONE" or quorum errors usually mean replication_factor exceeds the live node count. "AlreadyExists: Keyspace app already exists" means you omitted IF NOT EXISTS on a rerun.