Giter Site home page Giter Site logo

k1low / tbls Goto Github PK

View Code? Open in Web Editor NEW
3.1K 24.0 155.0 121.86 MB

tbls is a CI-Friendly tool for document a database, written in Go.

License: MIT License

Makefile 2.77% Go 96.82% Shell 0.31% Dockerfile 0.10%
database-schema mysql database-document documentation-tool postgresql sqlite bigquery spanner redshift sqlserver

tbls's Introduction


tbls

Build Status GitHub release Go Report Card Coverage Code to Test Ratio Test Execution Time

tbls ( is pronounced /ˈteɪbl̩z/. ) is a CI-Friendly tool for document a database, written in Go.

Key features of tbls are:

Table of Contents


Quick Start

Document a database with one command.

$ tbls doc postgres://dbuser:dbpass@hostname:5432/dbname

Using docker image.

$ docker run --rm -v $PWD:/work -w /work ghcr.io/k1low/tbls doc postgres://dbuser:dbpass@hostname:5432/dbname

Install

deb:

$ export TBLS_VERSION=X.X.X
$ curl -o tbls.deb -L https://github.com/k1LoW/tbls/releases/download/v$TBLS_VERSION/tbls_$TBLS_VERSION-1_amd64.deb
$ dpkg -i tbls.deb

RPM:

$ export TBLS_VERSION=X.X.X
$ yum install https://github.com/k1LoW/tbls/releases/download/v$TBLS_VERSION/tbls_$TBLS_VERSION-1_amd64.rpm

Homebrew:

$ brew install k1LoW/tap/tbls

MacPorts:

$ sudo port install tbls

aqua:

$ aqua g -i k1LoW/tbls

Manually:

Download binary from releases page

go install:

$ go install github.com/k1LoW/tbls@latest

Docker:

$ docker pull ghcr.io/k1low/tbls:latest

On GitHub Actions:

# .github/workflows/doc.yml
name: Document

on:
  push:
    branches:
      - main

jobs:
  doc:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout .tbls.yml
        uses: actions/checkout@v3
      -
        uses: k1low/setup-tbls@v1
      -
        name: Run tbls for generate database document
        run: tbls doc

:octocat: GitHub Actions for tbls is here.

Temporary:

