postgresql_autodoc is a nice tool for generating documentation for a postgresql database schema. It sends database metadata to an
HTML::Template-template and can generate html, dot, dia, and docbook xml. I wanted to use it to generate Pod -- one page per table or view.
Here's the technique I came up with :
- 1. Save the template below as "pod.tmpl".
- 2. Run: postgresql_autodoc -d mydb -l . -t pod
- 3. post-process the pod file like this :
mkdir pod
perl -MIO::File -lpe '
s/^_CUT: (.*)$// and do { *STDOUT = IO::File->new(">pod/$1"); };
s/^_DB: (.*)$// and do { $_ = qx[psql -c "$1"]; s/^/ /gm; };
' mydb.pod
(A prerequisite is to have comments on tables and columns stored inside the database using the comment features of postgres).
Here's the template :
<tmpl_loop schemas><tmpl_loop tables>
_CUT: <tmpl_if view_definition>view<tmpl_else>table</tmpl_if>_<tmpl_va
+r table>.pod
=head1 NAME
<tmpl_var table>
=head1 DESCRIPTION
<tmpl_var table_comment>
=head1 COLUMNS
<tmpl_loop columns> <tmpl_var column> (<tmpl_var column_type>) - <tmpl
+_var column_comment>
</tmpl_loop>
=head1 SCHEMA
_DB: \d+ <tmpl_var table>
=cut
</tmpl_loop>
</tmpl_loop>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.