Skip to content
This repository
Browse code

pod fixes, cleanup tests better, new diagram feature

  • Loading branch information...
commit 0c90f641d7b7501c9e782e44e2cb4da0346452ac 1 parent 334e813
John Napiorkowski authored
5 Changes
... ... @@ -1,5 +1,10 @@
1 1 Revision history for DBIx-Class-Migration
2 2
  3 +0.017 14 March 2012
  4 + - POD and documentation fixes (logie17++)
  5 + - new command: "dbic-migration diagram". If GraphViz is installed will
  6 + produce a png file of the current schema. EXPERIMENTAL!
  7 +
3 8 0.016 12 March 2012
4 9 - More POD and documentation fixes (Volker++), (logie17++)
5 10 - changed the way I declare version requirements in my dist.ini filr
3  dist.ini
@@ -5,7 +5,7 @@ copyright_holder = John Napiorkowski
5 5 copyright_year = 2012
6 6 abstract = Make it easy to migrate DBIC based databases
7 7
8   -version = 0.016
  8 +version = 0.017
9 9
10 10 [@Basic]
11 11 [Prereqs]
@@ -29,6 +29,7 @@ DBD::SQLite = 0
29 29 Pod::Parser = 1.51
30 30 Config::MySQL = 0
31 31 version = 0.77
  32 +SQL::Translator = 0.11010
32 33
33 34 [Prereqs / TestRequires]
34 35 Test::Most = 0
BIN  examples/MusicBase/share/db-diagram-v3.png
38 lib/DBIx/Class/Migration.pm
... ... @@ -1,6 +1,6 @@
1 1 package DBIx::Class::Migration;
2 2
3   -our $VERSION = "0.016";
  3 +our $VERSION = "0.017";
4 4
5 5 use Moose;
6 6 use JSON::XS;
@@ -10,6 +10,7 @@ use File::Path 'mkpath', 'remove_tree';
10 10 use MooseX::Types::LoadableClass 'LoadableClass';
11 11 use Class::Load 'load_class';
12 12 use Devel::PartialDump;
  13 +use SQL::Translator;
13 14
14 15 has db_sandbox_class => (
15 16 is => 'ro',
@@ -427,6 +428,24 @@ sub make_schema {
427 428 catdir($self->target_dir, 'dumped_db'));
428 429 }
429 430
  431 +sub diagram {
  432 + my $self = shift;
  433 + my $trans = SQL::Translator->new(
  434 + parser => 'SQL::Translator::Parser::DBIx::Class',
  435 + parser_args => { package => $self->schema },
  436 + producer => 'GraphViz',
  437 + producer_args => {
  438 + skip_tables => 'dbix_class_deploymenthandler_versions',
  439 + show_constraints => 1,
  440 + show_datatypes => 1,
  441 + show_sizes => 1,
  442 + out_file => catfile(
  443 + $self->target_dir, 'db-diagram-v' . $self->dbic_dh->schema_version . '.png')});
  444 +
  445 + $trans->translate
  446 + or die $trans->error;
  447 +}
  448 +
430 449 sub install_if_needed {
431 450 my ($self, %callbacks) = @_;
432 451 if(!$self->dbic_dh->version_storage_is_installed) {
@@ -885,6 +904,23 @@ the matching sets for that version.
885 904 Skips the table C<dbix_class_deploymenthandler_versions>, so you don't lose
886 905 deployment info (this is different from L</drop_tables> which does delete it.)
887 906
  907 +=head diagram
  908 +
  909 +Experimental feature. Although not specifically a migration task, I find it
  910 +useful to output visuals of my databases. This command will place a file in
  911 +your L</target_dir> called C<db-diagram-vXXX.png> where C<XXX> is he current
  912 +C<schema> version.
  913 +
  914 +This is using the Graphviz producer (L<SQL::Translator::Producer::GraphViz>)
  915 +which in turn requires L<Graphviz>. Since this is not always trivial to
  916 +install, I do not require it. You will need to add it manually to your
  917 +C<Makefile.PL> or C<dist.ini> and manage it yourself.
  918 +
  919 +This feature is experimental and currently does not offer any options, as I
  920 +am still determining the best way to meet the need without exceeding the
  921 +scope of L<DBIx::Class::Migration>. Consider this command a 'freebee' and
  922 +please don't depend on it in your custom code.
  923 +
888 924 =head2 install_if_needed
889 925
890 926 If the database is not installed, do so. Accepts a hash of callbacks or
9 lib/DBIx/Class/Migration/Script.pm
@@ -74,7 +74,7 @@ has fixture_sets => (
74 74 version status prepare install upgrade
75 75 downgrade drop_tables delete_table_rows
76 76 dump_all_sets make_schema install_if_needed
77   - dump );
  77 + dump diagram);
78 78 }
79 79
80 80 has migration_class => (
@@ -523,6 +523,13 @@ what the deployment perl run files get for schema.
523 523 Install the database to the current C<$schema> version if it is not currently
524 524 installed. Otherwise this is a nop (even if the database is behind the schema).
525 525
  526 +=head2 diagram
  527 +
  528 +Experimental feature. This command will place a file in your L</target_dir>
  529 +called C<db-diagram-vXXX.png> where C<XXX> is he current C<schema> version.
  530 +
  531 +This feature is experimental and currently does not offer any options.
  532 +
526 533 =head2 Command Flags
527 534
528 535 The following flags are used to modify or inform commands.
20 t/00-clean.t
... ... @@ -0,0 +1,20 @@
  1 +#!/usr/bin/env perl
  2 +
  3 +## Just a test class to make sure we have a nice, clean target_dir
  4 +## in case a previous test run make a mess.
  5 +
  6 +use lib 't/lib';
  7 +use Test::Most;
  8 +use DBIx::Class::Migration::Population;
  9 +use File::Spec::Functions 'catfile';
  10 +use File::Path 'rmtree';
  11 +
  12 +ok( my $p = DBIx::Class::Migration::Population->new(schema_class=>'Local::Schema'),
  13 + 'created population object from schema_class');
  14 +
  15 +rmtree catfile($p->target_dir, 'migrations');
  16 +rmtree catfile($p->target_dir, 'fixtures');
  17 +unlink catfile($p->target_dir, 'local-schema.db');
  18 +rmtree catfile($p->target_dir, 'local-schema');
  19 +
  20 +done_testing;

0 comments on commit 0c90f64

Please sign in to comment.
Something went wrong with that request. Please try again.