$ source <(curl https://raw.githubusercontent.com/k1LoW/tbls/main/use)
$ curl -sL https://raw.githubusercontent.com/k1LoW/tbls/main/use > /tmp/use-tbls.tmp && . /tmp/use-tbls.tmp

Getting Started

Document a database

Add .tbls.yml ( or tbls.yml ) file to your repository.

# .tbls.yml

# DSN (Database Source Name) to connect database
dsn: postgres://dbuser:dbpass@localhost:5432/dbname

# Path to generate document
# Default is `dbdoc`
docPath: doc/schema

Notice: If you are using a symbol such as # < in database password, URL-encode the password

Run tbls doc to analyzes the database and generate document in GitHub Friendly Markdown format.

$ tbls doc

Commit .tbls.yml and the document.

$ git add .tbls.yml doc/schema
$ git commit -m 'Add database document'
$ git push origin main

View the document on GitHub.

Sample document

sample

Diff database and ( document or database )

Update database schema.

$ psql -U dbuser -d dbname -h hostname -p 5432 -c 'ALTER TABLE users ADD COLUMN phone_number varchar(15);'
Password for user dbuser:
ALTER TABLE

tbls diff shows the difference between database schema and generated document.

$ tbls diff
diff postgres://dbuser:*****@hostname:5432/dbname doc/schema/README.md
--- postgres://dbuser:*****@hostname:5432/dbname
+++ doc/schema/README.md
@@ -4,7 +4,7 @@

 | Name | Columns | Comment | Type |
 | ---- | ------- | ------- | ---- |
-| [users](users.md) | 7 | Users table | BASE TABLE |
+| [users](users.md) | 6 | Users table | BASE TABLE |
 | [user_options](user_options.md) | 4 | User options table | BASE TABLE |
 | [posts](posts.md) | 8 | Posts table | BASE TABLE |
 | [comments](comments.md) | 6 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
diff postgres://dbuser:*****@hostname:5432/dbname doc/schema/users.md
--- postgres://dbuser:*****@hostname:5432/dbname
+++ doc/schema/users.md
@@ -14,7 +14,6 @@
 | email | varchar(355) |  | false |  |  | ex. [email protected] |
 | created | timestamp without time zone |  | false |  |  |  |
 | updated | timestamp without time zone |  | true |  |  |  |
-| phone_number | varchar(15) |  | true |  |  |  |

 ## Constraints

And, tbls diff support for diff checking between database and other database

$ tbls diff postgres://dbuser:*****@local:5432/dbname postgres://dbuser:*****@production:5432/dbname

Notice: tbls diff shows the difference Markdown documents only.

Re-generating database documentation

Existing documentation can re-generated using either --force or --rm-dist flag.

--force forces overwrite of the existing documents. It does not, however, remove files of removed tables.

$ tbls doc --force

--rm-dist removes files in docPath before generating the documents.

$ tbls doc --rm-dist

Lint a database

Add linting rule to .tbls.yml following

# .tbls.yml
lint:
  requireColumnComment:
    enabled: true
    exclude:
      - id
      - created
      - updated
  columnCount:
    enabled: true
    max: 10

Run tbls lint to check the database according to lint: rules

$ tbls lint
users.username: column comment required.
users.password: column comment required.
users.phone_number: column comment required.
posts.user_id: column comment required.
posts.title: column comment required.
posts.labels: column comment required.
comments.post_id: column comment required.
comment_stars.user_id: column comment required.
post_comments.comment: column comment required.
posts: too many columns. [12/10]
comments: too many columns. [11/10]

11 detected

Measure document coverage

tbls coverage measure and show document coverage ( description, comments ).

$ tbls coverage
Table                       Coverage
All tables                  16.1%
 public.users               20%
 public.user_options        37.5%
 public.posts               35.3%
 public.comments            14.3%
 public.comment_stars       0%
 public.logs                12.5%
 public.post_comments       87.5%
 public.post_comment_stars  0%
 public.CamelizeTable       0%
 public.hyphen-table        0%
 administrator.blogs        0%
 backup.blogs               0%
 backup.blog_options        0%
 time.bar                   0%
 time.hyphenated-table      0%
 time.referencing           0%

Continuous Integration

Continuous integration using tbls.

  1. Commit the document using tbls doc.
  2. Update the database schema in the development cycle.
  3. Check for document updates by running tbls diff or tbls lint in CI.
  4. Return to 1.

Example: Travis CI

# .travis.yml
language: go

install:
  - source <(curl -sL https://raw.githubusercontent.com/k1LoW/tbls/main/use)
script:
  - tbls diff
  - tbls lint

Tips: If your CI based on Debian/Ubuntu (/bin/sh -> dash), you can use the following install command curl -sL https://raw.githubusercontent.com/k1LoW/tbls/main/use > use-tbls.tmp && . ./use-tbls.tmp && rm ./use-tbls.tmp

Tips: If the order of the columns does not match, you can use the --sort option.

Configuration

Name

name: is used to specify the database name of the document.

# .tbls.yml
name: mydatabase

Description

desc: is used to specify the database description.

# .tbls.yml
desc: This is My Database

Labels

labels: is used to label the database or tables.

label database:

# .tbls.yml
labels:
  - cmdb
  - analytics

label tables:

# .tbls.yml
comments:
  -
    table: users
    labels:
      - user
      - privacy data

label columns:

# .tbls.yml
comments:
  -
    table: users
    columnLabels:
      email:
        - secure
        - encrypted

DSN

dsn: (Data Source Name) is used to connect to database.

# .tbls.yml
dsn: my://dbuser:dbpass@hostname:3306/dbname

Support Datasource

tbls supports the following databases/datasources.

PostgreSQL:

# .tbls.yml
dsn: postgres://dbuser:dbpass@hostname:5432/dbname
# .tbls.yml
dsn: pg://dbuser:dbpass@hostname:5432/dbname

When you want to disable SSL mode, add "?sslmode=disable" For example:

dsn: pg://dbuser:dbpass@hostname:5432/dbname?sslmode=disable

MySQL:

# .tbls.yml
dsn: mysql://dbuser:dbpass@hostname:3306/dbname
# .tbls.yml
dsn: my://dbuser:dbpass@hostname:3306/dbname

When you want to hide AUTO_INCREMENT clause on the table definitions, add "?hide_auto_increment". For example:

dsn: my://dbuser:dbpass@hostname:3306/dbname?hide_auto_increment

MariaDB:

# .tbls.yml
dsn: mariadb://dbuser:dbpass@hostname:3306/dbname
# .tbls.yml
dsn: maria://dbuser:dbpass@hostname:3306/dbname

SQLite:

# .tbls.yml
dsn: sqlite:///path/to/dbname.db
# .tbls.yml
dsn: sq:///path/to/dbname.db

BigQuery:

# .tbls.yml
dsn: bigquery://project-id/dataset-id?creds=/path/to/google_application_credentials.json
# .tbls.yml
dsn: bq://project-id/dataset-id?creds=/path/to/google_application_credentials.json

To set GOOGLE_APPLICATION_CREDENTIALS environment variable, you can use

  1. export GOOGLE_APPLICATION_CREDENTIALS or export GOOGLE_APPLICATION_CREDENTIALS_JSON
  2. Add query to DSN
    • ?google_application_credentials=/path/to/client_secrets.json
    • ?credentials=/path/to/client_secrets.json
    • ?creds=/path/to/client_secrets.json

Required permissions: bigquery.datasets.get bigquery.tables.get bigquery.tables.list

Also, you can use impersonate service account using environment variables below.

  • GOOGLE_IMPERSONATE_SERVICE_ACCOUNT: Email of service account
  • GOOGLE_IMPERSONATE_SERVICE_ACCOUNT_LIFETIME: You can use impersonate service account within this lifetime. This value must be readable from https://github.com/k1LoW/duration .

Cloud Spanner:

# .tbls.yml
dsn: spanner://project-id/instance-id/dbname?creds=/path/to/google_application_credentials.json

To set GOOGLE_APPLICATION_CREDENTIALS environment variable, you can use

  1. export GOOGLE_APPLICATION_CREDENTIALS or export GOOGLE_APPLICATION_CREDENTIALS_JSON
  2. Add query to DSN
    • ?google_application_credentials=/path/to/client_secrets.json
    • ?credentials=/path/to/client_secrets.json
    • ?creds=/path/to/client_secrets.json

Also, you can use impersonate service account using environment variables below.

  • GOOGLE_IMPERSONATE_SERVICE_ACCOUNT: Email of service account
  • GOOGLE_IMPERSONATE_SERVICE_ACCOUNT_LIFETIME: You can use impersonate service account within this lifetime. This value must be readable from https://github.com/k1LoW/duration .

Amazon Redshift:

# .tbls.yml
dsn: redshift://dbuser:dbpass@hostname:5432/dbname
# .tbls.yml
dsn: rs://dbuser:dbpass@hostname:5432/dbname

Microsoft SQL Server:

# .tbls.yml
dsn: mssql://DbUser:SQLServer-DbPassw0rd@hostname:1433/testdb
# .tbls.yml
dsn: sqlserver://DbUser:SQLServer-DbPassw0rd@hostname:1433/testdb
# .tbls.yml
dsn: ms://DbUser:SQLServer-DbPassw0rd@localhost:1433/testdb

Amazon DynamoDB:

# .tbls.yml
dsn: dynamodb://us-west-2
# .tbls.yml
dsn: dynamo://ap-northeast-1?aws_access_key_id=XXXXXxxxxxxxXXXXXXX&aws_secret_access_key=XXXXXxxxxxxxXXXXXXX

To set AWS credentials, you can use

  1. Use default credential provider chain of AWS SDK for Go
  2. Add query to DSN
    • ?aws_access_key_id=XXXXXxxxxxxxXXXXXXX&aws_secret_access_key=XXXXXxxxxxxxXXXXXXX

Snowflake (Experimental):

---
# .tbls.yml
dsn: snowflake://user:password@myaccount/mydb/myschema

See also: https://pkg.go.dev/github.com/snowflakedb/gosnowflake

MongoDB:

# .tbls.yml
dsn: mongodb://mongoadmin:secret@localhost:27017/test
# .tbls.yml
dsn: mongodb://mongoadmin:secret@localhost:27017/test?sampleSize=20

If a field has multiple types, the multipleFieldType query can be used to list all the types.

# .tbls.yml
dsn: mongodb://mongoadmin:secret@localhost:27017/test?sampleSize=20&multipleFieldType=true

JSON:

The JSON file output by the tbls out -t json command can be read as a datasource.

---
# .tbls.yml
dsn: json://path/to/testdb.json

HTTP:

---
# .tbls.yml
dsn: https://hostname/path/to/testdb.json
---
# .tbls.yml
dsn:
  url: https://hostname/path/to/testdb.json
  headers:
    Authorization: token GITHUB_OAUTH_TOKEN

GitHub:

---
# .tbls.yml
dsn: github://k1LoW/tbls/sample/mysql/schema.json

Document path

tbls doc generates document in the directory specified by docPath:.

# .tbls.yml
# Default is `dbdoc`
docPath: doc/schema

Document format

format: is used to change the document format.

# .tbls.yml
format:
  # Adjust the column width of Markdown format table
  # Default is false
  adjust: true
  # Sort the order of table list and columns
  # Default is false
  sort: false
  # Display sequential numbers in table rows
  # Default is false
  number: false
  # The comments for each table in the Tables section of the index page will display the text up to the first double newline (first paragraph).
  # Default is false
  showOnlyFirstParagraph: true
  # Hide table columns without values
  # Default is false
  hideColumnsWithoutValues: true
  # It can be boolean or array
  # hideColumnsWithoutValues: ["Parents", "Children"]

ER diagram

tbls doc generate ER diagram images at the same time.

# .tbls.yml
er:
  # Skip generation of ER diagram
  # Default is false
  skip: false
  # ER diagram image format (`png`, `jpg`, `svg`, `mermaid`)
  # Default is `svg`
  format: svg
  # Add table/column comment to ER diagram
  # Default is false
  comment: true
  # Hide relation definition from ER diagram
  # Default is false
  hideDef: true
  # Show column settings in ER diagram. If this section is not set, all columns will be displayed (default).
  showColumnTypes:
    # Show related columns
    related: true
    # Show primary key columns
    primary: true
  # Distance between tables that display relations in the ER
  # Default is 1
  distance: 2
  # ER diagram (png/jpg) font (font name, font file, font path or keyword)
  # Default is "" ( system default )
  font: M+

It is also possible to personalize the output by providing your own templates. See the Personalized Templates section below.

Lint

tbls lint work as linter for database.

# .tbls.yml
lint:
  # require table comment
  requireTableComment:
    enabled: true
    # all commented, or all uncommented.
    allOrNothing: false
  # require column comment
  requireColumnComment:
    enabled: true
    # all commented, or all uncommented.
    allOrNothing: true
    # exclude columns from warnings
    exclude:
      - id
      - created_at
      - updated_at
    # exclude tables from warnings
    excludeTables:
      - logs
      - comment_stars
  # require index comment
  requireIndexComment:
    enabled: true
    # all commented, or all uncommented.
    allOrNothing: false
    # exclude indexes from warnings
    exclude:
      - user_id_idx
    # exclude tables from warnings
    excludeTables:
      - logs
      - comment_stars
  # require constraint comment
  requireConstraintComment:
    enabled: true
    # all commented, or all uncommented.
    allOrNothing: false
    # exclude constrains from warnings
    exclude:
      - unique_user_name
    # exclude tables from warnings
    excludeTables:
      - logs
      - comment_stars
  # require trigger comment
  requireTriggerComment:
    enabled: true
    # all commented, or all uncommented.
    allOrNothing: false
    # exclude triggers from warnings
    exclude:
      - update_count
    # exclude tables from warnings
    excludeTables:
      - logs
      - comment_stars
  # require table labels
  requireTableLabels:
    enabled: true
    # all commented, or all uncommented.
    allOrNothing: false
    # exclude tables from warnings
    exclude:
      - logs
  # find a table that has no relation
  unrelatedTable:
    enabled: true
    # all related, or all unrelated.
    allOrNothing: true
    # exclude tables from warnings
    exclude:
      - logs
  # check max column count
  columnCount:
    enabled: true
    max: 10
    # exclude tables from warnings
    exclude:
      - user_options
  # require columns
  requireColumns:
    enabled: true
    columns:
      -
        name: created
      -
        name: updated
        exclude:
          - logs
          - CamelizeTable
  # check duplicate relations
  duplicateRelations:
    enabled: true
  # check if the foreign key columns have an index
  requireForeignKeyIndex:
    enabled: true
    exclude:
      - comments.user_id
  # checks if labels are in BigQuery style ( https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements )
  labelStyleBigQuery:
    enabled: true
    exclude:
      - schema_migrations
  # checks if tables are included in at least one viewpoint
  requireViewpoints: 
    enabled: true
    exclude:
      - schema_migrations

Filter tables

filter tables

include: and exclude: are used to filter target tables from tbls *.

# .tbls.yml
include:
  - some_prefix_*
exclude:
  - some_prefix_logs
  - CamelizeTable

lintExclude: is used to exclude tables from tbls lint.

# .tbls.yml
lintExclude:
  - CamelizeTable

Filter logic

  1. Add tables from include
  2. Remove tables from exclude
    • Check for include/exclude overlaps
    • If include is more specific than exclude (i.e. schema.MyTable > schema.* or schema.MyT* > schema.* ), include the table(s). If include is equally or less specific than exclude, exclude wins.
  3. Result

Comments

comments: is used to add table/column comment to database document without ALTER TABLE.

For example, you can add comment about VIEW TABLE or SQLite tables/columns.

# .tbls.yml
comments:
  -
    table: users
    # table comment
    tableComment: Users table
    # column comments
    columnComments:
      email: Email address as login id. ex. [email protected]
    # labels for tables
    labels:
      - privary data
      - backup:true
  -
    table: post_comments
    tableComment: post and comments View table
    columnComments:
      id: comments.id
      title: posts.title
      post_user: posts.users.username
      comment_user: comments.users.username
      created: comments.created
      updated: comments.updated
  -
    table: posts
    # index comments
    indexComments:
      posts_user_id_idx: user.id index
    # constraints comments
    constraintComments:
      posts_id_pk: PRIMARY KEY
    # triggers comments
    triggerComments:
      update_posts_updated: Update updated when posts update

Relations

relations: is used to add or override table relation to database document without FOREIGN KEY.

You can create ER diagrams with relations without having foreign key constraints.

relations:
  -
    table: logs
    columns:
      - user_id
    parentTable: users
    parentColumns:
      - id
    # Relation definition
    # Default is `Additional Relation`
    def: logs->users
  -
    table: logs
    columns:
      - post_id
    parentTable: posts
    parentColumns:
      - id
  -
    table: logs
    columns:
      - comment_id
    parentTable: comments
    parentColumns:
      - id
  -
    table: logs
    columns:
      - comment_star_id
    parentTable: comment_stars
    parentColumns:
      - id

img

Override relations

If you want to override an existing relation, set the override: to true.

relations:
  -
    table: posts
    columns:
      - user_id
    cardinality: zero or one
    parentTable: users
    parentColumns:
      - id
    parentCardinality: one or more
    override: true
    def: posts->users

Automatically detect relations

detectVirtualRelations: if enabled, automatically detect relations from table and column names.

detectVirtualRelations:
  enabled: true
  strategy: default

default strategy:

detectVirtualRelations:
  enabled: true
  strategy: default
  • some_table.user_id -> users.id
  • some_table.post_id -> posts.id

singularTableName strategy:

detectVirtualRelations:
  enabled: true
  strategy: singularTableName
  • some_table.user_id -> user.id
  • some_table.post_id -> post.id

Dictionary

dict: is used to replace title/table header of database document

# .tbls.yml
---
dict:
  Tables: テーブル一覧
  Description: 概要
  Columns: カラム一覧
  Indexes: INDEX一覧
  Constraints: 制約一覧
  Triggers: トリガー
  Relations: ER図
  Name: 名前
  Comment: コメント
  Type: タイプ
  Default: デフォルト値
  Children: 子テーブル
  Parents: 親テーブル
  Definition: 定義
  Table Definition: テーブル定義

Personalized Templates

It is possible to provide your own templates to personalize the documentation generated by tbls by adding a templates: section to your configuration. For example:

templates:
  dot:
    schema: 'templates/schema.dot.tmpl'
    table: 'templates/table.dot.tmpl'
  puml:
    schema: 'templates/schema.puml.tmpl'
    table: 'templates/table.puml.tmpl'
  md:
    index: 'templates/index.md.tmpl'
    table: 'templates/table.md.tmpl'

A good starting point to design your own template is to modify a copy the default ones for Dot, PlantUML and markdown.

Required Version

The requiredVersion setting defines a version constraint string. This defines which version of tbls can be used in the configuration.

requiredVersion: '>= 1.42, < 2'

Expand environment variables

All configuration values can be set by expanding the environment variables.

# .tbls.yml
dsn: my://${MYSQL_USER}:${MYSQL_PASSWORD}@hostname:3306/${MYSQL_DATABASE}

Viewpoints

Viewpoints of your database schema based on concerns of your domain and add description to them. You can also define groups of tables within viewpoints.

# .tbls.yml

viewpoints:
  -
    name: comments on post
    desc: Users can comment on each post multiple times and put a star on each comment.
    tables:
      - users
      - posts
      - comments
      - comment_stars
      - post_comments
      - post_comment_stars
    groups:
      -
        name: Comments
        desc: Tables about comments
        tables:
          - posts
          - comments
          - post_comments
      -
        name: Stars
        desc: Tables about stars
        tables:
          - comment_stars
          - post_comment_stars

Output formats

tbls out output in various formats.

Markdown:

$ tbls out -t md -o schema.md

DOT:

$ tbls out -t dot -o schema.dot

PlantUML:

$ tbls out -t plantuml -o schema.puml

Mermaid:

$ tbls out -t mermaid -o schema.mmd

Image (svg, png, jpg):

$ tbls out -t svg --table users --distance 2 -o users.svg

JSON:

$ tbls out -t json -o schema.json

Tips: tbls doc can load schema.json as DSN.

$ tbls doc json:///path/to/schema.json

YAML:

$ tbls out -t yaml -o schema.yaml

Excel:

$ tbls out -t xlsx -o schema.xlsx

.tbls.yml:

$ tbls out -t config -o .tbls.new.yml

Command arguments

tbls subcommands ( doc,diff, etc) accepts arguments and options

$ tbls doc my://root:mypass@localhost:3306/testdb doc/schema

You can check available arguments and options using tbls help [COMMAND].

$ tbls help doc
'tbls doc' analyzes a database and generate document in GitHub Friendly Markdown format.

Usage:
  tbls doc [DSN] [DOC_PATH] [flags]

Flags:
  -j, --adjust-table       adjust column width of table
  -b, --base-url string    base url for links
  -c, --config string      config file path
  -t, --er-format string   ER diagrams output format (png, svg, jpg, mermaid). default: svg
  -f, --force              force
  -h, --help               help for doc
      --rm-dist            remove files in docPath before generating documents
      --sort               sort
      --when string        command execute condition
      --without-er         no generate ER diagrams

Output Schema data

tbls doc also output schema data ( schema.json ) to same directory as the generated schema document.

To disable output of schema data, set disableOutputSchema: to true in .tbls.yml file.

Environment variables

tbls accepts environment variables TBLS_DSN and TBLS_DOC_PATH

$ env TBLS_DSN=my://root:mypass@localhost:3306/testdb TBLS_DOC_PATH=doc/schema tbls doc

tbls's People

Contributors

attsun1031 avatar dependabot[bot] avatar folago avatar github-actions[bot] avatar k1low avatar kakisoft avatar kanata2 avatar kojirock5260 avatar kymmt90 avatar linyows avatar lytchev avatar majimaccho avatar mjpieters avatar mmizutani avatar mrtc0 avatar muno92 avatar navaneeth-spotnana avatar ogumaru avatar oohira avatar paulkabira avatar peccu avatar suzuki avatar tomi avatar toshi0607 avatar wubin1989 avatar yasu89 avatar yauhenpylaurea avatar yoskhdia avatar ypyl avatar yu-ichiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tbls's Issues

pq: SSL is not enabled on the server

What happened

error pq: SSL is not enabled on the server

What you expected to happed

connect

What stacktrace or error message from tbls did you see?

pq: SSL is not enabled on the server

Anything else we need to know?

how to disable ssl in connection ?

Environment

  • tbls version
  • Database version
  • Stacktrace or error message from tbls ( If you can, set DEBUG=1)
  • Config ( .tbls.yml )

Layout collapses when comment contains line breaks

テーブルのコメントに改行が含まれている場合、個々の md は問題ないですが README.md の表が崩れるようです。 markdown で出力するコメント部分が <br> 対応されると良いのかなと思いました。

  • sql
COMMENT ON TABLE schemaX.test_table IS 'title xxx.

Description xxx.';
  • schemaX.test_table.md
# schemaX.test_table

## Description

title xxx.

Description xxx.
  • README.md
## Tables

| Name | Columns | Comment | Type |
| ---- | ------- | ------- | ---- |
| [schemaX.test_table](schemaX.test_table.md) | 1 | title xxx.

Description xxx. | BASE TABLE |

not found column 'res_company_ldap."user"'

What happened

while running tbls doc $DSN $DIR

What you expected to happed

generate the docs

What stacktrace or error message from tbls did you see?

err: not found column 'res_company_ldap."user"'

Anything else we need to know?

the column already exists, the DB is an odoo DB and working fine

Environment

  • tbls version latest
  • Database version PG 12.x
  • Stacktrace or error message from tbls ( If you can, set DEBUG=1)
    not found column 'res_company_ldap."user"' github.com/k1LoW/tbls/schema.(*Table).FindColumnByName /Users/k1low/src/github.com/k1LoW/tbls/schema/schema.go:174 github.com/k1LoW/tbls/drivers/postgres.(*Postgres).Analyze /Users/k1low/src/github.com/k1LoW/tbls/drivers/postgres/postgres.go:304 github.com/k1LoW/tbls/datasource.Analyze /Users/k1low/src/github.com/k1LoW/tbls/datasource/datasource.go:83 github.com/k1LoW/tbls/cmd.glob..func4 /Users/k1low/src/github.com/k1LoW/tbls/cmd/doc.go:72 github.com/spf13/cobra.(*Command).execute /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:830 github.com/spf13/cobra.(*Command).ExecuteC /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:914 github.com/spf13/cobra.(*Command).Execute /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:864 github.com/k1LoW/tbls/cmd.Execute /Users/k1low/src/github.com/k1LoW/tbls/cmd/root.go:59 main.main /Users/k1low/src/github.com/k1LoW/tbls/main.go:33 runtime.main /Users/k1low/.anyenv/envs/goenv/versions/1.13.6/src/runtime/proc.go:203 runtime.goexit /Users/k1low/.anyenv/envs/goenv/versions/1.13.6/src/runtime/asm_amd64.s:1357
  • Config ( .tbls.yml )

Personalized templates

The embedded templates are great to get you started with tbls doc but depending on the DB or the project it might fall short in some aspects.

It would be very helpful to be possible to specify a personalized template at execution time and inside the tbls.yml config file.

E.g.:

# tbls.yml
er:
  format: svg
  comment: true
  distance: 2
  font: M+
  template: "path/to/dot/template"
$tbls out -t plantuml -template "path/to/puml/template" -o schema.puml

ER diagramformat not work

Version: v1.16.0
System: Ubuntu 18.04

add ER config into .tbls.yml, but it still generates png file ??

er:
  # Skip generation of ER diagram
  # Default is false
  skip: false
  # ER diagram format
  # Default is `png`
  format: svg

ps: tbls is a great tool !!!

doc command exits with error `malformed version`

What happened

When executing tbls doc on a PostgreSQL database the program stops and outputs error malformed version: 12.3,

What you expected to happed

doc program should complete and show output filename

Anything else we need to know?

The PostgreSQL version that tbls obtains has the comma appended for some reason. I'm pretty sure the error might be with the go database/sql package, but in any case this might be resolved by slicing off the comma from the string returned at https://github.com/k1LoW/tbls/blob/master/drivers/postgres/postgres.go#L348.

Environment

  • tbls version: 1.48.0
  • Database version: PostgreSQL 12.3
  • Shell: powershell

How to deploy with gitbook?

How to read documents use gitbook?I want to deploy the documents on my own server use gitbook.
And If I have many databases. How could I generate a document like this:
on the left is database memu. right is tables in the selected database?

Below is what I get now,and it's not working with gitbook.
image

Thanks!

Add a command-line switch to either tbls out or tbls lint to ignore virtual information

What happened

I'm dealing with slow connection to a remote database; running tbls lint or tbls doc over an ssh tunnel is painfully slow. However, running tbls on the remote server and then outputting to JSON back over the SSH connection is way better:

alias rtbls="scp .tbls.yml server:/tmp && ssh server 'cd /tmp && tbls out -t json' > /tmp/tbls.json"
rtbls && tbls lint json:///tmp/tbls.json

However, I'm defining additional relations: entries in my configuration:

# additional implied relationships
relations:
  - table: foo
    columns:
      - bar_type
    parentTable: bar_types
    parentColumns:
      - bar_type_name
    def: bar_type validation
   - table: bar_types
     columns:
       - spamparams
     parentTable: spam_definitions
     parentColumns:
       - name
     def: validation of `spam?ham=...` parameters

lint:
  duplicateRelations:
    enabled: true

These are reflected in the exported JSON file in the "relations" structure with "virtual": trueset.

When you then run lint with the same configuration file and the JSON file as the DSN, warnings are generated for duplicate relationships:

public.foo: duplicate relations. [public.foo -> public.bar_types]
public.bar_types: duplicate relations. [public.foo -> public.spam_definitions]

When generating ER diagrams, two dotted lines and labels are drawn, per virtual relationship.

What you expected to happed

Virtual relationships present in the configuration file and in a JSON dump should be merged, and so not generate a warning or a duplicate line.

Anything else we need to know?

Workaround is to remove the "virtual": true relationships first; using jq as a filter:

"... && ssh server '...' | jq 'del(.relations[] | select(.virtual == true))' > /tmp/tbls.json"

This problem may also apply to comments defined in the configuration. I did not test this.

Environment

  • tbls version: 1.35.0
  • Database version: Postgresql 10
  • OS: Ubuntu 18.04 (remote server) & Mac OS X 10.13 (local machine driving the ssh connection)
  • Shell: bash

tbls doesn't manage the md files after creation

What happened

tbls doesn't manage the md files after creation

What you expected to happed

A new md file should be created after creation a corresponding table in the database and then running tbls doc

What stacktrace or error message from tbls did you see?

output files already exists

Anything else we need to know?

Am I right that tbls doc should update the md files indocPath after running? So if we create/ delete a new object in the database, the related md file should appear/desappear?
As I see, now it creates the files in a proper way only the first time. Next, even though the table was deleted from the database, the file remains unchanged. And similary, if I create a new table, I could see the changes only in tbls diff When I run tbls doc again to commit them, the local files aren't changed and I don't see any new files related to the created table.

Environment

  • tbls version 1.24.1
  • Database version Postgres 11.5
  • Stacktrace or error message from tbls ( If you can, set DEBUG=1)
    output files already exists
  • Config ( .tbls.yml )

Better handling of table descriptions on README vs. detail page.

Currently, the README.md file lists all tables with their full table comment.

I'm putting a lot of info in some of my table descriptions, including SQL code blocks. These render rather badly in the comment column of the central Tables table, which treats markdown just a little different.

Perhaps the Tables table should only use the first paragraph of each table description.

E.g. the description

Foo widgets

Tracks Foo widget metadata as the frobnar twiddles with the status and inserts more
information.

Because there may be redundant, duplicated rows with different timestamps in this table,
please use a window query to consolidate adjacent rows:

-- Some elaborate sample query

would only take the text up to the first double newline and so the comment in the Tables comments column becomes:

Foo widgets

and only the detail page shows the remainder.

AWS Redshift has no trigger

https://docs.aws.amazon.com/ja_jp/redshift/latest/dg/c_unsupported-postgresql-features.html
↑公式ドキュメントに記載の通り、AWS Redshiftにはトリガーがありません。
そのため、直近のバージョンのtblsを実行するとpanicが発生するようです。

$ tbls version
dev
$ DEBUG=1 tbls doc --force --er-format svg
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x41e5af6]

goroutine 1 [running]:
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/opt/go/libexec/src/database/sql/sql.go:2955 +0x66
database/sql.(*Rows).Close(0x0, 0xc0002d9880, 0x2)
        /usr/local/opt/go/libexec/src/database/sql/sql.go:2951 +0x33
github.com/k1LoW/tbls/drivers/postgres.(*Postgres).Analyze(0x49d6558, 0xc0000e6180, 0xc0000a31d0, 0x468ee00, 0xc00035bc00)
        /Users/watarukura/src/github.com/k1LoW/tbls/drivers/postgres/postgres.go:158 +0x233f
github.com/k1LoW/tbls/datasource.Analyze(0xc0000b6360, 0x5c, 0x0, 0x0, 0x0)
        /Users/watarukura/src/github.com/k1LoW/tbls/datasource/datasource.go:62 +0x29d
github.com/k1LoW/tbls/cmd.glob..func2(0x49ad220, 0xc000089c20, 0x0, 0x3)
        /Users/watarukura/src/github.com/k1LoW/tbls/cmd/doc.go:72 +0x110
github.com/spf13/cobra.(*Command).execute(0x49ad220, 0xc000089bf0, 0x3, 0x3, 0x49ad220, 0xc000089bf0)
        /Users/watarukura/src/github.com/spf13/cobra/command.go:766 +0x2cc
github.com/spf13/cobra.(*Command).ExecuteC(0x49ad940, 0xc0000f3f88, 0x4007b30, 0xc00007a058)
        /Users/watarukura/src/github.com/spf13/cobra/command.go:850 +0x2f8
github.com/spf13/cobra.(*Command).Execute(0x49ad940, 0x0, 0x0)
        /Users/watarukura/src/github.com/spf13/cobra/command.go:800 +0x2b
github.com/k1LoW/tbls/cmd.Execute()
        /Users/watarukura/src/github.com/k1LoW/tbls/cmd/root.go:59 +0x2d
main.main()
        /Users/watarukura/src/github.com/K1LoW/tbls/main.go:32 +0x20

/Users/watarukura/src/github.com/k1LoW/tbls/drivers/postgres/postgres.go:158

		// constraint
		constraintRows, err := db.Query(`
SELECT
  pc.conname AS name,
  (CASE WHEN contype='t' THEN pg_get_triggerdef((SELECT oid FROM pg_trigger WHERE tgconstraint = pc.oid LIMIT 1))
        ELSE pg_get_constraintdef(pc.oid)
   END) AS def,
  contype AS type
FROM pg_constraint AS pc
LEFT JOIN pg_stat_user_tables AS ps ON ps.relid = pc.conrelid
WHERE ps.relname = $1
AND ps.schemaname = $2
ORDER BY pc.conrelid, pc.conindid, pc.conname`, tableName, tableSchema)
		defer constraintRows.Close()
		if err != nil {
			return errors.WithStack(err)
		}

SELECT oid FROM pg_trigger WHERE tgconstraint = pc.oid LIMIT 1;

[42703][500310] [Amazon](500310) Invalid operation: column "tgconstraint" does not exist in pg_trigger; java.lang.RuntimeException: com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation: column "tgconstraint" does not exist in pg_trigger;

sql: Scan error on column index 1: unsupported Scan, storing driver.Value type <nil> into type *string

mysqlのドキュメントを生成しようとするとエラーが出てしまいます。
対処方法などありましたら、教えていただけないでしょうか。

# cat /etc/redhat-release 
CentOS release 6.6 (Final)
# mysql --version
mysql  Ver 14.14 Distrib 5.6.23, for Linux (x86_64) using  EditLine wrapper
# go version
go version go1.9.6 linux/amd64
# tbls version
0.9.3
# tbls doc mysql://db_user:password@localhost:3306/cs_production ./dbdoc
sql: Scan error on column index 1: unsupported Scan, storing driver.Value type <nil> into type *string

Excluding tables from the ERD

Feature request:
We use the knex library for migrations.
We'd like to be able to add table names to the tbls config to be ignored from the doc's and diagrams.
They are two tables knex_migrations and knex_migrations_lock.
They seem to generated slightly different schemas everytime we add a new migration version, which is adding unnecessary overhead to our PRs.
It would be nice to be able to exclude these tables, by name, in the tbls config file.

custom fileds.

Feature Request. Hi, could you add a feature, that allows adding a comment to the not existing field in the table? For example, there is a service (f.e. superset) usage that extends the table with some custom fields or metrics, and I want them to be documented. Thanks in advance.

PostgreSQL+PostGIS: not found table 'public.topology' (non-default schema issue)

What happened

$ tbls doc
not found table 'public.topology'

Seems related to #28 and #153

You can reproduce with docker image mdillon/postgis:9.5

What you expected to happed

I expected a generated documentation.

What stacktrace or error message from tbls did you see?

not found table 'public.topology'

Anything else we need to know?

PostGIS is enabled and manages the topology schema. This is the output of \dt:

foobar> \dt
+----------+-------------------+--------+--------+
| Schema   | Name              | Type   | Owner  |
|----------+-------------------+--------+--------|
| public   | migration         | table  | dbuser |
| public   | spatial_ref_sys   | table  | dbuser |
| public   | subscriber        | table  | dbuser |
| public   | user              | table  | dbuser |
| public   | user_role         | table  | dbuser |
| public   | users_homes       | table  | dbuser |
| public   | users_roles       | table  | dbuser |
| public   | users_tokens      | table  | dbuser |
| topology | layer             | table  | dbuser |
| topology | topology          | table  | dbuser |
+----------+-------------------+--------+--------+

Environment

  • tbls version: 1.28.2
  • PostgreSQL v9.5.16
  • PostGIS v2.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
  • .tbls.yml:
---

name: foobar
dsn: postgres://dbuser:dbpass@localhost:5432/foobar?sslmode=disable
docPath: docs/schema

Stacktrace

$ DEBUG=1 tbls doc
not found table 'public.topology'
github.com/k1LoW/tbls/schema.(*Schema).FindTableByName
        /Users/k1low/src/github.com/k1LoW/tbls/schema/schema.go:110
github.com/k1LoW/tbls/drivers/postgres.(*Postgres).Analyze
        /Users/k1low/src/github.com/k1LoW/tbls/drivers/postgres/postgres.go:337
github.com/k1LoW/tbls/datasource.Analyze
        /Users/k1low/src/github.com/k1LoW/tbls/datasource/datasource.go:85
github.com/k1LoW/tbls/cmd.glob..func4
        /Users/k1low/src/github.com/k1LoW/tbls/cmd/doc.go:69
github.com/spf13/cobra.(*Command).execute
        /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:844
github.com/spf13/cobra.(*Command).ExecuteC
        /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:945
github.com/spf13/cobra.(*Command).Execute
        /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:885
github.com/k1LoW/tbls/cmd.Execute
        /Users/k1low/src/github.com/k1LoW/tbls/cmd/root.go:59
main.main
        /Users/k1low/src/github.com/k1LoW/tbls/main.go:33
runtime.main
        /Users/k1low/.anyenv/envs/goenv/versions/1.13.6/src/runtime/proc.go:203
runtime.goexit
        /Users/k1low/.anyenv/envs/goenv/versions/1.13.6/src/runtime/asm_amd64.s:1357

add comment

comments:
    -
        table: a
        comment: xxxxxxxxxxxxxxxxxxxxx
        columnComments:
            order_no: xxxxxxxx
            detail_no: xxxxxxxxx
            amazon_item_id: xxxxxxxx
            divided_delivery_charge: xxxxxxxxx
            divided_cod_fee: xxxxxxxxx
            registration_date: xxxxxxxxx
            registration_id: xxxxxxxxx
            update_date: xxxxxxxxx
            update_id: xxxxxxxxx
    -
        table: b
        comment: xxxxxxxxx
        columnComments:
            order_no: xxxxxxxxx
            store_code: xxxxxxxxx
            course: xxxxxxxxx
            registration_date: xxxxxxxxx
            registration_id: xxxxxxxxx
            update_date: xxxxxxxxx
            update_id: xxxxxxxxx

以上のようにymlファイルを記述しましたがコメントが追加されません
しかしテーブルを1つだけ指定した場合は追加されます
2個目の-(ハイフン)を無くしても追加されませんでした

Invalid links can be generated when not selecting all the tables

What happened

Suppose you have tables A, B, and C.
both A and B point to table C.
If we specify to generate docs only for tables A and B, the link in theese pointing to non existing table C documentation will be generated.

What you expected to happed

Should not create a link to avoid user errors when browsing generated output.
A switch not to generate links at all can do the job as well.

Environment

  • tbls version : 1.37.0
  • postgreSQL database
  • Windows 10
  • config:
comments:
- table: A
  tableComment: table A
- table: B
  tableComment: table B
desc: 'My description'
docPath: doc/schema
dsn: postgres://user:pass@localhost:5432/dbname?sslmode=disable
er:
  skip: true
include:
- A
- B
name: Db overview

MSSQL: Encountered "Not found table" error when using custom database schema

Thanks for this very interesting work/project. It checks many of the right boxes for my ER-Diagram needs (including CI pipeline and markdown generation features). Further, it works as expected for conventional databases that use the default "dbo" schema for tables.

What happened

Was able to successfully connect to a Microsoft SQL server, but the first table in the database failed with the error:
"Not found table '{TableNameHere}'"

What you expected to happed

I expected that the database documentation would be generated.

Anything else we need to know?

The missing table makes use of a custom database namespace other than "dbo" (e.g. "appname_dbo"). It seems reasonable that I would need to indicate a database schema configuration when custom, but I don't know if/how to do that. The source code seems to mention "dbo" by name, but it is unclear to me if I can change the defaultSchemaName via the tbls.yml file.

Environment

  • tbls version
    1.43.1
  • Database version
    MSSQL 2016
  • OS ( Ubuntu bionic, macOS Calalina, WSL2, etc )
    Windows x64
  • Shell ( bash, zsh, poworshell, etc )
    powershell
  • Stacktrace or error message from tbls ( If you can, set DEBUG=1)
github.com/k1LoW/tbls/schema.(*Schema).FindTableByName

         /Users/k1low/src/github.com/k1LoW/tbls/schema/schema.go:139

 github.com/k1LoW/tbls/drivers/mssql.(*Mssql).Analyze

         /Users/k1low/src/github.com/k1LoW/tbls/drivers/mssql/mssql.go:423

 github.com/k1LoW/tbls/datasource.Analyze

         /Users/k1low/src/github.com/k1LoW/tbls/datasource/datasource.go:111

 github.com/k1LoW/tbls/cmd.glob..func5

         /Users/k1low/src/github.com/k1LoW/tbls/cmd/doc.go:73

 github.com/spf13/cobra.(*Command).execute

         /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:846

 github.com/spf13/cobra.(*Command).ExecuteC

         /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:950

 github.com/spf13/cobra.(*Command).Execute

         /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:887

 github.com/k1LoW/tbls/cmd.Execute

         /Users/k1low/src/github.com/k1LoW/tbls/cmd/root.go:184

 main.main

         /Users/k1low/src/github.com/k1LoW/tbls/main.go:33

 runtime.main

         /usr/local/Cellar/go/1.13.7/libexec/src/runtime/proc.go:203

 runtime.goexit

         /usr/local/Cellar/go/1.13.7/libexec/src/runtime/asm_amd64.s:1357

  • Config ( .tbls.yml )
dbn: mssql://un:pwd@hostname:port/dbname

Won't work with MariaDB

What happened

Docs won't generate

What you expected to happed

Docs should be generated.

What stacktrace or error message from tbls did you see?

DEBUG=1 tbls doc
malformed version: 10.4.10-MariaDB-1:10.4.10+maria~bionic-log:
    github.com/aquasecurity/go-version/pkg/version.Parse
        /Users/k1low/go/pkg/mod/github.com/aquasecurity/[email protected]/pkg/version/version.go:44

Anything else we need to know?

Looks like the reason is that that library (github.com/aquasecurity/go-version) has been updated.

Environment

  • tbls version: 1.47.0
  • Database version: MariaDB 10.4.10
  • OS: Ubuntu bionic
  • Shell: zsh

Support comments on indexes

Postgres supports COMMENT ON on just about anything, including INDEX.

Please include any comments on indexes in the Indexes table.

Redshift: separate quoting around schema and table name breaks reference parser

What happened

I'm testing tbls against a schema with a reserved name (time) as well as with a hyphenated table name:

CREATE SCHEMA time;

CREATE TABLE time.bar (
  id int IDENTITY(1, 1) PRIMARY KEY
);
CREATE TABLE time."hyphenated-table" (
  id int IDENTITY(1, 1) PRIMARY KEY
);
CREATE TABLE time.referencing (
  id int IDENTITY(1, 1) PRIMARY KEY,
  bar_id int NOT NULL,
  ht_id int NOT NULL,
  CONSTRAINT referencing_bar_id FOREIGN KEY(bar_id) REFERENCES time.bar(id),
  CONSTRAINT referencing_ht_id FOREIGN KEY(ht_id) REFERENCES time."hyphenated-table"(id)
);

While foreign keys are not enforced by Redshift, the query optimiser does use them so it makes sense to put these in.

The above schema breaks tbls' relations parsing, because it doesn't account for the quoting that AWS redshift puts on both the schema and on the second table, when querying constraints:

select pg_get_constraintdef(oid) as def from pg_constraint
where conrelid = 'time.referencing'::regclass and contype = 'f';
                def
-----------------------------------------------------
 FOREIGN KEY (bar_id) REFERENCES "time".bar(id)
 FOREIGN KEY (ht_id) REFERENCES "time"."hyphenated-table"(id)
(2 rows)

Note the "time" quoting in the response, and the separate quotes around hyphenated-table.

This causes tbls to be unhappy, because the postgres driver only strips quotes from the start and end of the string

With DEBUG=1 we thus see:

not found table 'time".bar'
github.com/k1LoW/tbls/schema.(*Schema).FindTableByName
	/Users/k1low/src/github.com/k1LoW/tbls/schema/schema.go:136
github.com/k1LoW/tbls/drivers/postgres.(*Postgres).Analyze
	/Users/k1low/src/github.com/k1LoW/tbls/drivers/postgres/postgres.go:359
github.com/k1LoW/tbls/datasource.Analyze
	/Users/k1low/src/github.com/k1LoW/tbls/datasource/datasource.go:93
github.com/k1LoW/tbls/cmd.glob..func6
	/Users/k1low/src/github.com/k1LoW/tbls/cmd/out.go:80
github.com/spf13/cobra.(*Command).execute
	/Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:846
github.com/spf13/cobra.(*Command).ExecuteC
	/Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:950
github.com/spf13/cobra.(*Command).Execute
	/Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:887
github.com/k1LoW/tbls/cmd.Execute
	/Users/k1low/src/github.com/k1LoW/tbls/cmd/root.go:153
main.main
	/Users/k1low/src/github.com/k1LoW/tbls/main.go:33
runtime.main
	/Users/k1low/.anyenv/envs/goenv/versions/1.13.10/src/runtime/proc.go:203
runtime.goexit
	/Users/k1low/.anyenv/envs/goenv/versions/1.13.10/src/runtime/asm_amd64.s:1357

Perhaps a more sophisticated quote removal routine is needed?

Environment

  • tbls version: 1.35.0
  • Database version: redshift

Support MSSQL description

Previous Title:

[Question] Which property is read for MSSQL server comments?

First of all, great tool.

I am using this tool to document my MSSQL server and would like to know which property is used to generate the comment data. I have tried adding the widely popular MS_Description(set from SMSS description) property to tables and columns but the generated output contains empty cells for Comments column and Description header under table.

I see no options in configuration for specifying the property. Am I doing something wrong?
Any help is appreciated.

panic: runtime error: invalid memory address or nil pointer dereference

What happened

after I tried to use tbls doc with postgre, the error occurred.
截屏2020-08-11 23 45 11

What you expected to happed

get this fixed.

What stacktrace or error message from tbls did you see?

here it is:

tbls doc
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x41b8fb2]

