Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

postgresql schema pod

by bduggan (Pilgrim)
on Feb 04, 2010 at 16:04 UTC ( [id://821413]=perlmeditation: print w/replies, xml ) Need Help??

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>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://821413]
Approved by MidLifeXis
Front-paged by MidLifeXis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found