DEV Community

maru44
maru44

Posted on

A Tool to Visualize Definition of Tables in RDB

Link:
https://github.com/maru44/scheman

Scheman is a tool to visualize definition of tables in RDB.

Main purpose of this is accelerating working collaboration between engineers and non-engineers.

You can generate drawing of tables schema and ERD with one command and just a few settings by using this.

You can choose output destination from Notion, File or both of them.

Usage

I will show you usage.

Installation

install

go install github.com/maru44/scheman@v1.3.0
Enter fullscreen mode Exit fullscreen mode

If you want not to install you can use by

go run github.com/maru44/scheman@v1.3.0 ...
Enter fullscreen mode Exit fullscreen mode

I will proceed on the premise of scheman installed.

Setup config

Create scheman.toml(.yaml) and write database settings.

[psql]
  dbname  = "scheman"
  host    = "localhost"
  port    = 5432
  user    = "root"
  pass    = "password"
  sslmode = "disable"
  schema  = "public"

Enter fullscreen mode Exit fullscreen mode

Command

I will show some examples.

Notion

First I will show you the command to write tables schema and ERD in notion.

go install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@v4.8.6 \
  && scheman psql --services notion --erd-outputs notion \
    --notion-token ${NOTION_TOKEN} --notion-page-id ${PSQL_NOTION_PAGE_ID}
Enter fullscreen mode Exit fullscreen mode

Flag services indicates the output destinations of schema-definition.
Flag erd-outputs indicates the output destinations of ERD.

The value of table-index is output like the following picture if the command succeeded.
If you want to overwrite schema definition and ERD in notion from next time, please set notion-page-index the value outputted in command line.

result outputted in command line

The Free Entry attribute is the attribute you can write freely. This value is inherited even if you execute scheman command next time.

The outputs will be like these pictures.
I'm sorry for these pictures are very rough.

schema-definition
https://user-images.githubusercontent.com/46714011/155822065-f0f9f785-b2b1-4abd-b98b-052496dff169.png

ERD
https://user-images.githubusercontent.com/46714011/155862202-77e81b99-681a-44fb-bf1c-669dae7f1f5a.png

File

go install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@v4.8.6 \
  && scheman psql --def-file ./def.csv --erd-file ./erd.md
Enter fullscreen mode Exit fullscreen mode

Flag def-file indicates the output destination file of schema-definition.
Flag erd-file indicates the output destination file of ERD.

The outputs will be like these.

schema-definition
https://github.com/maru44/scheman/blob/master/testdata/postgres/def.csv

ERD
https://github.com/maru44/scheman/blob/master/testdata/postgres/erd.md

Options

  • config
    • the file written configurations
    • default is scheman
    • you can use sqlboiler.toml if you set this sqlboiler.toml
  • services
    • indicates the output destinations of schema-definition
    • default is [ ]
    • option is only notion yet
  • erd-outputs
    • indicates the output destinations of ERD
    • default is [ ]
    • option is only notion yet
  • disable-views
    • if true, scheman ignore views
    • default is false
  • attr-ignore
    • which attributes ignore
    • default is [ ]
    • options are Data Type, PK, Auto Generate, Unique, Null, Default, Comment, Free Entry, Enum

Thanks

Using sqlboiler to parse connected database.
https://github.com/volatiletech/sqlboiler

Using go-notion as notion client.
https://github.com/dstotijn/go-notion

Top comments (0)