goroutine 1 [running]:
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/Users/k1low/.anyenv/envs/goenv/versions/1.13.10/src/database/sql/sql.go:3063 +0x72
database/sql.(*Rows).Close(0x0, 0x5109c4c, 0x3d0)
/Users/k1low/.anyenv/envs/goenv/versions/1.13.10/src/database/sql/sql.go:3059 +0x33
github.com/k1LoW/tbls/drivers/postgres.(*Postgres).Analyze(0xc00039da80, 0xc000377570, 0x5399d20, 0xc000449ee0)
/Users/k1low/src/github.com/k1LoW/tbls/drivers/postgres/postgres.go:141 +0x28bb
github.com/k1LoW/tbls/datasource.Analyze(0xc000036640, 0x49, 0x0, 0x0, 0x0, 0x0)
/Users/k1low/src/github.com/k1LoW/tbls/datasource/datasource.go:111 +0x80b
github.com/k1LoW/tbls/cmd.glob..func5(0x5cfd1e0, 0x5d7c5a8, 0x0, 0x0)
/Users/k1low/src/github.com/k1LoW/tbls/cmd/doc.go:73 +0x1b0
github.com/spf13/cobra.(*Command).execute(0x5cfd1e0, 0x5d7c5a8, 0x0, 0x0, 0x5cfd1e0, 0x5d7c5a8)
/Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:846 +0x2aa
github.com/spf13/cobra.(*Command).ExecuteC(0x5cfd9c0, 0x4, 0x5d7c5a8, 0x0)
/Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
/Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:887
github.com/k1LoW/tbls/cmd.Execute()
/Users/k1low/src/github.com/k1LoW/tbls/cmd/root.go:184 +0x86
main.main()
/Users/k1low/src/github.com/k1LoW/tbls/main.go:33 +0x20

