Hooked on Bach - Updating Compose's command line

Published

Bach is Compose's command line tool for working with database deployments and it has just got easier than ever to use. Leveraging the Compose API has never been simpler with Bach 0.4.1.

Just over a year ago, we introduced you to Bach, the Compose command line tool which gave you a quick way to interact with the Compose API. Lots of users have told us they find it super useful, but we wanted to make it essential. So, here's Bach 0.4.1, the latest edition with some subtle but major enhancements.

What's my name

As a Compose user, you know your database deployments have a deployment id and a name. The Compose API works entirely with deployment ids, a 24 character hexadecimal number, and so Bach also demanded deployment ids. While I was working on another command line project, we had a similar problem with huge ids and short names for a command line. With a simple heuristic, we detected which was which and if it was a name, invoked a lookup to find the id for the database. It worked so well, we thought we'd bring that back to Bach.

So, what does that mean practically? Well, instead of typing...

$ bach details 59367927aac7d90016027163
              ID: 59367927aac7d90016027163
           Name: hot96
           Type: postgresql
        Version: 9.6.6
     Created At: 2017-06-06 09:43:03.523 +0000 UTC
....

We can type...

$ bach details hot96
             ID: 59367927aac7d90016027163
           Name: hot96
           Type: postgresql
        Version: 9.6.6
     Created At: 2017-06-06 09:43:03.523 +0000 UTC
...

Which is, a lot clearer and quicker. We've implemented this anywhere a command has needed a deployment id. Before you ask though; no, you can't rename existing deployments.

Who's who?

Bach has a deployments command and it took the form of a long vertical list of your databases. We've left that command in place but its now joined by the list command which gives a compact horizontal list:

$ bach list
ID                       Type           Name  
------------------------ -------------- ----------------------------------------
56aa59a641380c0010000000 mongodb        WiredForTigers  
59258b8a272d78000f8665d4 mysql          MyOwnPrivateSQL  
59367927aac7d90016027163 postgresql     hot96  
...

All about scale

In the past, if you used the bach scale command, it returned the raw values used for the database scale; units, type of scaling, size of unit. But they were just a list of values. In Bach 0.4.1, they are interpreted for you like so:

$  bach scale hot96
This is a storage scaled deployment.  
There are 2 units of 1024 MB storage allocated to it.  
This means a storage of 2048MB is available of which, 1024MB is used.  
The allocated units give each database node 204MB of RAM.  

This should make the information easier to consume. Pro-tip: If you still want the un-interpreted data, use the --json flag which returns the JSON data as processed by Bach:

$ bach scale hot96 --json
{
 "allocated_units": 2,
 "used_units": 1,
 "starting_units": 1,
 "minimum_units": 1,
 "unit_size_in_mb": 1024,
 "unit_type": "data"
}

Nearly all commands in Bach support the --json flag. Pro-pro-tip: If you use the --raw flag you get the un-manipulated data returned by the API, ideal if you have your own JSON parsing scripts to process it...

$ bach scale hot96 --raw
{"allocated_units":2,"used_units":1,"starting_units":1,"minimum_units":1,"unit_size_in_mb":1024,"memory_per_unit_in_mb":102,"storage_per_unit_in_mb":1024,"unit_type":"data"}

Again, that feature is supported by many commands.

What next for Bach?

Bach is open source and we would love to hear what you think of it. If you have a feature you want to add or already have your own extension, we're open for collaboration at https://github.com/compose/bach.


Read more articles about Compose databases - use our Curated Collections Guide for articles on each database type. If you have any feedback about this or any other Compose article, drop the Compose Articles team a line at articles@compose.com. We're happy to hear from you.

attribution Jordan Mixson

Dj Walker-Morgan
Dj Walker-Morgan was Compose's resident Content Curator, and has been both a developer and writer since Apples came in II flavors and Commodores had Pets. Love this article? Head over to Dj Walker-Morgan’s author page to keep reading.

Conquer the Data Layer

Spend your time developing apps, not managing databases.