Skip to content

Commit

Permalink
coerce target_dir to absolute to work right on 5.26+ - fix #96
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Feb 25, 2019
1 parent f8ed661 commit 3b6f242
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Revision history for DBIx-Class-Migration.
- update DBIx::Class::DeploymentHandler dep to 0.002222 - thanks @KES777 for report
- POD improvements - thanks @manwar
- use Log::Any for errors - thanks @upasana-me
- coerce target_dir to absolute to work right on 5.26+

0.061 2019-02-25
- POD improvements - thanks @n7st and @willsheppard
Expand Down
7 changes: 5 additions & 2 deletions lib/DBIx/Class/Migration.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use JSON::MaybeXS qw(JSON);
use File::Copy 'cp';
use File::Spec::Functions 'catdir', 'catfile', 'updir';
use File::Path 'mkpath', 'remove_tree';
use DBIx::Class::Migration::Types 'LoadableClass', 'LoadableDBICSchemaClass';
use DBIx::Class::Migration::Types qw(
LoadableClass LoadableDBICSchemaClass
AbsolutePath
);
use Class::Load 'load_class';
use Devel::PartialDump;
use SQL::Translator;
Expand Down Expand Up @@ -99,7 +102,7 @@ has target_dir_builder => ( is => 'ro', lazy_build => 1);
->new(schema_class=>$inferred_schema_class);
}

has target_dir => (is=>'ro', isa=>'Str', lazy_build=>1);
has target_dir => (is => 'ro', isa=> AbsolutePath, coerce => 1, lazy_build=>1);

sub _build_target_dir {
shift->target_dir_builder->build;
Expand Down
7 changes: 5 additions & 2 deletions lib/DBIx/Class/Migration/Script.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use Moose;
use MooseX::Attribute::ENV;
use Pod::Find ();
use Pod::Usage ();
use DBIx::Class::Migration::Types 'LoadableClass', 'ArraySQLTProducers';
use DBIx::Class::Migration::Types qw(
LoadableClass ArraySQLTProducers AbsolutePath
);
use Log::Any;
use Carp 'croak';

Expand Down Expand Up @@ -45,7 +47,8 @@ has schema => (is=>'ro', predicate=>'has_schema');
has schema_class => (traits => [ 'Getopt', 'ENV' ], is => 'ro', isa => 'Str',
predicate=>'has_schema_class', env_prefix=>ENV_PREFIX, cmd_aliases => 'S');

has target_dir => (traits => [ 'Getopt', 'ENV' ], is => 'ro', isa=> 'Str',
has target_dir => (traits => [ 'Getopt', 'ENV' ],
is => 'ro', isa=> AbsolutePath, coerce => 1,
predicate=>'has_target_dir', env_prefix=>ENV_PREFIX, cmd_aliases => 'dir');

has sandbox_dir => (traits => [ 'Getopt', 'ENV' ], is => 'ro', isa=> 'Str',
Expand Down
16 changes: 15 additions & 1 deletion lib/DBIx/Class/Migration/Types.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ package #hide from PAUSE

use MooseX::Types::LoadableClass 'LoadableClass';
use MooseX::Types::Moose 'Str', 'ClassName', 'ArrayRef';
use MooseX::Types -declare => [ 'LoadableDBICSchemaClass', 'SQLTProducer', 'ArraySQLTProducers' ];
use MooseX::Types -declare => [
'LoadableDBICSchemaClass',
'SQLTProducer', 'ArraySQLTProducers',
'AbsolutePath',
];
use Module::Find ();
use MooseX::Getopt::OptionTypeMap ();
use File::Spec::Functions 'file_name_is_absolute', 'rel2abs';

subtype LoadableDBICSchemaClass,
as LoadableClass,
Expand Down Expand Up @@ -48,6 +53,15 @@ MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
ArraySQLTProducers() => '=s@'
);

subtype AbsolutePath,
as Str,
where { file_name_is_absolute $_ },
;
coerce AbsolutePath,
from Str,
via { rel2abs $_ },
;

1;

=head1 NAME
Expand Down
3 changes: 1 addition & 2 deletions t/migration-postgresql.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ use File::Spec::Functions 'catfile';
use File::Path 'rmtree';
use Test::Requires qw(Test::Postgresql58);
use File::Temp 'tempdir';
use Cwd 'abs_path'; # if no abs_path, need "." in @INC

my $dir = tempdir(DIR => abs_path('t'), CLEANUP => 1);
my $dir = tempdir(DIR => 't', CLEANUP => 1);

ok(
my $migration = DBIx::Class::Migration->new(
Expand Down
3 changes: 1 addition & 2 deletions t/migration-sqlite.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use DBIx::Class::Migration;
use File::Spec::Functions 'catfile';
use File::Path 'rmtree';
use File::Temp 'tempdir';
use Cwd 'abs_path'; # if no abs_path, need "." in @INC

my $dir = tempdir(DIR => abs_path('t'), CLEANUP => 1);
my $dir = tempdir(DIR => 't', CLEANUP => 1);

ok(
my $migration = DBIx::Class::Migration->new(
Expand Down
3 changes: 1 addition & 2 deletions t/upgrade-downgrade-sqlite.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use Test::Most;
use DBIx::Class::Migration;
use File::Spec::Functions 'catfile';
use File::Temp 'tempdir';
use Cwd 'abs_path'; # if no abs_path, need "." in @INC

my $dir = tempdir(DIR => abs_path('t'), CLEANUP => 1);
my $dir = tempdir(DIR => 't', CLEANUP => 1);

my ($target_dir, $schema_args); # Outer Scope so we can reuse

Expand Down

0 comments on commit 3b6f242

Please sign in to comment.