Anything else we need to know?

I get the same error when using other postgresql databases.

Environment

  • tbls version
    1.43.0

  • Database version
    psql (PostgreSQL) 9.2.24

  • OS
    macOS Calalina

  • Shell
    zsh

  • Stacktrace or error message from tbls ( If you can, set DEBUG=1)
    DEBUG=1 tbls doc
    and the same error message.

  • Config ( .tbls.yml )
    dsn: postgres://user:pw@host:5432/db?sslmode=disable

Segfault when trying to document Redshift database

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x41f7cf6]

goroutine 1 [running]:
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
        /Users/k1low/.anyenv/envs/goenv/versions/1.12.5/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0x48c2a0c, 0x172)
        /Users/k1low/.anyenv/envs/goenv/versions/1.12.5/src/database/sql/sql.go:2972 +0x33
github.com/k1LoW/tbls/drivers/postgres.(*Postgres).Analyze(0xc0003397c0, 0xc0000dd4f0, 0x498d880, 0xc0003b6f40)
        /Users/k1low/src/github.com/k1LoW/tbls/drivers/postgres/postgres.go:131 +0x2f8a
github.com/k1LoW/tbls/datasource.Analyze(0x7ffeefbfe421, 0xa0, 0x0, 0x0, 0x0)
        /Users/k1low/src/github.com/k1LoW/tbls/datasource/datasource.go:74 +0x683
