better type info for MySQL
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 11mysql_common.t
1 use strict;
2 use Test::More;
3 use lib qw(t/lib);
4 use dbixcsl_common_tests;
5
6 my $dsn         = $ENV{DBICTEST_MYSQL_DSN} || '';
7 my $user        = $ENV{DBICTEST_MYSQL_USER} || '';
8 my $password    = $ENV{DBICTEST_MYSQL_PASS} || '';
9 my $test_innodb = $ENV{DBICTEST_MYSQL_INNODB} || 0;
10
11 my $skip_rels_msg = 'You need to set the DBICTEST_MYSQL_INNODB environment variable to test relationships.';
12
13 my $tester = dbixcsl_common_tests->new(
14     vendor           => 'Mysql',
15     auto_inc_pk      => 'INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT',
16     innodb           => $test_innodb ? q{Engine=InnoDB} : 0,
17     dsn              => $dsn,
18     user             => $user,
19     password         => $password,
20     connect_info_opts=> { on_connect_call => 'set_strict_mode' },
21     skip_rels        => $test_innodb ? 0 : 1,
22     no_inline_rels   => 1,
23     no_implicit_rels => 1,
24     data_types  => {
25         # http://dev.mysql.com/doc/refman/5.5/en/data-type-overview.html
26         # Numeric Types
27         'bit'         => { data_type => 'bit', size => 1 },
28         'bit(11)'     => { data_type => 'bit', size => 11 },
29
30         'bool'        => { data_type => 'tinyint' },
31         'boolean'     => { data_type => 'tinyint' },
32         'tinyint'     => { data_type => 'tinyint' },
33         'tinyint unsigned'
34                       => { data_type => 'tinyint',   extra => { unsigned => 1 } },
35         'smallint'    => { data_type => 'smallint' },
36         'smallint unsigned'
37                       => { data_type => 'smallint',  extra => { unsigned => 1 } },
38         'mediumint'   => { data_type => 'mediumint' },
39         'mediumint unsigned'
40                       => { data_type => 'mediumint', extra => { unsigned => 1 } },
41         'int'         => { data_type => 'integer' },
42         'int unsigned'
43                       => { data_type => 'integer',   extra => { unsigned => 1 } },
44         'integer'     => { data_type => 'integer' },
45         'integer unsigned'
46                       => { data_type => 'integer',   extra => { unsigned => 1 } },
47         'bigint'      => { data_type => 'bigint' },
48         'bigint unsigned'
49                       => { data_type => 'bigint',    extra => { unsigned => 1 } },
50
51         'serial'      => { data_type => 'bigint', is_auto_increment => 1, extra => { unsigned => 1 } },
52
53         'float'       => { data_type => 'float' },
54         'float unsigned'
55                       => { data_type => 'float',     extra => { unsigned => 1 } },
56         'double'      => { data_type => 'double precision' },
57         'double unsigned'
58                       => { data_type => 'double precision', extra => { unsigned => 1 } },
59         'double precision' =>
60                          { data_type => 'double precision' },
61         'double precision unsigned'
62                       => { data_type => 'double precision', extra => { unsigned => 1 } },
63
64         # we skip 'real' because its alias depends on the 'REAL AS FLOAT' setting
65
66         'float(2)'    => { data_type => 'float' },
67         'float(24)'   => { data_type => 'float' },
68         'float(25)'   => { data_type => 'double precision' },
69
70         'float(3,3)'  => { data_type => 'float', size => [3,3] },
71         'double(3,3)' => { data_type => 'double precision', size => [3,3] },
72         'double precision(3,3)'
73                       => { data_type => 'double precision', size => [3,3] },
74
75         'decimal'     => { data_type => 'decimal' },
76         'decimal unsigned'
77                       => { data_type => 'decimal', extra => { unsigned => 1 } },
78         'dec'         => { data_type => 'decimal' },
79         'numeric'     => { data_type => 'decimal' },
80         'fixed'       => { data_type => 'decimal' },
81
82         'decimal(3)'   => { data_type => 'decimal', size => [3,0] },
83
84         'decimal(3,3)' => { data_type => 'decimal', size => [3,3] },
85         'dec(3,3)'     => { data_type => 'decimal', size => [3,3] },
86         'numeric(3,3)' => { data_type => 'decimal', size => [3,3] },
87         'fixed(3,3)'   => { data_type => 'decimal', size => [3,3] },
88
89         # Date and Time Types
90         'date'        => { data_type => 'date' },
91         'datetime'    => { data_type => 'datetime' },
92         'timestamp DEFAULT current_timestamp'
93                       => { data_type => 'timestamp', default_value => \"CURRENT_TIMESTAMP" },
94         'time'        => { data_type => 'time' },
95         'year'        => { data_type => 'year' },
96         'year(4)'     => { data_type => 'year' },
97         'year(2)'     => { data_type => 'year', size => 2 },
98
99         # String Types
100         'char'         => { data_type => 'char',      size => 1  },
101         'char(11)'     => { data_type => 'char',      size => 11 },
102         'varchar(20)'  => { data_type => 'varchar',   size => 20 },
103         'binary'       => { data_type => 'binary',    size => 1  },
104         'binary(11)'   => { data_type => 'binary',    size => 11 },
105         'varbinary(20)'=> { data_type => 'varbinary', size => 20 },
106
107         'tinyblob'    => { data_type => 'tinyblob' },
108         'tinytext'    => { data_type => 'tinytext' },
109         'blob'        => { data_type => 'blob' },
110
111         # text(M) types will map to the appropriate type, length is not stored
112         'text'        => { data_type => 'text' },
113
114         'mediumblob'  => { data_type => 'mediumblob' },
115         'mediumtext'  => { data_type => 'mediumtext' },
116         'longblob'    => { data_type => 'longblob' },
117         'longtext'    => { data_type => 'longtext' },
118
119         "enum('foo', 'bar', 'baz')"
120                       => { data_type => 'enum', extra => { list => [qw/foo bar baz/] } },
121         "set('foo', 'bar', 'baz')"
122                       => { data_type => 'set',  extra => { list => [qw/foo bar baz/] } },
123     },
124 );
125
126 if( !$dsn || !$user ) {
127     $tester->skip_tests('You need to set the DBICTEST_MYSQL_DSN, _USER, and _PASS environment variables');
128 }
129 else {
130     diag $skip_rels_msg if not $test_innodb;
131     $tester->run_tests();
132 }
133
134 # vim:et sts=4 sw=4 tw=0: