cqlsh -f: Run a CQL Script File in CI
cqlsh -f schema.cql executes every statement in a CQL file against Cassandra and exits.
Schema and seed data for Cassandra live in versioned .cql files. -f applies them in CI exactly as you would locally.
What it does
cqlsh -f reads a file of semicolon-terminated CQL statements and runs them in order. The interactive equivalent is the SOURCE command. By default cqlsh stops at the first error, so a broken statement fails the file and the CI step.
Common usage
cqlsh -f ./schema.cql 127.0.0.1 9042
# pick a keyspace before running the file
cqlsh -k app -f ./migrations/001.cql
# interactive equivalent
cqlsh -e "SOURCE './schema.cql'"Options
| Flag | What it does |
|---|---|
| -f <path> | Execute statements from the file and exit |
| -k <keyspace> | Set the active keyspace for the session |
| SOURCE '<path>' | Interactive command to run a file |
| -u / -p | Authentication credentials |
| --request-timeout <s> | Per-statement timeout for slow DDL |
In CI
Make schema files idempotent with IF NOT EXISTS so reruns do not error on already-created keyspaces or tables. cqlsh halts on the first failed statement, which is what you want for a migration; if you deliberately need to continue, you must split the file. DDL changes propagate as schema agreement across nodes, so a multi-node cluster may need a brief settle before dependent queries.
Common errors in CI
"SyntaxException: line N:M ..." points to a malformed statement at that position in the file. "ConfigurationException: Keyspace ... does not exist" means an earlier CREATE KEYSPACE did not run or you did not pass -k. "Unable to connect to any servers" means Cassandra is not ready; gate the file behind a readiness check.