github.com/k1LoW/tbls/cmd.glob..func2(0x4e5dbc0, 0xc0001f7460, 0x1, 0x1)
        /Users/k1low/src/github.com/k1LoW/tbls/cmd/doc.go:72 +0x111
github.com/spf13/cobra.(*Command).execute(0x4e5dbc0, 0xc0001f7430, 0x1, 0x1, 0x4e5dbc0, 0xc0001f7430)
        /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:766 +0x2ae
github.com/spf13/cobra.(*Command).ExecuteC(0x4e5d4a0, 0x0, 0x0, 0x45eabea)
        /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:850 +0x2fc
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:800
github.com/k1LoW/tbls/cmd.Execute()
        /Users/k1low/src/github.com/k1LoW/tbls/cmd/root.go:59 +0x2e
main.main()
        /Users/k1low/src/github.com/k1LoW/tbls/main.go:32 +0x20
$ tbls version
1.15.1
$ go version
go version go1.12.5 darwin/amd64

Please let me know if there's any other information I can provide to help debugging!

show public objects explicitly?

Hi @k1LoW,

It's a followup of #158
the tbls lint returns the full object name (schema_name.table_name[.column_name]) for the objects except the public schema. It just omits the public word in the output.
That's why it's impossible to filter the public objects out just using

