Giter Site home page Giter Site logo

dst's Introduction

Database Schema Tool

Export to different format from definition file.

Usage

Command

NAME:
   dst - Database schema tool

USAGE:
   dst [global options] command [command options] [arguments...]

VERSION:
   development

COMMANDS:
   convert, c  Convert to other format
   verify, v   Verify the foreign key
   help, h     Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug, -d    Debug mode (default: false)
   --help, -h     show help (default: false)
   --version, -v  print the version (default: false)

Use --help after command to show addition information, e.g.

$ dst convert --help

NAME:
   dst convert - Convert to other format

USAGE:
   dst convert command [command options] [arguments...]

COMMANDS:
   yaml, y
   excel, e
   text, t
   diagram, d
   help, h     Shows a list of commands or help for one command

OPTIONS:
   --help, -h  show help (default: false)

Example

Create a definition file (e.g. sample.yml)

# column definition:
#   na: column-name
#   ty: data-type
#   nu: not null (Y/N)
#   id: identity (Y/N)
#   in: index (Y/N)
#   un: unique (Y/N)
#   va: default value
#   fk: foreign key hint
#   cd: cardinality
#   tt: title
#   dc: description

# fixed columns:
# the columns will be appended to each table
fixed:
  - { na: deleted, ty: int, va: 0, nu: Y, dc: "0:activated, others:deleted" }
  - { na: create_user_id, ty: int, nu: Y, dc: "record create user ID" }
  - { na: create_time, ty: datetime, nu: Y, dc: "record create time" }
  - { na: update_user_id, ty: int, nu: Y, dc: "record update user ID" }
  - { na: update_time, ty: datetime, nu: Y, dc: "record update time" }
  - { na: recver, ty: int, nu: Y, va: 0, dc: "record version" }

schemas:
  - name: General
    tables:
      - name: doc
        title: document
        desc: External document/files
        columns:
          - { na: doc_id, ty: INT, id: Y, nu: Y, dc: "unique identifier" }
          - { na: ver, ty: INT, nu: Y, dc: "version, starts from zero" }
          - { na: ref, ty: VARCHAR(50), nu: Y, un: Y, dc: "reference to locate the external file" }

      - name: doc_tag
        title: document tag
        desc: "Relationship table between doc and tag"
        columns:
          - { na: doc_tag_id, ty: INT, id: Y, nu: Y, dc: "unique identifier" }
          - { na: doc_id, ty: INT, nu: Y, fk: doc.doc_id, cd: "0..*:1", dc: "doc id" }
          - { na: tag_id, ty: INT, nu: Y, fk: tag.tag_id, cd: "0..*:1", dc: "tag id" }

      - name: tag
        desc: "Code table for tag"
        columns:
          - { na: tag_id, ty: INT, id: Y, nu: Y, dc: "unique identifier" }
          - { na: code, ty: VARCHAR(10), dc: "tag code. eg. premarket md application index A1" }
          - { na: name, ty: VARCHAR(20), nu: Y, dc: "tag name" }
          - { na: priority, ty: VARCHAR(50), dc: "tag priority" }
          - { na: descr, ty: VARCHAR(50), dc: "tag description" }
          - { na: source, ty: CHAR(3), nu: Y, dc: "Source; COM: common, PRE: pre, POS: post" }
          - { na: type, ty: CHAR(3), nu: Y, dc: "Tag Type; ATT: attachment, APP: application, COM: company" }
# -- YAML to Excel
$ dst convert excel -i sample.yml -o sample.xlsx

# -- Excel to YAML
$ dst convert yaml -i sample.xlsx -o sample.yml

# -- YAML to ER diagram definition file
$ dst convert diagram -i sample.yml -o sample.puml

# -- YAML to ER diagram (.png)
# download plantuml.jar from https://plantuml.com/download
$ dst convert diagram -i sample.yml -o sample.puml -j plantuml.jar
# you may convert some of tables, select the tables starts with 'tag' pattern only, '*' can be replaced by '%'
$ dst convert diagram -i sample.yml -o sample.puml -j plantuml.jar -p 'tag*'
# for simple mode, only show PK and FK in the diagram
$ dst convert diagram -i sample.yml -o sample.puml -j plantuml.jar --simple
# include foreign key name in the relationship line
$ dst convert diagram -i sample.yml -o sample.puml -j plantuml.jar --fk

# -- YAML to SQL schema file
# generate using template.tpl
$ dst convert text -i sample.yml -o sample.sql -t template.tpl
# generate using template.tpl, select the tables start with 'tag' pattern only, '*' can be replaced by '%'
$ dst convert text -i sample.yml -o sample.sql -t template.tpl -p -p 'tag*'

# -- Verify foreign key
# make sure the foreign table and key exist
$ dst verify -i sample.yml

dst's People

Contributors

zrs01 avatar

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.