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