Exclude:
 - public.*

I just wonder, is it difficult to add this one into code?
thanks in advance.

Postgres: Support Materialized Views

In Postgres, a Materialized View is basically a cached copy of a query, and has a lot in common with views and tables. They are treated just like tables when querying, and just like views in that they have an underlying query that produced the data.

However, they are not showing up in the tbls documentation, because they are neither a view, nor a table, and the current information schema query doesn't include materialized views anyway (they are listed in the pg_catalog.pg_class table but not in information_schema.tables).

Current materialized views can be listed with the pg_catalog.pg_matviews view. The following version of the tableRows query adds in materialized views:

SELECT DISTINCT cls.oid AS oid, cls.relname AS table_name, tbl.table_type AS table_type, tbl.table_schema AS table_schema
FROM pg_catalog.pg_class cls
INNER JOIN pg_namespace ns ON cls.relnamespace = ns.oid
INNER JOIN (SELECT table_name, table_type, table_schema
FROM information_schema.tables
WHERE table_schema != 'pg_catalog' AND table_schema != 'information_schema'
AND table_catalog = $1
UNION SELECT matviewname as table_name, 'MATERIALIZED VIEW' as table_type, schemaname as table_schema
FROM pg_catalog.pg_matviews
WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema'
) tbl ON cls.relname = tbl.table_name AND ns.nspname = tbl.table_schema
ORDER BY oid;

