Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pod fixes, cleanup tests better, new diagram feature

  • Loading branch information...
commit 0c90f641d7b7501c9e782e44e2cb4da0346452ac 1 parent 334e813
@jjn1056 authored
View
5 Changes
@@ -1,5 +1,10 @@
Revision history for DBIx-Class-Migration
+0.017 14 March 2012
+ - POD and documentation fixes (logie17++)
+ - new command: "dbic-migration diagram". If GraphViz is installed will
+ produce a png file of the current schema. EXPERIMENTAL!
+
0.016 12 March 2012
- More POD and documentation fixes (Volker++), (logie17++)
- changed the way I declare version requirements in my dist.ini filr
View
3  dist.ini
@@ -5,7 +5,7 @@ copyright_holder = John Napiorkowski
copyright_year = 2012
abstract = Make it easy to migrate DBIC based databases
-version = 0.016
+version = 0.017
[@Basic]
[Prereqs]
@@ -29,6 +29,7 @@ DBD::SQLite = 0
Pod::Parser = 1.51
Config::MySQL = 0
version = 0.77
+SQL::Translator = 0.11010
[Prereqs / TestRequires]
Test::Most = 0
View
BIN  examples/MusicBase/share/db-diagram-v3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
38 lib/DBIx/Class/Migration.pm
@@ -1,6 +1,6 @@
package DBIx::Class::Migration;
-our $VERSION = "0.016";
+our $VERSION = "0.017";
use Moose;
use JSON::XS;
@@ -10,6 +10,7 @@ use File::Path 'mkpath', 'remove_tree';
use MooseX::Types::LoadableClass 'LoadableClass';
use Class::Load 'load_class';
use Devel::PartialDump;
+use SQL::Translator;
has db_sandbox_class => (
is => 'ro',
@@ -427,6 +428,24 @@ sub make_schema {
catdir($self->target_dir, 'dumped_db'));
}
+sub diagram {
+ my $self = shift;
+ my $trans = SQL::Translator->new(
+ parser => 'SQL::Translator::Parser::DBIx::Class',
+ parser_args => { package => $self->schema },
+ producer => 'GraphViz',
+ producer_args => {
+ skip_tables => 'dbix_class_deploymenthandler_versions',
+ show_constraints => 1,
+ show_datatypes => 1,
+ show_sizes => 1,
+ out_file => catfile(
+ $self->target_dir, 'db-diagram-v' . $self->dbic_dh->schema_version . '.png')});
+
+ $trans->translate
+ or die $trans->error;
+}
+
sub install_if_needed {
my ($self, %callbacks) = @_;
if(!$self->dbic_dh->version_storage_is_installed) {
@@ -885,6 +904,23 @@ the matching sets for that version.
Skips the table C<dbix_class_deploymenthandler_versions>, so you don't lose
deployment info (this is different from L</drop_tables> which does delete it.)
+=head diagram
+
+Experimental feature. Although not specifically a migration task, I find it
+useful to output visuals of my databases. This command will place a file in
+your L</target_dir> called C<db-diagram-vXXX.png> where C<XXX> is he current
+C<schema> version.
+
+This is using the Graphviz producer (L<SQL::Translator::Producer::GraphViz>)
+which in turn requires L<Graphviz>. Since this is not always trivial to
+install, I do not require it. You will need to add it manually to your
+C<Makefile.PL> or C<dist.ini> and manage it yourself.
+
+This feature is experimental and currently does not offer any options, as I
+am still determining the best way to meet the need without exceeding the
+scope of L<DBIx::Class::Migration>. Consider this command a 'freebee' and
+please don't depend on it in your custom code.
+
=head2 install_if_needed
If the database is not installed, do so. Accepts a hash of callbacks or
View
9 lib/DBIx/Class/Migration/Script.pm
@@ -74,7 +74,7 @@ has fixture_sets => (
version status prepare install upgrade
downgrade drop_tables delete_table_rows
dump_all_sets make_schema install_if_needed
- dump );
+ dump diagram);
}
has migration_class => (
@@ -523,6 +523,13 @@ what the deployment perl run files get for schema.
Install the database to the current C<$schema> version if it is not currently
installed. Otherwise this is a nop (even if the database is behind the schema).
+=head2 diagram
+
+Experimental feature. This command will place a file in your L</target_dir>
+called C<db-diagram-vXXX.png> where C<XXX> is he current C<schema> version.
+
+This feature is experimental and currently does not offer any options.
+
=head2 Command Flags
The following flags are used to modify or inform commands.
View
20 t/00-clean.t
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+
+## Just a test class to make sure we have a nice, clean target_dir
+## in case a previous test run make a mess.
+
+use lib 't/lib';
+use Test::Most;
+use DBIx::Class::Migration::Population;
+use File::Spec::Functions 'catfile';
+use File::Path 'rmtree';
+
+ok( my $p = DBIx::Class::Migration::Population->new(schema_class=>'Local::Schema'),
+ 'created population object from schema_class');
+
+rmtree catfile($p->target_dir, 'migrations');
+rmtree catfile($p->target_dir, 'fixtures');
+unlink catfile($p->target_dir, 'local-schema.db');
+rmtree catfile($p->target_dir, 'local-schema');
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.