64c2438e14feffd7576b321e899f7624f6bd2f88
[dbsrgits/DBIx-Class-Historic.git] / t / storage / deploy.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'deploy';
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8 use Test::Exception;
9 use Path::Class qw/dir/;
10
11
12 use DBICTest;
13
14 local $ENV{DBI_DSN};
15
16 # this is how maint/gen_schema did it (connect() to force a storage
17 # instance, but no conninfo)
18 # there ought to be more code like this in the wild
19 like(
20   DBICTest::Schema->connect->deployment_statements('SQLite'),
21   qr/\bCREATE TABLE artist\b/i  # ensure quoting *is* disabled
22 );
23
24 lives_ok( sub {
25     my $parse_schema = DBICTest->init_schema(no_deploy => 1);
26     $parse_schema->deploy({},'t/lib/test_deploy');
27     $parse_schema->resultset("Artist")->all();
28 }, 'artist table deployed correctly' );
29
30 my $schema = DBICTest->init_schema( quote_names => 1 );
31
32 my $var = dir ("t/var/ddl_dir-$$");
33 $var->mkpath unless -d $var;
34
35 my $test_dir_1 = $var->subdir ('test1', 'foo', 'bar' );
36 $test_dir_1->rmtree if -d $test_dir_1;
37 $schema->create_ddl_dir( [qw(SQLite MySQL)], 1, $test_dir_1 );
38
39 ok( -d $test_dir_1, 'create_ddl_dir did a make_path on its target dir' );
40 ok( scalar( glob $test_dir_1.'/*.sql' ), 'there are sql files in there' );
41
42 my $less = $schema->clone;
43 $less->unregister_source('BindType');
44 $less->create_ddl_dir( [qw(SQLite MySQL)], 2, $test_dir_1, 1 );
45
46 for (
47   [ SQLite => '"' ],
48   [ MySQL => '`' ],
49 ) {
50   my $type = $_->[0];
51   my $q = quotemeta($_->[1]);
52
53   for my $f (map { $test_dir_1->file("DBICTest-Schema-${_}-$type.sql") } qw(1 2) ) {
54     like scalar $f->slurp, qr/CREATE TABLE ${q}track${q}/, "Proper quoting in $f";
55   }
56
57   {
58     local $TODO = 'SQLT::Producer::MySQL has no knowledge of the mythical beast of quoting...'
59       if $type eq 'MySQL';
60
61     my $f = $test_dir_1->file("DBICTest-Schema-1-2-$type.sql");
62     like scalar $f->slurp, qr/DROP TABLE ${q}bindtype_test${q}/, "Proper quoting in diff $f";
63   }
64 }
65
66 {
67   local $TODO = 'we should probably add some tests here for actual deployability of the DDL?';
68   ok( 0 );
69 }
70
71 END {
72   $var->rmtree;
73 }
74
75 done_testing;