tblsrun

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 6 Imported by: 0

README

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
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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Database Database
	TBLS     TBLS
}

func NewConfig

func NewConfig(env string) (Config, error)

NewConfig creates an instance of Config. It needs the path of the env file to be used.

type Database

type Database struct {
	Name     string
	Schema   string
	Username string
	Password string
	Host     string
	Port     string
}

func (Database) DSN

func (db Database) DSN() string

func (Database) DSNDefaultDBName deprecated

func (db Database) DSNDefaultDBName() string

Deprecated: use DSN instead

func (Database) DSNWithoutSchema added in v0.3.0

func (db Database) DSNWithoutSchema() string

func (Database) GetPort

func (db Database) GetPort() uint32

func (Database) QuotedName

func (db Database) QuotedName() string

func (Database) WithDBName

func (d Database) WithDBName(dbName string) Database

func (Database) WithSchema

func (d Database) WithSchema(schema string) Database

type TBLS

type TBLS struct {
	DBName       string `env:"TBLS_DATABASE_NAME"`
	DBPort       string `env:"TBLS_DATABASE_PORT,default=5432"`
	Schema       string `env:"TBLS_DATABASE_SCHEMA"`
	MigrationDir string `env:"TBLS_MIGRATION_DIR"`
	CfgFile      string `env:"TBLS_CONFIG_FILE,default=.tbls.yml"`
}

func (TBLS) GetConfigFiles added in v0.3.0

func (tbls TBLS) GetConfigFiles() []string

func (TBLS) GetMigrationDirs added in v0.3.0

func (tbls TBLS) GetMigrationDirs() []string

func (TBLS) GetSchemas added in v0.3.0

func (tbls TBLS) GetSchemas() (schemas []string)

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL