From: Arthur Axel 'fREW' Schmidt Date: Tue, 23 Feb 2010 05:29:12 +0000 (-0600) Subject: initial gutting of create_ddl_dir interface X-Git-Tag: v0.001000_01~143 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9e401dc2315997fa9bded6a727329fae7924d8dd;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git initial gutting of create_ddl_dir interface --- diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index b1c525e..52fabeb 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -62,6 +62,13 @@ has version_rs => ( handles => [qw( is_installed db_version )], ); +has databases => ( + # make this coerce from Str + isa => 'ArrayRef[Str]', + is => 'ro', + default => sub { [qw( MySQL SQLite PostgreSQL )] }, +); + method _build_version_rs { $self->schema->set_us_up_the_bomb; $self->schema->resultset('__VERSION') @@ -164,14 +171,14 @@ method upgrade_single_step($db_version, $target_version) { }); } -method create_ddl_dir($databases, $version, $dir, $preversion, $sqltargs) { +method create_ddl_dir($version, $preversion, $sqltargs) { my $schema = $self->schema; - if(!$dir || !-d $dir) { - carp "No directory given, using ./\n"; + my $databases = $self->databases; + my $dir = $self->upgrade_directory; + unless( -d $dir ) { + carp "Upgrade directory $dir does not exist, using ./\n"; $dir = "./"; } - $databases ||= ['MySQL', 'SQLite', 'PostgreSQL']; - $databases = [ $databases ] if(ref($databases) ne 'ARRAY'); my $schema_version = $schema->schema_version || '1.x'; $version ||= $schema_version; diff --git a/t/02-instantiation.t b/t/02-instantiation.t index 9765eff..6053739 100644 --- a/t/02-instantiation.t +++ b/t/02-instantiation.t @@ -16,12 +16,13 @@ VERSION1: { my $handler = DBIx::Class::DeploymentHandler->new({ upgrade_directory => $sql_dir, schema => $s, + databases => ['SQLite'], }); ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly'); my $version = $s->schema_version(); - $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0); + $handler->create_ddl_dir( $version, 0); ok(-e 't/sql/DBICVersion-Schema-1.0-SQLite.sql', 'DDL for 1.0 got created successfully'); dies_ok { @@ -44,13 +45,14 @@ VERSION2: { my $handler = DBIx::Class::DeploymentHandler->new({ upgrade_directory => $sql_dir, schema => $s, + databases => ['SQLite'], }); ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly'); $version = $s->schema_version(); - $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0); - $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '1.0'); + $handler->create_ddl_dir($version, 0); + $handler->create_ddl_dir($version, '1.0'); ok(-e 't/sql/DBICVersion-Schema-2.0-SQLite.sql', 'DDL for 2.0 got created successfully'); ok(-e 't/sql/DBICVersion-Schema-1.0-2.0-SQLite.sql', 'DDL for migration from 1.0 to 2.0 got created successfully'); dies_ok { @@ -82,14 +84,15 @@ VERSION3: { my $handler = DBIx::Class::DeploymentHandler->new({ upgrade_directory => $sql_dir, schema => $s, + databases => ['SQLite'], }); ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly'); $version = $s->schema_version(); - $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0); - $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '1.0'); - $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '2.0'); + $handler->create_ddl_dir( $version, 0); + $handler->create_ddl_dir( $version, '1.0'); + $handler->create_ddl_dir( $version, '2.0'); ok(-e 't/sql/DBICVersion-Schema-3.0-SQLite.sql', 'DDL for 3.0 got created successfully'); ok(-e 't/sql/DBICVersion-Schema-1.0-3.0-SQLite.sql', 'DDL for migration from 1.0 to 3.0 got created successfully'); ok(-e 't/sql/DBICVersion-Schema-2.0-3.0-SQLite.sql', 'DDL for migration from 2.0 to 3.0 got created successfully');