If we then update the view definition handling to use the pg_catalog.pg_get_viewdef() function (which works for both views and materialized views) the code can also handle MATERIALIZED VIEWs. Note: pg_get_viewdef() takes an OID, but currently the OID is stored as a string, this should really be a uint64!

This is a rough sketch of how this could work:

		// (materialized) view definition
		if tableType == "VIEW" || tableType == "MATERIALIZED VIEW" {
			viewDefRows, err := p.db.Query(`SELECT pg_catalog.pg_get_viewdef($1);`, tableOid)
			defer viewDefRows.Close()
			if err != nil {
				return errors.WithStack(err)
			}
			for viewDefRows.Next() {
				var tableDef sql.NullString
				err := viewDefRows.Scan(&tableDef)
				if err != nil {
					return errors.WithStack(err)
				}
				table.Def = fmt.Sprintf("CREATE %s %s AS (\n%s\n)", tableType, tableName, strings.TrimRight(tableDef.String, ";"))
			}
		}

As an aside: the same feature request could apply to Oracle and SQL Server, which also support materialized views. I just don't know how they treat these types in their system catalog and if tbls already handles them.

Lint for requiring a column

Feature request:
A lint option that requires all tables to have a specified column(s).
We are constantly forgetting to include a modified_at column, and would like tbls lint to help us remember.
We'd also like to exclude some tables from this lint just like the other lint options.

Format the markdown table notation string

Markdownをそのまま見た場合、テーブルの出力内容が整形されておらず非常に見にくいため、
整形して出力するようにしてほしい

現在の状態

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| id | int(11) |  | false |  |  |  |
| name | varchar(10) |  | false |  |  |  |

期待する結果

## Columns

| Name | Type        | Default | Nullable | Children | Parents | Comment |
| ---- | ----------- | ------- | -------- | -------- | ------- | ------- |
| id   | int(11)     |         | false    |          |         |         |
| name | varchar(10) |         | false    |          |         |         |

v1.17.1 linux build is broken

What happened

v1.17.1 linux build is maybe broken

What you expected to happed

RE build

Anything else we need to know?

Version of Go is difference

Environment

  • tbls version
    • 1.17.1
  • Database version
    • PostgreSQL 9.6

tbls does not work with AWS Redshift

tbls doc postgres://user:[email protected]:5439/dbname ./redshift
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x112f0db]

goroutine 1 [running]:
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/opt/go/libexec/src/database/sql/sql.go:2907 +0x6b
database/sql.(*Rows).Close(0x0, 0xc420195840, 0x1)
	/usr/local/opt/go/libexec/src/database/sql/sql.go:2903 +0x33
github.com/k1LoW/tbls/drivers/postgres.(*Postgres).Analyze(0x16ad940, 0xc4200b19a0, 0xc42009a900, 0x14995c0, 0xc4200acfc0)
	/Users/watarukura/src/github.com/k1LoW/tbls/drivers/postgres/postgres.go:28 +0x26cf
github.com/k1LoW/tbls/db.Analyze(0x7ffeefbffa51, 0x5a, 0x0, 0x0, 0x0)
	/Users/watarukura/src/github.com/k1LoW/tbls/db/db.go:47 +0x296
github.com/k1LoW/tbls/cmd.glob..func4(0x168a680, 0xc420134d60, 0x2, 0x2)
	/Users/watarukura/src/github.com/k1LoW/tbls/cmd/doc.go:53 +0x79
github.com/k1LoW/tbls/vendor/github.com/spf13/cobra.(*Command).execute(0x168a680, 0xc420134d20, 0x2, 0x2, 0x168a680, 0xc420134d20)
	/Users/watarukura/src/github.com/k1LoW/tbls/vendor/github.com/spf13/cobra/command.go:766 +0x2c1
github.com/k1LoW/tbls/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x168ab40, 0xc420057f68, 0x136c5d7, 0x144f631)
	/Users/watarukura/src/github.com/k1LoW/tbls/vendor/github.com/spf13/cobra/command.go:852 +0x30a
github.com/k1LoW/tbls/vendor/github.com/spf13/cobra.(*Command).Execute(0x168ab40, 0xc42007c058, 0x0)
	/Users/watarukura/src/github.com/k1LoW/tbls/vendor/github.com/spf13/cobra/command.go:800 +0x2b
github.com/k1LoW/tbls/cmd.Execute()
	/Users/watarukura/src/github.com/k1LoW/tbls/cmd/root.go:49 +0x2d
main.main()
	/Users/watarukura/src/github.com/k1LoW/tbls/main.go:33 +0x20

Analyze で実行している下記SQLがエラーを返すようです。

dbname=#
SELECT CONCAT(table_schema, '."', table_name, '"')::regclass::oid AS oid, table_name, table_type
FROM information_schema.tables
WHERE table_schema != 'pg_catalog' AND table_schema != 'information_schema'
AND table_catalog = 'dbname'
ORDER BY oid;
ERROR:  function concat(information_schema.sql_identifier, "unknown", information_schema.sql_identifier, "unknown") does not exist
HINT:  No function matches the given name and argument types. You may need to add explicit type casts.
dbname=#

'column not found' error if FK constraint references column that name has uppercase letters (MySQL)

What happened

> CREATE DATABASE test;

> USE test;

> CREATE TABLE table1 (productCode INT PRIMARY KEY);

> CREATE TABLE table2 (productCode INT, FOREIGN KEY(`productCode`) REFERENCES table1(`productCode`));

