PostgreSQL数据库架构设计与维护工具
pg-db-tools的Python项目详细描述
使用基于yaml的 描述。
阅读documentation on readthedocs.io。
安装
从pypi安装:
$ pip3 install pg-db-tools
从github安装:
$ git clone https://github.com/hendrikx-itc/pg-db-tools $ sudo pip3 install pg-db-tools
用法
命令用法:
db-schema <command> [options] commands: compile compile output from schema definition extract extract schema definition from source doc documentation generation command --help,-h display help information
编译
子命令编译:
db-schema compile <output-type> <schema-filename> output-types: dot Generate Graphviz DOT sql Generate SQL md Generate Markdown documentation rst Generate reStructuresText documentation
提取
子命令提取:
db-schema extract <source> sources: from-db Extract from postgres database
来自数据库的子命令:
db-schema extract from-db --format {yaml.json} [--owner OWNER] [schemas]
架构: *可以提供多个架构 *如果未提供模式,则返回所有模式
示例:
PGHOST=localhost \ PGPORT=5432 \ PGUSER=postgres \ PGDATABASE=postgres \ db-schema extract from-db --format yaml
医生
示例
从示例webshop.yaml:
$ db-schema compile sql example/webshop.yaml
从示例webshop.yaml:
$ db-schema compile rst example/webshop.yaml
结果:
Schema ``shop`` =============== Tables ------ Order ^^^^^ Contains all orders +---------+--------------------------+----------+-------------+ | Column | Type | Nullable | Description | +=========+==========================+==========+=============+ | id | integer | ✔ | Primary key | +---------+--------------------------+----------+-------------+ | created | timestamp with time zone | ✔ | | +---------+--------------------------+----------+-------------+ OrderLine ^^^^^^^^^ Contains all order lines for all orders +------------+---------+----------+-------------+ | Column | Type | Nullable | Description | +============+=========+==========+=============+ | id | integer | ✔ | Primary key | +------------+---------+----------+-------------+ | order_id | integer | ✔ | | +------------+---------+----------+-------------+ | line_nr | integer | ✔ | | +------------+---------+----------+-------------+ | product_id | integer | ✔ | | +------------+---------+----------+-------------+ | amount | integer | ✔ | | +------------+---------+----------+-------------+ Schema ``public`` =================
说明格式
工具集的主要组件之一是数据库模式描述 格式。描述格式基于yaml,因为它易于阅读和 为人类写作。
看一个例子[这里](https://github.com/hendrikx-itc/pg-db-tools/blob/master/example/webshop.yaml)
请参阅架构文件[此处](https://github.com/hendrikx-itc/pg-db-tools/blob/master/src/pg_db_tools/spec.schema)
注
这个工具不是一个跨数据库工具集,因为 这通常会导致兼容性问题和多个部分支持 数据库引擎。