Disclaimer: This is a fork of jackscodemonkey's sphinx-sql, which aims to provide a tool to document database design within DDL source code.
It was extended by winkelband in Dec 2020 by the following features:
- Support more DDL objects (cluster objects like Role; catalog objects like Extension, Trigger, Materialized View [and other objects consist of two words]; objects with quoted names)
- Extract Table Attributes (Columns with metadata) (can be disabled); also Comments On Columns are parsed as the description (use one-line text, no markup!)
- Objects without a top-level comment are also listed
- Distinct header for tables generated by sphinx (Dependent Objects, ChangeLog, Attributes) by using the first row
- New examples in
tests/
to reflect the added features
- The following sections of this README were slighty modified:
- Installation
- Configuration
This fork utilizes a slightly modified version of ddlparse to parse table attributes (columns), but it also works with the original ddlparse (v1.9.0 tested).
Tip: If you create your DDL with pgModeler, you may want to look into this simple script to genrate single DDL files, which can be handled by sphinx-sql.
TODO:
See docs/source/todo.rst
sphinx-sql is a Sphinx documentation extension for building documentation from SQL source files.
Having found nothing in the while that could help solve the db first problem, I've written sphinx-sql.
This implimentation is tested against Greenplum / Postgres, those are the databases I work with on a daily basis. If you want to extend functionality, have a quick look at the contrib section of this document.
Install from PyPI:
pip install -e git://github.com/winkelband/sphinx-sql.git#egg=sphinx-sql
In your conf.py for Sphinx enable the extension:
extensions = [
'sphinx_sql.sphinx_sql',
]
By default, Table Columns with their metadata are extracted from the DDL. You can disable this behaviour by change settings in your conf.py:
sphinxsql_include_table_attributes = False
Create a new rst file (we'll call it autosql.rst) and include it in your toc-tree.
.. toctree::
:maxdepth: 2
:caption: Navigation:
autosql
Add the directive with a relative path from your document build folder to the root of your SQL source in the autosql.rst file.
SQL Documentation
^^^^^^^^^^^^^^^^^
.. autosql::
:sqlsource: ../../SQL
Key word groups:
FUNCTIONS:
/*
Parameters:
Name | Type | Description
Return: Void
Purpose:
Detailed explanation of the function which includes:
- Function business logic
- Transformation rules
- Here is a bit more text.
Dependent Objects:
Type |Name
Table |schema_name.source_table5
View |schema_name.target_table6
ChangeLog:
Date | Author | Ticket | Modification
YYYY-MM-DD | Developer name | T-223 | Short Modification details or some really long text that will continue on.
*/
TABLES/VIEWS/etc:
/*
Purpose:
This a new view to show how auto documentation can add new obejcts quickly.
Dependent Objects:
Type |Name
Table |schema1.ext_table
ChangeLog:
Date | Author | Ticket | Modification
2020-10-26 | Developer_2 | T-220 | Initial Definition
*/
DML:
/*
Object Name: <schema.name>
Object Type: DML
Purpose:
This a new view to show how auto documentation can add new obejcts quickly.
ChangeLog:
Date | Author | Ticket | Modification
2020-10-26 | Developer_2 | T-220 | Initial Definition
*/