Test suite now is fully parallelizable
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / deploy_methods / sql_translator_protoschema_transform.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9 use lib 't/lib';
10 use DBICDHTest;
11 use aliased 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator';
12 use File::Spec::Functions qw(catfile splitdir);
13 use File::Path qw(rmtree mkpath);
14 use File::Temp qw(tempfile tempdir);
15
16 my $dbh = DBICDHTest::dbh();
17 my @connection = (sub { $dbh }, { ignore_version => 1 });
18 my $sql_dir = tempdir( CLEANUP => 1 );
19
20 VERSION1: {
21    use_ok 'DBICVersion_v1';
22    my $s = DBICVersion::Schema->connect(@connection);
23    my $dm = Translator->new({
24       schema            => $s,
25       script_directory => $sql_dir,
26       databases         => ['SQLite'],
27       sql_translator_args          => { add_drop_table => 0 },
28    });
29
30    $dm->prepare_deploy;
31    $dm->deploy;
32 }
33
34 VERSION2: {
35    use_ok 'DBICVersion_v2';
36    my $s = DBICVersion::Schema->connect(@connection);
37    my $dm = Translator->new({
38       schema            => $s,
39       script_directory => $sql_dir,
40       databases         => ['SQLite'],
41       sql_translator_args          => { add_drop_table => 0 },
42       txn_wrap          => 1,
43    });
44
45    $dm->prepare_deploy;
46    mkpath(catfile(splitdir($sql_dir), qw(_preprocess_schema upgrade 1.0-2.0 )));
47    open my $prerun, '>',
48       catfile(splitdir($sql_dir), qw(_preprocess_schema upgrade 1.0-2.0 003-semiautomatic.pl ));
49    my (undef, $fn) = tempfile(OPEN => 0);
50    print {$prerun}
51       qq^sub {
52          open my \$fh, ">", '$fn'
53             if \$_[0]->isa("SQL::Translator::Schema")
54             && \$_[1]->isa("SQL::Translator::Schema");
55       }^;
56    close $prerun;
57    $dm->prepare_upgrade({
58      from_version => '1.0',
59      to_version => '2.0',
60      version_set => [qw(1.0 2.0)]
61    });
62    ok -e $fn, 'intermediate script ran with the right args';
63    $dm->upgrade_single_step({ version_set => [qw( 1.0 2.0 )] });
64 }
65 done_testing;
66 #vim: ts=2 sw=2 expandtab