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