DBIx-Class-DeploymentHandler
view release on metacpan or search on metacpan
t/deploy_methods/sql_translator.t view on Meta::CPAN
#!perl
use strict;
use warnings;
use Test::More;
use Test::Fatal qw(lives_ok dies_ok);
use lib 't/lib';
use DBICDHTest;
use aliased 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator';
use Path::Class qw(dir file);
use File::Temp qw(tempfile tempdir);
my $dbh = DBICDHTest::dbh();
my @connection = (sub { $dbh }, { ignore_version => 1 });
my $sql_dir = tempdir( CLEANUP => 1 );
my (undef, $stuffthatran_fn) = tempfile(OPEN => 0);
for (qw(initialize upgrade downgrade deploy)) {
dir($sql_dir, '_common', $_, '_any')->mkpath;
open my $fh, '>',
file($sql_dir, '_common', $_, qw(_any 000-win.pl ));
print {$fh} qq^sub {open my \$fh, ">>", '$stuffthatran_fn'; use Data::Dumper::Concise; print {\$fh} join(",", \@{\$_[1]||[]}) . "\\n"; }^;
close $fh;
}
for (qw(initialize upgrade downgrade deploy)) {
dir($sql_dir, 'SQLite', $_, '_any')->mkpath;
open my $fh, '>',
file($sql_dir, 'SQLite', $_, qw(_any 000-win2.pl ));
print {$fh} qq^sub {open my \$fh, ">>", '$stuffthatran_fn'; use Data::Dumper::Concise; print {\$fh} join(",", \@{\$_[1]||[]}) . "\\n"; }^;
close $fh;
}
VERSION1: {
use_ok 'DBICVersion_v1';
my $s = DBICVersion::Schema->connect(@connection);
my $dm = Translator->new({
schema => $s,
script_directory => $sql_dir,
databases => ['SQLite'],
sql_translator_args => { add_drop_table => 0 },
});
ok( $dm, 'DBIC::DH::DM::SQL::Translator gets instantiated correctly' );
$dm->prepare_deploy;
dir($sql_dir, qw(SQLite initialize 1.0 ))->mkpath;
open my $prerun, '>',
file($sql_dir, qw(SQLite initialize 1.0 003-semiautomatic.pl ));
my (undef, $fn) = tempfile(OPEN => 0);
print {$prerun} "sub { open my \$fh, '>', '$fn'}";
close $prerun;
$dm->initialize({ version => '1.0' });
ok -e $fn, 'code got run in preinit';
dies_ok {$dm->prepare_deploy} 'prepare_deploy dies if you run it twice' ;
ok(
-f file($sql_dir, qw(SQLite deploy 1.0 001-auto.sql )),
'1.0 schema gets generated properly'
);
dies_ok {
( run in 0.829 second using v1.01-cache-2.11-cpan-54e63673c56 )