5 sqlt-diagram - Automatically create a diagram from a database schema
9 ./sqlt-diagram -d|-f|--from|--db=db_parser [options] schema.sql
13 -o|--output Output file name (default STDOUT)
14 -i|--image Output image type ("png" or "jpeg," default "png")
15 -t|--title Title to give schema
16 -c|--cols Number of columns
17 -n|--no-lines Don't draw lines
18 --font-size Font size ("small," "medium," "large," or "huge,"
20 --gutter Gutter size between tables
22 --show-fk-only Only show fields that act as primary
25 --natural-join Perform natural joins
26 --natural-join-pk Perform natural joins from primary keys only
27 -s|--skip Fields to skip in natural joins
28 --skip-tables Comma-separated list of table names to exclude
29 --skip-tables-like Comma-separated list of regexen to exclude tables
30 --debug Print debugging information
34 This script will create a picture of your schema. Only the database
35 driver argument (for SQL::Translator) is required. If no output file
36 name is given, then image will be printed to STDOUT, so you should
37 redirect the output into a file.
39 The default action is to assume the presence of foreign key
40 relationships defined via "REFERENCES" or "FOREIGN KEY" constraints on
41 the tables. If you are parsing the schema of a file that does not
42 have these, you will find the natural join options helpful. With
43 natural joins, like-named fields will be considered foreign keys.
44 This can prove too permissive, however, as you probably don't want a
45 field called "name" to be considered a foreign key, so you could
46 include it in the "skip" option, and all fields called "name" will be
47 excluded from natural joins. A more efficient method, however, might
48 be to simply deduce the foriegn keys from primary keys to other fields
49 named the same in other tables. Use the "natural-join-pk" option
68 $out_file, $image_type, $db_driver, $title, $num_columns,
69 $no_lines, $font_size, $add_color, $debug, $show_fk_only,
70 $gutter, $natural_join, $join_pk_only, $skip_fields,
71 $skip_tables, $skip_tables_like, $help
75 'd|db|f|from=s' => \$db_driver,
76 'o|output:s' => \$out_file,
77 'i|image:s' => \$image_type,
78 't|title:s' => \$title,
79 'c|columns:i' => \$num_columns,
80 'n|no-lines' => \$no_lines,
81 'font-size:s' => \$font_size,
82 'gutter:i' => \$gutter,
83 'color' => \$add_color,
84 'show-fk-only' => \$show_fk_only,
85 'natural-join' => \$natural_join,
86 'natural-join-pk' => \$join_pk_only,
87 's|skip:s' => \$skip_fields,
88 'skip-tables:s' => \$skip_tables,
89 'skip-tables-like:s' => \$skip_tables_like,
93 my @files = @ARGV; # the create script(s) for the original db
95 pod2usage(1) if $help;
96 pod2usage( -message => "No db driver specified" ) unless $db_driver;
97 pod2usage( -message => 'No input file' ) unless @files;
99 my $translator = SQL::Translator->new(
102 debug => $debug || 0,
104 out_file => $out_file,
105 image_type => $image_type,
106 gutter => $gutter || 0,
108 num_columns => $num_columns,
109 no_lines => $no_lines,
110 font_size => $font_size,
111 add_color => $add_color,
112 show_fk_only => $show_fk_only,
113 natural_join => $natural_join,
114 join_pk_only => $join_pk_only,
115 skip_fields => $skip_fields,
116 skip_tables => $skip_tables,
117 skip_tables_like => $skip_tables_like,
119 ) or die SQL::Translator->error;
121 for my $file (@files) {
122 my $output = $translator->translate( $file ) or die
123 "Error: " . $translator->error;
125 print "Image written to '$out_file'. Done.\n";
132 # -------------------------------------------------------------------
138 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.