Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/akarki15/dbdot

Generate DOT description for postgres db schema
https://github.com/akarki15/dbdot

graph-description-language postgresql schema

Last synced: about 2 months ago
JSON representation

Generate DOT description for postgres db schema

Awesome Lists containing this project

README

        

# dbdot

`dbdot` is a command line tool that generates [DOT](https://en.wikipedia.org/wiki/DOT_(graph_description_language)) description from postgres database schema.

`dbdot` is compiled to platform specific binary, so all you need is the right binary for your machine. Grab the appropriate binary for your architecture from the [latest release here](https://github.com/akarki15/dbdot/releases).

# Demos
#### Demo 1: Produce DOT for all the tables in postgres db `pgguide` and user `kewluser`
```
$ ./dbdot -dbname=pgguide -user=kewluser [16:33:31]
digraph {

node[label=<products[idinteger titlecharacter varying pricenumeric created_attimestamp with time zone deleted_attimestamp with time zone tagsARRAY]>,shape=plaintext] n1;
node[label=<purchase_items[idinteger purchase_idinteger product_idinteger pricenumeric quantityinteger statecharacter varying]>,shape=plaintext] n2;
node[label=<users[idinteger emailcharacter varying passwordcharacter varying detailsUSER-DEFINED created_attimestamp with time zone deleted_attimestamp with time zone]>,shape=plaintext] n3;
node[label=<purchases[idinteger created_attimestamp with time zone namecharacter varying addresscharacter varying statecharacter varying zipcodeinteger user_idinteger]>,shape=plaintext] n4;
n2->n1;
n2->n4;
n4->n3;

}
```
#### Demo 2: Produce a schema diagram for all the tables in `pgguide` db for `kewluser`
```
$ ./dbdot -dbname=pgguide -user=kewluser > test.dot && dot -Tpng test.dot -o outfile.png && open outfile.png
```
Above command pipes the DOT description into test.dot and invokes `dot` cli tool to transform test.dot to a outfile.png. Here's what outfile.png looks like:

![outfile.png](https://raw.githubusercontent.com/akarki15/dbdot/master/images/outfile.png)

#### Demo 3: Whitelist tables and produce schema diagram for them
```
./dbdot -dbname=pgguide -user=kewluser > test.dot --whitelist=purchase_items,purchases && dot -Tpng test.dot -o outfile-whitelisted.png && open outfile-whitelisted.png
```
Here's what outfile-whitelisted.png looks like:

![outfile-whitelisted.png](https://raw.githubusercontent.com/akarki15/dbdot/master/images/outfile-whitelisted.png)

# Flags
dbdot currently supports the following flags:
```
-W ask for password
-dbname string
dbname for which you want to generate dot file
-host string
database host (default "localhost")
-port uint
database port (default 5432)
-schema string
schema name (default "public")
-sslmode
enable sslmode for postgres db connection
-user string
username of postgres db
-whitelist string
comma separated list of tables you want to generate dot file for
```

# TODO
Here's some features I would like to have for this project:
* Support connection string. What happens if the user doesn't have access to db?
* Add support for more db types.
* Prettify output.
* Add ability to whitelist columns in a table. Users should be able whitelist columns per table. But this starts getting into territory of language design. i.e. what kind of cli syntax should dbdot support. Hence this is the last item in my list.

# Inspiration
A while back I wanted a _simple_ tool that would just spit out schema for tables that I wanted. A lot of tools I found were way too powerful, requiring a zillion installation and configuration. This inspired me to write a simple self contained tool that was laser focused on just reading schema and spitting out DOT.

# Similar projects
* http://schemaspy.org/