Test suite now is fully parallelizable
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / deploy_methods / sql_translator_protoschema_transform.t
CommitLineData
f9c6ab50 1#!perl
2
cbbd1b5f 3use strict;
4use warnings;
5
f9c6ab50 6use Test::More;
7use Test::Exception;
8
9use lib 't/lib';
10use DBICDHTest;
11use aliased 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator';
7b3d00f9 12use File::Spec::Functions qw(catfile splitdir);
f9c6ab50 13use File::Path qw(rmtree mkpath);
7b3d00f9 14use File::Temp qw(tempfile tempdir);
f9c6ab50 15
f3b5161e 16my $dbh = DBICDHTest::dbh();
624e3018 17my @connection = (sub { $dbh }, { ignore_version => 1 });
7b3d00f9 18my $sql_dir = tempdir( CLEANUP => 1 );
f9c6ab50 19
20VERSION1: {
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
34VERSION2: {
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
f9c6ab50 45 $dm->prepare_deploy;
7b3d00f9 46 mkpath(catfile(splitdir($sql_dir), qw(_preprocess_schema upgrade 1.0-2.0 )));
f9c6ab50 47 open my $prerun, '>',
7b3d00f9 48 catfile(splitdir($sql_dir), qw(_preprocess_schema upgrade 1.0-2.0 003-semiautomatic.pl ));
2dfc27ba 49 my (undef, $fn) = tempfile(OPEN => 0);
f9c6ab50 50 print {$prerun}
2dfc27ba 51 qq^sub {
52 open my \$fh, ">", '$fn'
53 if \$_[0]->isa("SQL::Translator::Schema")
54 && \$_[1]->isa("SQL::Translator::Schema");
55 }^;
f9c6ab50 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 });
2dfc27ba 62 ok -e $fn, 'intermediate script ran with the right args';
f9c6ab50 63 $dm->upgrade_single_step({ version_set => [qw( 1.0 2.0 )] });
64}
65done_testing;
66#vim: ts=2 sw=2 expandtab