PostgreSQL数据库架构设计与维护工具

pg-db-tools的Python项目详细描述


Crates.io

使用基于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

这个工具不是一个跨数据库工具集,因为 这通常会导致兼容性问题和多个部分支持 数据库引擎。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Android Java在活动之间传递值   java当实体中存在关系时,我可以只使用实体的id而不是从DB中获取实体吗?   bouncycastle Java运行SSHD服务器错误未找到类定义   java SWT/Swing>Threads n'Hell   java多线程数据库读取   java如何在Eclipse中轻松提交Git   java在哪里可以找到字符串相等比较的一组特定排序规则?   无连接表的java单向单域关系   java扩展三角文件   java spring。杰克逊。序列化。failonemptybeans   java无法加载请求的类:oracle。jdbc。驾驶员OracleDriver   java通过数组进行索引循环并打印出元素?   找不到eclipse错误类中的java提交Hadoop作业   Java:随机设定种子   java片段、异步任务和侦听器   java在分号后使用{}