DEV Community

Sualeh Fatehi
Sualeh Fatehi

Posted on • Updated on

How to Document Your Cassandra Database with One Command (and Nothing to Install)

Ever wondered what the tables in your Cassandra database look like? Generate a text file of your Cassandra database with one command. You can run this on any system that has Docker installed.

For now, create a Cassandra database in a Docker container. Later you can use the same technique to conect to your own Cassandra database. Create two Docker Compose files for the Cassandra and SchemaCrawler containers. Also create one more with the CQL database creation script. You can find these files in the GitHub gist for this article.

Then open a command shell in the same folder that you created these files, and run:

docker-compose -f schemacrawler.yml -f cassandra.yml up -d
Enter fullscreen mode Exit fullscreen mode

Wait for a while for the containers to start up, and then connect into the Cassandra container by running:

docker exec -it cassandra bash
Enter fullscreen mode Exit fullscreen mode

In the Cassandra container shell, run the script to create a sample database, and exit the shell:

cqlsh -f /share/database.cql
exit
Enter fullscreen mode Exit fullscreen mode

Now that the Cassandra database is created, connect into the SchemaCrawler container by running:

docker exec -it schemacrawler bash
Enter fullscreen mode Exit fullscreen mode

In the SchemaCrawler container shell, run SchemaCrawler against the Cassandra database to see your table. Run:

schemacrawler \
  --url jdbc:cassandra://cassandra:9042/store \
  --user cassandra --password cassandra \
  --info-level minimum \
  --command list
Enter fullscreen mode Exit fullscreen mode

After you have got this working, you can alter the command to show more details of the database. For example, you can run:

schemacrawler \
  --url jdbc:cassandra://cassandra:9042/store \
  --user cassandra --password cassandra \
  --info-level standard \
  --command schema
Enter fullscreen mode Exit fullscreen mode

You can save the output with an additional --output-file /share/schema.txt argument, and the file will be created in your local directory. schemacrawler help will give you more information, as well as the SchemaCrawler website. Now you are ready to connect to your own database. If you need help on how to construct the connection URL, take a look at ing-bank/cassandra-jdbc-wrapper.

Top comments (3)

Collapse
 
adriens profile image
adriens

Hi @sualeh I wonder if you could the same oneLiner on the following NoSQL databases :

Collapse
 
sualeh profile image
Sualeh Fatehi

@adriens - good idea. Let me try out their JDBC drivers, and see what I can do.

Collapse
 
adriens profile image
adriens

I did play with Neo4J driver a long time ago, cf dedicated article

Also, it could be cool to organize these posts within a dedicated DEV.to series like "Schemacrawler oneliners" (one post per database).

This serie could be used as a reference for all databases.