From: Fitz Elliott Date: Wed, 9 Jul 2014 21:22:46 +0000 (-0400) Subject: generate svg of DBICTest::Schema in author mode X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ad93ee3644101e17d08bfbbd36cb3b181c9e27b2;p=dbsrgits%2FDBIx-Class.git generate svg of DBICTest::Schema in author mode * Use SQL::Translator and GraphViz to produce an svg of the DBIC test schema layout. The new file is examples/DBICTest/db-diagram.svg and will be generated when the Makefile.PL is run in author mode. * Add GraphViz to DBIC::Optional::Dependencies's dist_dir group --- diff --git a/examples/DBICTest/db-diagram.svg b/examples/DBICTest/db-diagram.svg new file mode 100644 index 0000000..6f6f307 --- /dev/null +++ b/examples/DBICTest/db-diagram.svg @@ -0,0 +1,514 @@ + + + + + + +test + + +node1 + +artist + +- artistid integer [PA] +- name varchar(100) [U,N] +- rank integer [U] +- charfield char(10) [U,N] + + +node21 + +artist_undirected_map + +- id1 integer [PK] +- id2 integer [PK] + + +node1->node21 + + + + +node25 + +forceforeign + +- artist integer [PK] +- cd integer + + +node1->node25 + + + + +node28 + +cd + +- cdid integer [PA] +- artist integer [U] +- title varchar(100) [U] +- year varchar(100) +- genreid integer [N] +- single_track integer [FK,N] + + +node1->node28 + + + + +node37 + +twokeys + +- artist integer [PK] +- cd integer [PK] + + +node1->node37 + + + + +node38 + +artwork_to_artist + +- artwork_cd_id integer [PK,FK] +- artist_id integer [PK,FK] + + +node1->node38 + + + + +node2 + +bindtype_test + +- id integer [PA] +- bytea bytea [N] +- blob blob [N] +- clob clob [N] +- a_memo memo [N] + + +node3 + +collection + +- collectionid integer [PA] +- name varchar(100) + + +node29 + +collection_object + +- collection integer [PK] +- object integer [PK] + + +node3->node29 + + + + +node4 + +encoded + +- id integer [PA] +- encoded varchar(100) [N] + + +node24 + +employee + +- employee_id integer [PA] +- position integer +- group_id integer [N] +- group_id_2 integer [N] +- group_id_3 integer [N] +- name varchar(100) [N] +- encoded integer [N] + + +node4->node24 + + + + +node5 + +event + +- id integer [PA] +- starts_at date +- created_on timestamp +- varchar_date varchar(20) [N] +- varchar_datetime varchar(20) [N] +- skip_inflation datetime [N] +- ts_without_tz datetime [N] + + +node6 + +fourkeys + +- foo integer [PK] +- bar integer [PK] +- hello integer [PK] +- goodbye integer [PK] +- sensors character +- read_count int [N] + + +node39 + +fourkeys_to_twokeys + +- f_foo integer [PK] +- f_bar integer [PK] +- f_hello integer [PK] +- f_goodbye integer [PK] +- t_artist integer [PK] +- t_cd integer [PK] +- autopilot character +- pilot_sequence integer [N] + + +node6->node39 + + + + +node7 + +genre + +- genreid integer [PA] +- name varchar(100) [U] + + +node7->node28 + + + + +node8 + +link + +- id integer [PA] +- url varchar(100) [N] +- title varchar(100) [N] + + +node22 + +bookmark + +- id integer [PA] +- link integer [N] + + +node8->node22 + + + + +node9 + +money_test + +- id integer [PA] +- amount money [N] + + +node10 + +noprimarykey + +- foo integer [U] +- bar integer [U] +- baz integer + + +node11 + +onekey + +- id integer [PA] +- artist integer +- cd integer + + +node12 + +owners + +- id integer [PA] +- name varchar(100) [U] + + +node23 + +books + +- id integer [PA] +- source varchar(100) +- owner integer +- title varchar(100) [U] +- price integer [N] + + +node12->node23 + + + + +node13 + +producer + +- producerid integer [PA] +- name varchar(100) [U] + + +node35 + +cd_to_producer + +- cd integer [PK] +- producer integer [PK] +- attribute integer [N] + + +node13->node35 + + + + +node14 + +self_ref + +- id integer [PA] +- name varchar(100) + + +node26 + +self_ref_alias + +- self_ref integer [PK] +- alias integer [PK] + + +node14->node26 + + + + +node15 + +sequence_test + +- pkid1 integer [PK] +- pkid2 integer [PK] +- nonpkid integer +- name varchar(100) [N] + + +node16 + +serialized + +- id integer [PA] +- serialized text + + +node17 + +timestamp_primary_key_test + +- id timestamp [PK] + + +node18 + +treelike + +- id integer [PA] +- parent integer [N] +- name varchar(100) + + +node18->node18 + + + + +node19 + +twokeytreelike + +- id1 integer [PK] +- id2 integer [PK] +- parent1 integer +- parent2 integer +- name varchar(100) [U] + + +node19->node19 + + + + +node20 + +typed_object + +- objectid integer [PA] +- type varchar(100) +- value varchar(100) + + +node20->node29 + + + + +node27 + +track + +- trackid integer [PA] +- cd integer [U] +- position int [U] +- title varchar(100) [U] +- last_updated_on datetime [N] +- last_updated_at datetime [N] + + +node27->node28 + + + + +node30 + +lyrics + +- lyric_id integer [PA] +- track_id integer [FK] + + +node27->node30 + + + + +node28->node27 + + + + +node31 + +cd_artwork + +- cd_id integer [PK] + + +node28->node31 + + + + +node32 + +liner_notes + +- liner_id integer [PK] +- notes varchar(100) + + +node28->node32 + + + + +node34 + +tags + +- tagid integer [PA,U] +- cd integer [U] +- tag varchar(100) [U] + + +node28->node34 + + + + +node28->node35 + + + + +node28->node37 + + + + +node33 + +lyric_versions + +- id integer [PA] +- lyric_id integer [FK,U] +- text varchar(100) [U] + + +node30->node33 + + + + +node36 + +images + +- id integer [PA] +- artwork_id integer [FK] +- name varchar(100) +- data blob [N] + + +node31->node36 + + + + +node31->node38 + + + + +node37->node39 + + + + + diff --git a/lib/DBIx/Class/Optional/Dependencies.pm b/lib/DBIx/Class/Optional/Dependencies.pm index 7e69eea..d208394 100644 --- a/lib/DBIx/Class/Optional/Dependencies.pm +++ b/lib/DBIx/Class/Optional/Dependencies.pm @@ -669,7 +669,8 @@ my $dbic_reqs = { req => { 'ExtUtils::MakeMaker' => '6.64', 'Pod::Inherit' => '0.91', - }, + 'GraphViz' => '0', + } }, dist_upload => { diff --git a/maint/Makefile.PL.inc/56_autogen_schema_files.pl b/maint/Makefile.PL.inc/56_autogen_schema_files.pl index 6096010..5d3bbba 100644 --- a/maint/Makefile.PL.inc/56_autogen_schema_files.pl +++ b/maint/Makefile.PL.inc/56_autogen_schema_files.pl @@ -1,6 +1,8 @@ require File::Spec; my $test_ddl_fn = File::Spec->catfile(qw( t lib sqlite.sql )); my @test_ddl_cmd = qw( -I lib -I t/lib -- maint/gen_sqlite_schema_files --schema-class DBICTest::Schema ); +my $test_graph_fn = File::Spec->catfile(qw( examples DBICTest db-diagram.svg )); +my @test_graph_cmd = qw( -I lib -I t/lib -- maint/gen_dbictest_schema_diagram --schema-class DBICTest::Schema ); my $example_ddl_fn = File::Spec->catfile(qw( examples Schema db example.sql )); my $example_db_fn = File::Spec->catfile(qw( examples Schema db example.db )); @@ -15,6 +17,9 @@ if ( DBIx::Class::Optional::Dependencies->req_ok_for ('deploy') ) { print "Regenerating $test_ddl_fn\n"; system( $^X, @test_ddl_cmd, '--ddl-out' => $test_ddl_fn ); + print "Regenerating $test_graph_fn\n"; + system( $^X, @test_graph_cmd, '--diagram-out' => $test_graph_fn ); + print "Regenerating $example_ddl_fn and $example_db_fn\n"; system( $^X, @example_ddl_cmd, '--ddl-out' => $example_ddl_fn, '--deploy-to' => $example_db_fn ); diff --git a/maint/gen_dbictest_schema_diagram b/maint/gen_dbictest_schema_diagram new file mode 100644 index 0000000..e2df755 --- /dev/null +++ b/maint/gen_dbictest_schema_diagram @@ -0,0 +1,57 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use DBICTest; + +use Module::Runtime 'use_module'; +use SQL::Translator; +use Path::Class 'file'; +use Getopt::Long; +my $getopt = Getopt::Long::Parser->new( + config => [qw/gnu_getopt bundling_override no_ignore_case/] +); +my $args = {}; +$getopt->getoptions($args, qw/ + diagram-out=s@ + schema-class=s@ +/); + +die "You need to specify one diagram output filename via --diagram-out\n" + if @{$args->{'diagram-out'}||[]} != 1; + +die "You need to specify one DBIC schema class via --schema-class\n" + if @{$args->{'schema-class'}||[]} != 1; + +my $diagram_fh; +if ($args->{'diagram-out'}[0] eq '-') { + $diagram_fh = *STDOUT; +} +else { + my $fn = file($args->{'diagram-out'}[0]); + $fn->dir->mkpath; + open $diagram_fh, '>', $fn + or die "Unable to open $fn: $!\n"; +} +binmode $diagram_fh; # avoid win32 \n crapfest + +my $schema_class = $args->{'schema-class'}[0]; +use_module( $schema_class ); +my $schema = $schema_class->connect( DBICTest->_database(quote_char => '"') ); + +my $trans = SQL::Translator->new( + parser => 'SQL::Translator::Parser::DBIx::Class', + parser_args => { dbic_schema => $schema }, + producer => 'GraphViz', + producer_args => { + show_constraints => 1, + show_datatypes => 1, + show_sizes => 1, + out_file => $diagram_fh, + output_type => 'svg', + layout => 'neato', + } +); + +$trans->translate or die $trans->error;