Giter VIP home page Giter VIP logo

tblsrun's Introduction

tblsrun

Generate database documentation from migration files. Uses tbls internally to generate the docs. Useful for reviewing database schema change in your team.

How it works?

It works by spawning a database, then it will run the migrations files, and run the tbls to generate the db doc.

Currently it only support postgres for the DB & golang-migrate for migration files format

Example Database

Here is the example database documentation link

Snippets

db documentation snipped

Installation

go install github.com/fahmifan/tblsrun/cmd/tblsrun@latest

How To Use

  • Set env variables, you can use .env.example as a reference.
  • Create tbls config (see example.tbls.yml)
  • Then run tbslrun, e.g.: tblsrun postgres docker
    • Currently it only support postgres with 2 modes embedded or docker
      • embedded will run postgres binary as child process
      • docker will spawn a postgres docker container, you need docker installed to use this
    • When running, it will install the latest tbls automatically if not exists in the $PATH

Environtment Variables

  • TBLS_DATABASE_NAME
    • your database name, it will be use in the generated doc
  • TBLS_DATABASE_SCHEMA
    • your database schema, it will be use in the generated doc
  • TBLS_DATABASE_PORT
    • override the default database port (e.g. postgres: 5432)
  • TBLS_MIGRATION_DIR
    • the directory where your migration files are located
    • currently only support golang-migrate format
  • TBLS_CONFIG_FILE
    • the path to your tbls config file

Multiple migrations folder & schemas

One use case for this is when you have multiple schemas in your database with separate migrations folder, and you want to generate the doc for each schema.

To enable this, you need to set the TBLS_DATABASE_SCHEMA to schema_1,schema_2,schema_n, and the TBLS_MIGRATION_DIR to dir_1,dir_2,dir_n.

If we want to generate it into different folder, we need to have multiple .tbls.yml & .env files, example to configure this:

# schema_1.tbls.yml
docPath: example/dbdoc/bar

# schema_2.tbls.yml
docPath: example/dbdoc/foo

Check example for more details.

Available Commands

Generate database documentation from migration files

Usage:
  tblsrun [command]

Available Commands:
  help        Help about any command
  postgres    Run tbls with postgres

Flags:
      --env-file string   --env-file="custom.env" (default ".env")
  -h, --help   help for tblsrun

Testing

To do manual test we can run make dbdoc and check there should be 2 output

tblsrun's People

Contributors

fahmifan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

kokizzu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.