> SHOW CREATE TABLE table1;
+--------+------------------------------------------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                                                                 |
+--------+------------------------------------------------------------------------------------------------------------------------------+
| table1 | CREATE TABLE `table1` (
  `productCode` int(11) NOT NULL,
  PRIMARY KEY (`productCode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+--------+------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

> SHOW CREATE TABLE table2;
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                                                                                                                                                                         |
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| table2 | CREATE TABLE `table2` (
  `productCode` int(11) DEFAULT NULL,
  KEY `productCode` (`productCode`),
  CONSTRAINT `table2_ibfk_1` FOREIGN KEY (`productCode`) REFERENCES `table1` (`productcode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Then,

$ tbls doc mysql://user:[email protected]:3306/test ./dbdoc
not found column 'productcode' on table 'table1'

As you see, MySQL converts productCode into productcode in forein key constraint. This is OK in MySQL because
column names are case-insensitive. However tbls compares column names in case-sensitive manner. This is the cause of the error.

What you expected to happed

Column name comparison should be case-insensitive in MySQL.

What stacktrace or error message from tbls did you see?

$ DEBUG=1 tbls doc mysql://[email protected]:3306/test ./dbdoc
not found column 'productcode' on table 'table1'
github.com/k1LoW/tbls/schema.(*Table).FindColumnByName
	/Users/k1low/src/github.com/k1LoW/tbls/schema/schema.go:149
github.com/k1LoW/tbls/drivers/mysql.(*Mysql).Analyze
	/Users/k1low/src/github.com/k1LoW/tbls/drivers/mysql/mysql.go:362
github.com/k1LoW/tbls/datasource.Analyze
	/Users/k1low/src/github.com/k1LoW/tbls/datasource/datasource.go:111
github.com/k1LoW/tbls/cmd.glob..func5
	/Users/k1low/src/github.com/k1LoW/tbls/cmd/doc.go:73
github.com/spf13/cobra.(*Command).execute
	/Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:846
github.com/spf13/cobra.(*Command).ExecuteC
	/Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:950
github.com/spf13/cobra.(*Command).Execute
	/Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:887
github.com/k1LoW/tbls/cmd.Execute
	/Users/k1low/src/github.com/k1LoW/tbls/cmd/root.go:184
main.main
	/Users/k1low/src/github.com/k1LoW/tbls/main.go:33
runtime.main
	/usr/local/Cellar/go/1.13.7/libexec/src/runtime/proc.go:203
runtime.goexit
	/usr/local/Cellar/go/1.13.7/libexec/src/runtime/asm_amd64.s:1357

Anything else we need to know?

  • In MySQL, database and table names are case-sensitive but columns are case-insensitive.
  • In PostgreSQL, all quoted names are case-sensitive (if not quoted, case-insensitive).

Environment

  • tbls 1.43.1
  • mysql Ver 8.0.12 for osx10.13 on x86_64 (Homebrew)
  • macOS Catalina 10.15.5
  • zsh

panic: runtime error: index out of range

link #36 (comment)

# cat /etc/redhat-release 
CentOS release 6.9 (Final)
# mysql --version
mysql  Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using  EditLine wrapper
# go version
go version go1.9.6 linux/amd64
# go get -u github.com/k1LoW/tbls
# DEBUG=1 tbls doc mysql://user:password@localhost:3306/tbls_mysql57 ./dbdoc
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/k1LoW/tbls/db.Analyze(0x7ffdb65f48b3, 0x46, 0x0, 0x0, 0x0)
        /root/go/src/github.com/k1LoW/tbls/db/db.go:28 +0x453
github.com/k1LoW/tbls/cmd.glob..func4(0xaa7620, 0xc420118e40, 0x2, 0x2)
        /root/go/src/github.com/k1LoW/tbls/cmd/doc.go:56 +0x65
github.com/k1LoW/tbls/vendor/github.com/spf13/cobra.(*Command).execute(0xaa7620, 0xc420118e00, 0x2, 0x2, 0xaa7620, 0xc420118e00)
        /root/go/src/github.com/k1LoW/tbls/vendor/github.com/spf13/cobra/command.go:766 +0x2c1
github.com/k1LoW/tbls/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xaa7ae0, 0xc42001c0b8, 0x0, 0xc42004ff48)
        /root/go/src/github.com/k1LoW/tbls/vendor/github.com/spf13/cobra/command.go:852 +0x334
github.com/k1LoW/tbls/vendor/github.com/spf13/cobra.(*Command).Execute(0xaa7ae0, 0x0, 0x0)
        /root/go/src/github.com/k1LoW/tbls/vendor/github.com/spf13/cobra/command.go:800 +0x2b
github.com/k1LoW/tbls/cmd.Execute()
        /root/go/src/github.com/k1LoW/tbls/cmd/root.go:53 +0x2d
main.main()
        /root/go/src/github.com/k1LoW/tbls/main.go:34 +0x20

improve documentation how to start, how to connect Docker with my Repository

I want to try this app on my SQL Server databases. So I tried to follow the readme.md instruction. I never before used Docker. But why not to use it.

I installed docker desktop for Windows => OK

I called docker pull k1low/tbls:latest in a command line => OK, something happened, something was downloaded, But I don't understand what happens when I call this command. A short explanation in the readme would be helpful.

Add .tbls.yml ( or tbls.yml ) file to your repository.

My understanding: I should create an empty git repository and in this repo I should create the file?
I created an empty git repository on the place where all my repos are located. But Docker will not know this place.

Run tbls doc

If I run in the folder where I created the repository the "tbls" is not found.
if I run this where I called the docker pull k1low/tbls:latest then there is no information where the repository is located.

So please explain in the documentation a little bit, how I should the Docker tell which repository to use.

BTW, when I want to document MS SQL Server, did tbls only support user+password or also integrated security? If yes, how?

Cross-schema virtual relations

I'd like to request support for cross-schema relations in the ER diagram. Our use case would only be virtual relations (as they're not real foreign keys) but having them shown would be very useful.

I think just having the external schema(s) added to the diagram as a group with related tables inside it and only fields of interest would be sufficient.

Bonus: If the SVG generated clickable areas to navigate to schema or table documentation that'd be epic 👌 Probably a separate feature request though, haha.

add a mask and WHERE part

Feature request
Dear all,
Is it possible to add( bc I didn't find a such option) an option to mask the table or a column name using * , %, _, etc? Or check some conditions likewhere: to identify the list of affected objects when the exclude list is specified.
Thanks in advance.

[sqlite] tbls doc error - near ".": syntax error

What happened

tbls doc sq://./data.db # => near ".": syntax error

Tried different paths - absolute, relative with dot and without.

What you expected to happed

No errors

What stacktrace or error message from tbls did you see?

near ".": syntax error
github.com/k1LoW/tbls/drivers/sqlite.(*Sqlite).Analyze
        /Users/k1low/src/github.com/k1LoW/tbls/drivers/sqlite/sqlite.go:251
github.com/k1LoW/tbls/datasource.Analyze
        /Users/k1low/src/github.com/k1LoW/tbls/datasource/datasource.go:85
github.com/k1LoW/tbls/cmd.glob..func4
        /Users/k1low/src/github.com/k1LoW/tbls/cmd/doc.go:69
github.com/spf13/cobra.(*Command).execute
        /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:844
github.com/spf13/cobra.(*Command).ExecuteC
        /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:945
github.com/spf13/cobra.(*Command).Execute
        /Users/k1low/go/pkg/mod/github.com/spf13/[email protected]/command.go:885
github.com/k1LoW/tbls/cmd.Execute
        /Users/k1low/src/github.com/k1LoW/tbls/cmd/root.go:59
main.main
        /Users/k1low/src/github.com/k1LoW/tbls/main.go:33
runtime.main
        /Users/k1low/.anyenv/envs/goenv/versions/1.13.6/src/runtime/proc.go:203
runtime.goexit
        /Users/k1low/.anyenv/envs/goenv/versions/1.13.6/src/runtime/asm_amd64.s:1357

Environment

  • tbls version v1.29.2
  • Database version - sqlite 3
  • Windows 10
  • Config ( .tbls.yml ) - empty

tbls does not support PostgreSQL non-default schema

エラーメッセージ

  • Error: not found table dummy_table

該当箇所

原因?

このテーブルは hoge という schema に属しています。
上記箇所で t.Name は schema name が考慮されておらず name は考慮されているため不一致となるようです。

t.Name -> dummy_table
name -> hoge.dummy_table

Foreign key constraints are treated as unique keys

What happened

If you add a unique attribute and a foreign key constraint at the same time, the foreign key constraint information will be lost.

What you expected to happed

If you check category_info.md, sql is correct below.

CREATE TABLE `category_info` (
  `id` int(11) NOT NULL,
  `category_id` int(11) NOT NULL,
  `group_name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `category_info_category_id_unique` (`category_id`),
  CONSTRAINT `category_info_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8

If you check the constraints, foreign will be treated as UNIQUE.

Name Type Definition
category_info_category_id_foreign UNIQUE UNIQUE KEY category_info_category_id_foreign (category_id)
category_info_category_id_unique UNIQUE UNIQUE KEY category_info_category_id_unique (category_id)
PRIMARY PRIMARY KEY PRIMARY KEY (id)

I want it to be recognized as a foreign key.

| Name | Type | Definition |
| ---- | ---- | ---------- |
- | category_info_category_id_foreign | UNIQUE | UNIQUE KEY category_info_category_id_foreign (category_id) |
+ | category_info_category_id_foreign | FOREIGN KEY | FOREIGN KEY (category_id) REFERENCES categories (id)
| category_info_category_id_unique | UNIQUE | UNIQUE KEY category_info_category_id_unique (category_id) |
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |

What stacktrace or error message from tbls did you see?

No error message.

Anything else we need to know?

Reproduce with the data defined in the repository below.

https://github.com/togana/example-tbls

Execute the following to generate a document.

$ docker-compose up -d mysql
$ sleep 5
$ docker-compose run --rm tbls

Environment

  • tbls version

use docker image tag latest.

$ docker image ls k1low/tbls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
k1low/tbls          latest              303cdf6d0395        2 months ago        39.4MB
  • Database version
$ docker image ls mysql:5.7
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 cd3ed0dfff7e        7 months ago        437MB
  • OS

macOS Calalina

  • Shell

zsh

  • Stacktrace or error message from tbls ( If you can, set DEBUG=1)
  • Config ( .tbls.yml )

MySQL: Inconsistent docs generation if AUTO_INCREMENT has been used

What happened

Generating the docs with a clean DB or with a DB that has some data gives different results, specifically in tables with AUTO_INCREMENT.

The following diff is form a docs generate from a clean/empty DB and vs. docs generated from a DB with data.

- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
+ ) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

What you expected to happed

No difference in the generated docs regardless of the state of the DB.

What stacktrace or error message from tbls did you see?

Anything else we need to know?

Would be nice to have a flag to prevent the AUTO_INCREMENT=[...] to be shown, on the same line of #240.

More than happy to send a PR!

Environment

  • tbls version: 1.44.0
  • Database version: MySQL 8.0.21
  • OS ( Ubuntu bionic, macOS Calalina, WSL2, etc ): Linux
  • Shell ( bash, zsh, poworshell, etc )
  • Stacktrace or error message from tbls ( If you can, set DEBUG=1)
  • Config ( .tbls.yml )

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.