Tbls についての Tipsを備忘録として残しておく

環境

  • OS: macOS 15.3

手順

Tbls について

実際の DB に接続してテーブル定義書を生成してくれるツール
様々な形式(markdown, Excel 等)で生成してくれる
※詳細は Tbls を参照

設定ファイルについて

#
# @see https://github.com/k1LoW/tbls
#

# Data Source Name
## @see https://github.com/k1LoW/tbls#dsn
# dsn: postgres://<<user>>:<<pass>>@localhost:5432/<<dbname>>
# To connect with SSL mode disabled
# dsn: postgres://<<user>>:<<pass>>@localhost:5432/<<dbname>>?sslmode=disable
# DSN configuration values should be found in the .env file TBLS_DSN

# Disable output of schema data
# Default is false
disableOutputSchema: false

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: false
  # It can be boolean or array
  # hideColumnsWithoutValues: ["Parents", "Children"]

er:
  # Skip generation of ER diagram
  # Default is false
  skip: false
  # ER diagram image format (`png`, `jpg`, `svg`, `mermaid`)
  # Default is `svg`
  format: mermaid
  # Add table/column comment to ER diagram
  # Default is false
  comment: false
  # 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: 1
  # ER diagram (png/jpg) font (font name, font file, font path or keyword)
  # Default is "" ( system default )
  font: ""

detectVirtualRelations:
  enabled: true
  strategy: default

# Exclude tables
exclude:
  - goose_db_version

docPath: docs/ja/

comments:
  -
    table: mst_books
    tableComment: |-
            書籍情報を管理するテーブル
    columnComments:
      name: 書籍名
TBLS_DSN=postgres://postgres:postgres@localhost:5432/olbdb?sslmode=disable

出力ファイルの上書きについて

# markdown
tbls doc --config .tbls.yml --rm-dist
# Excel
tbls out --config .tbls.yml -t xlsx -o schema.xlsx

DSN の設定について

ローカルで実施する場合は以下のどちらかで可能

  • Port Forwarding ※推奨
  • ローカルに各環境からテーブル定義のみインポートして実行

mkdocs との連携

S3 等にアップロードして公開する場合は、mkdocs と連携して公開することも可能

site_name: "DB Schema Tables"
docs_dir: docs

theme:
  name: material
  language: ja
  features:
    - search.suggest
    - search.highlight
    - search.share

extra_css:
  - assets/stylesheets/extra.css

extra_javascript:
  - assets/javascripts/custom.js

plugins:
  - search
  - i18n:
      default_language: ja
      languages:
        ja:
          name: 日本語
          build: true
        en:
          name: English
          build: true

markdown_extensions:
  - pymdownx.highlight:
      anchor_linenums: true
      line_spans: __span
      pygments_lang_class: true
  - pymdownx.inlinehilite
  - pymdownx.snippets
  - pymdownx.superfences:
      custom_fences:
        - name: mermaid
          class: mermaid
          format: !!python/name:pymdownx.superfences.fence_code_format
nav:
  - Home: README.md
  - 日本語/Japanese:
    - テーブル一覧: ja/README.md
  - English:
    - Table List: en/README.md
babel==2.17.0
backrefs==5.9
certifi==2025.7.9
charset-normalizer==3.4.2
click==8.2.1
colorama==0.4.6
ghp-import==2.1.0
mkdocs-i18n==0.4.6
idna==3.10
Jinja2==3.1.6
Markdown==3.8.2
MarkupSafe==3.0.2
mergedeep==1.3.4
mkdocs==1.6.1
mkdocs-get-deps==0.2.0
mkdocs-glightbox==0.4.0
mkdocs-material==9.6.15
mkdocs-material-extensions==1.3.1
packaging==25.0
paginate==0.5.7
pathspec==0.12.1
platformdirs==4.3.8
py==1.11.0
Pygments==2.19.2
pymdown-extensions==10.16
python-dateutil==2.9.0.post0
PyYAML==6.0.2
pyyaml_env_tag==1.1
requests==2.32.4
six==1.17.0
urllib3==2.5.0
watchdog==6.0.0