fix CURRENT_TIMESTAMP default for MySQL
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 11mysql_current_timestamp.t
CommitLineData
f430297e 1use strict;
2use lib qw(t/lib);
3use Test::More;
4use DBI;
5
6my $DUMP_DIR;
7BEGIN {
8 $DUMP_DIR = './t/_common_dump';
9}
10
11use lib $DUMP_DIR;
12use DBIx::Class::Schema::Loader 'make_schema_at', "dump_to_dir:$DUMP_DIR";
13use File::Path;
14use Test::Exception;
15
16my ($dsn, $user, $password) = map $ENV{"DBICTEST_MYSQL_$_"}, qw/DSN USER PASS/;
17
18if( !$dsn || !$user ) {
19 plan skip_all => 'You need to set the DBICTEST_MYSQL_DSN, _USER, and _PASS'
20 .' environment variables';
21}
22
23eval "use SQL::Translator '0.09007';";
24plan skip_all => 'SQL::Translator 0.09007 or greater required'
25 if $@;
26
27plan tests => 2;
28
29my $dbh = DBI->connect($dsn, $user, $password, {
30 RaiseError => 1, PrintError => 0
31});
32
33eval { $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
43rmtree $DUMP_DIR;
44
45make_schema_at(
46 'TestSL::Schema',
47 {
48 use_namespaces => 1,
49 constraint => qr/^loadertest\z/
50 },
51 [ $dsn, $user, $password, ]
52);
53
54lives_ok { require TestSL::Schema } 'schema loads';
55
56$dbh->do('DROP TABLE loadertest');
57
58my $schema = TestSL::Schema->connect($dsn, $user, $password);
59
60my @warnings;
61local $SIG{__WARN__} = sub { push @warnings, shift };
62
63$schema->deploy;
64
65ok (not(grep /Invalid default/, @warnings)), 'default deployed';
66diag $_ for @warnings;
67
68END {
69 rmtree $DUMP_DIR;
70 eval { $dbh->do('DROP TABLE loadertest') };
71}