Commit | Line | Data |
f430297e |
1 | use strict; |
2 | use lib qw(t/lib); |
3 | use Test::More; |
4 | use DBI; |
5 | |
6 | my $DUMP_DIR; |
7 | BEGIN { |
8 | $DUMP_DIR = './t/_common_dump'; |
9 | } |
10 | |
11 | use lib $DUMP_DIR; |
12 | use DBIx::Class::Schema::Loader 'make_schema_at', "dump_to_dir:$DUMP_DIR"; |
13 | use File::Path; |
14 | use Test::Exception; |
15 | |
16 | my ($dsn, $user, $password) = map $ENV{"DBICTEST_MYSQL_$_"}, qw/DSN USER PASS/; |
17 | |
18 | if( !$dsn || !$user ) { |
19 | plan skip_all => 'You need to set the DBICTEST_MYSQL_DSN, _USER, and _PASS' |
20 | .' environment variables'; |
21 | } |
22 | |
23 | eval "use SQL::Translator '0.09007';"; |
24 | plan skip_all => 'SQL::Translator 0.09007 or greater required' |
25 | if $@; |
26 | |
27 | plan tests => 2; |
28 | |
29 | my $dbh = DBI->connect($dsn, $user, $password, { |
30 | RaiseError => 1, PrintError => 0 |
31 | }); |
32 | |
33 | eval { $dbh->do('DROP TABLE loadertest') }; |
34 | $dbh->do(q{ |
35 | CREATE TABLE loadertest ( |
36 | id INT PRIMARY KEY, |
37 | somedate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, |
38 | somestr VARCHAR(100) NOT NULL DEFAULT 'foo' |
39 | ) Engine=InnoDB |
40 | }); |
41 | # XXX there needs to be code to distinguish these two types of defaults |
42 | |
43 | rmtree $DUMP_DIR; |
44 | |
45 | make_schema_at( |
46 | 'TestSL::Schema', |
47 | { |
48 | use_namespaces => 1, |
49 | constraint => qr/^loadertest\z/ |
50 | }, |
51 | [ $dsn, $user, $password, ] |
52 | ); |
53 | |
54 | lives_ok { require TestSL::Schema } 'schema loads'; |
55 | |
56 | $dbh->do('DROP TABLE loadertest'); |
57 | |
58 | my $schema = TestSL::Schema->connect($dsn, $user, $password); |
59 | |
60 | my @warnings; |
61 | local $SIG{__WARN__} = sub { push @warnings, shift }; |
62 | |
63 | $schema->deploy; |
64 | |
65 | ok (not(grep /Invalid default/, @warnings)), 'default deployed'; |
66 | diag $_ for @warnings; |
67 | |
68 | END { |
69 | rmtree $DUMP_DIR; |
70 | eval { $dbh->do('DROP TABLE loadertest') }; |
71 | } |