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