schema_diagram - Create a diagram of a database's tables
schema_diagram [--user username] [--password password] [--format format] [--output filename] [--tile] [--scale factor] [--paper paper_size] DBI_data_source
Produces a diagram of the specified database, showing all the tables, listing their fields, and indicating foreign key links between tables.
The output can be various formats, including PostScript, png, SVG, and GraphViz's dot. If the poster(1) command is available then PostScript output can be tiled on to multiple sheets.
Generate a PostScript diagram of the Postgres database wedding, saving it to the file wedding.ps:
wedding
schema_diagram DBI:Pg:dbname=wedding
Same, but tile it over multiple sheets:
schema_diagram --tile DBI:Pg:dbname=wedding
Generate a png image of the MySQL database intranet, connecting as the user wiki, and saving it to the file intranet.png:
intranet
wiki
intranet.png
schema_diagram --format png --user wiki DBI:mysql:intranet
Same, but save to the file DB_schema.png:
DB_schema.png
schema_diagram --output DB_schema.png --user wiki DBI:mysql:intranet
Specify the database with DBI_data_source, a string in the format used by the Perl DBI module, such as in the above examples.
If non-default authentication is required, specify them with these options:
The username to the database as.
The password to use when connecting to the database.
These options can be used to specify the output format and filename. By default PostScript output is generated and the filename based on the database's name.
The output format. Valid values include png, svg, fig, plain, and any format which the GraphViz module can create with an add_* method. The format dot can be used to specify GraphViz's dot format, suitable for passing to dot(1).
png
svg
fig
plain
add_*
dot
dot(1)
The name of the file to save the diagram in. If the filename has an extension which matches the desired format then there is no need to also pass the --format option; schema_diagram will work out the format from the filename.
--format
These options use the poster(1) command to split the diagram over multiple sheets, with cutmarks suitable for printing and assembling into a large poster. There is no tiling by default.
poster(1)
Tile the diagram. This will use the system's default paper size, and a scale factor of 0.4.
Scale the diagram by the specified factor.
Specifying --scale implies --tile.
--scale
--tile
Tile on to sheets of the specified paper size.
Specifying --paper implies --tile.
--paper
If you wish to tweak a diagram, perhaps to remove some irrelevant tables or specify a de facto foreign key link which isn't encoded in the database, use --format dot. Then edit the created file with a text editor (the format is quite intutive to make basic changes), and use the dot command to generate the diagram.
--format dot
DBI, GraphViz, GraphViz::DBI::FromSchema, poster
Written by Smylers, for Webfusion http://www.webfusion.com/
Contact me on <Smylers@cpan.org> or http://twitter.com/Smylers2
Copyright 2011 Webfusion Ltd
This library is software libre; you may redistribute it and modify it under the terms of any of these licences:
The GNU General Public License, version 2
The GNU General Public License, version 3
The Artistic License
The Artistic License 2.0
To install GraphViz::DBI::FromSchema, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GraphViz::DBI::FromSchema
CPAN shell
perl -MCPAN -e shell install GraphViz::DBI::FromSchema
For more information on module installation, please visit the detailed CPAN module installation guide.