zoukankan      html  css  js  c++  java
  • tbls ci 友好的数据库文档化工具

    tbls 是用golang 编写的数据库文档化工具,当前支持的数据库有pg、mysql、bigquery
    此工具同时提供了变更对比、lint 校验,生成是markdown格式的

    简单使用

    安装

    mac 系统使用brew 安装

     
    brew install k1LoW/tap/tbls 

    简单项目使用

    • 数据库准备

      pg 使用docker-compose 运行

    version: "3"
    services:
      postgres:
        image: postgres:9.6.11
        ports:
        - "5432:5432"
        environment:
        - "POSTGRES_PASSWORD:dalong"
     
     
    • 创建.tbls.yml 文件

      主要是配置数据库连接,以及生成文档的存储路径

    # .tbls.yml
    # DSN (Databaase Source Name) to connect database
    dsn: postgres://postgres:dalong@localhost:5432/postgres?sslmode=disable
    # Path to generate document
    # Default is `dbdoc`
    docPath: doc/schema
     
     
    • 添加数据库
    CREATE TABLE userlogins (
        id SERIAL PRIMARY KEY,
        username text
    );
    • diff 操作
    tbls diff
    diff postgres://postgres:*****@localhost:5432/postgres?sslmode=disable doc/schema/README.md
    --- postgres://postgres:*****@localhost:5432/postgres?sslmode=disable
    +++ doc/schema/README.md
    @@ -4,7 +4,6 @@
     | Name | Columns | Comment | Type |
     | ---- | ------- | ------- | ---- |
    -| [userlogins](userlogins.md) | 2 | | BASE TABLE |
     ---
    diff postgres://postgres:*****@localhost:5432/postgres?sslmode=disable doc/schema/userlogins.md
    --- postgres://postgres:*****@localhost:5432/postgres?sslmode=disable
    +++ doc/schema/userlogins.md
    @@ -1,27 +1 @@
    -# userlogins
    -## Description
    -
    -## Columns
    -
    -| Name | Type | Default | Nullable | Children | Parents | Comment |
    -| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
    -| id | integer | nextval('userlogins_id_seq'::regclass) | false | | | |
    -| username | text | | true | | | |
    -
    -## Constraints
    -
    -| Name | Type | Definition |
    -| ---- | ---- | ---------- |
    -| userlogins_pkey | PRIMARY KEY | PRIMARY KEY (id) |
    -
    -## Indexes
    -
    -| Name | Definition |
    -| ---- | ---------- |
    -| userlogins_pkey | CREATE UNIQUE INDEX userlogins_pkey ON public.userlogins USING btree (id) |
    -
    ----
    -
    -> Generated by [tbls](https://github.com/k1LoW/tbls)
     
     
    • 生成doc
    tbls doc
    • 效果
    doc/schema/README.md
    doc/schema/userlogins.md
     

    内容信息
    README.md

     
    # postgres
    ## Tables
    | Name | Columns | Comment | Type |
    | ---- | ------- | ------- | ---- |
    | [userlogins](userlogins.md) | 2 | | BASE TABLE |
    ---
    > Generated by [tbls](https://github.com/k1LoW/tbls)
     
     

    userlogins.md

    # userlogins
    ## Description
    ## Columns
    | Name | Type | Default | Nullable | Children | Parents | Comment |
    | ---- | ---- | ------- | -------- | -------- | ------- | ------- |
    | id | integer | nextval('userlogins_id_seq'::regclass) | false | | | |
    | username | text | | true | | | |
    ## Constraints
    | Name | Type | Definition |
    | ---- | ---- | ---------- |
    | userlogins_pkey | PRIMARY KEY | PRIMARY KEY (id) |
    ## Indexes
    | Name | Definition |
    | ---- | ---------- |
    | userlogins_pkey | CREATE UNIQUE INDEX userlogins_pkey ON public.userlogins USING btree (id) |
    ---
    > Generated by [tbls](https://github.com/k1LoW/tbls)
     
     
    • UI 效果

    说明

    tbls 做为数据库diff 以及自动文档生成还是很很不错的工具,同时对于ci也是比较友好的

    参考资料

    https://github.com/rongfengliang/tbls-pg-demo
    https://github.com/k1LoW/tbls#support-database

  • 相关阅读:
    iOS 里面 NSTimer 防止 循环引用
    [leetcode 34] search for a range
    [leetcode 37]sudoku solver
    [leetcode 36] valid sudoku
    [leetcode 48] rotate image
    [leetcode 35] Search Insert Position
    [leetcode 27]Implement strStr()
    [leetcode 26] Remove Duplicates from Sorted Array
    [leetcode 25]Reverse Nodes in k-Group
    [leetcode 24] Swap Nodes in k-Group
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/10929042.html
Copyright © 2011-2022 走看看