rename vendor tests
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_02mysql_common.t
CommitLineData
a78e3fed 1use strict;
26334ec1 2use Test::More;
c2849787 3use lib qw(t/lib);
fbd83464 4use dbixcsl_common_tests;
a78e3fed 5
9e978a19 6my $dsn = $ENV{DBICTEST_MYSQL_DSN} || '';
7my $user = $ENV{DBICTEST_MYSQL_USER} || '';
8my $password = $ENV{DBICTEST_MYSQL_PASS} || '';
9my $test_innodb = $ENV{DBICTEST_MYSQL_INNODB} || 0;
a78e3fed 10
26334ec1 11my $skip_rels_msg = 'You need to set the DBICTEST_MYSQL_INNODB environment variable to test relationships.';
a78e3fed 12
fbd83464 13my $tester = dbixcsl_common_tests->new(
52bf3f26 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,
309e2aa1 20 connect_info_opts=> { on_connect_call => 'set_strict_mode' },
eb040f78 21 loader_options => { preserve_case => 1 },
8ff3a23a 22 skip_rels => $test_innodb ? 0 : $skip_rels_msg,
52bf3f26 23 no_inline_rels => 1,
24 no_implicit_rels => 1,
98857177 25 data_types => {
26 # http://dev.mysql.com/doc/refman/5.5/en/data-type-overview.html
27 # Numeric Types
26334ec1 28 'bit' => { data_type => 'bit', size => 1 },
29 'bit(11)' => { data_type => 'bit', size => 11 },
30
31 'bool' => { data_type => 'tinyint' },
32 'boolean' => { data_type => 'tinyint' },
33 'tinyint' => { data_type => 'tinyint' },
34 'tinyint unsigned'
35 => { data_type => 'tinyint', extra => { unsigned => 1 } },
36 'smallint' => { data_type => 'smallint' },
37 'smallint unsigned'
38 => { data_type => 'smallint', extra => { unsigned => 1 } },
39 'mediumint' => { data_type => 'mediumint' },
40 'mediumint unsigned'
41 => { data_type => 'mediumint', extra => { unsigned => 1 } },
42 'int' => { data_type => 'integer' },
43 'int unsigned'
44 => { data_type => 'integer', extra => { unsigned => 1 } },
45 'integer' => { data_type => 'integer' },
46 'integer unsigned'
47 => { data_type => 'integer', extra => { unsigned => 1 } },
33aa3462 48 'integer not null'
49 => { data_type => 'integer' },
26334ec1 50 'bigint' => { data_type => 'bigint' },
51 'bigint unsigned'
52 => { data_type => 'bigint', extra => { unsigned => 1 } },
53
54 'serial' => { data_type => 'bigint', is_auto_increment => 1, extra => { unsigned => 1 } },
55
56 'float' => { data_type => 'float' },
57 'float unsigned'
58 => { data_type => 'float', extra => { unsigned => 1 } },
59 'double' => { data_type => 'double precision' },
60 'double unsigned'
61 => { data_type => 'double precision', extra => { unsigned => 1 } },
98857177 62 'double precision' =>
26334ec1 63 { data_type => 'double precision' },
64 'double precision unsigned'
65 => { data_type => 'double precision', extra => { unsigned => 1 } },
66
67 # we skip 'real' because its alias depends on the 'REAL AS FLOAT' setting
68
69 'float(2)' => { data_type => 'float' },
70 'float(24)' => { data_type => 'float' },
71 'float(25)' => { data_type => 'double precision' },
72
73 'float(3,3)' => { data_type => 'float', size => [3,3] },
74 'double(3,3)' => { data_type => 'double precision', size => [3,3] },
75 'double precision(3,3)'
76 => { data_type => 'double precision', size => [3,3] },
77
78 'decimal' => { data_type => 'decimal' },
79 'decimal unsigned'
80 => { data_type => 'decimal', extra => { unsigned => 1 } },
81 'dec' => { data_type => 'decimal' },
82 'numeric' => { data_type => 'decimal' },
83 'fixed' => { data_type => 'decimal' },
84
85 'decimal(3)' => { data_type => 'decimal', size => [3,0] },
86
87 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] },
88 'dec(3,3)' => { data_type => 'decimal', size => [3,3] },
89 'numeric(3,3)' => { data_type => 'decimal', size => [3,3] },
90 'fixed(3,3)' => { data_type => 'decimal', size => [3,3] },
91
98857177 92 # Date and Time Types
58333f16 93 'date' => { data_type => 'date', datetime_undef_if_invalid => 1 },
94 'datetime' => { data_type => 'datetime', datetime_undef_if_invalid => 1 },
6e566cc4 95 'timestamp default current_timestamp'
58333f16 96 => { data_type => 'timestamp', default_value => \'current_timestamp', datetime_undef_if_invalid => 1 },
26334ec1 97 'time' => { data_type => 'time' },
98 'year' => { data_type => 'year' },
99 'year(4)' => { data_type => 'year' },
100 'year(2)' => { data_type => 'year', size => 2 },
101
98857177 102 # String Types
26334ec1 103 'char' => { data_type => 'char', size => 1 },
104 'char(11)' => { data_type => 'char', size => 11 },
105 'varchar(20)' => { data_type => 'varchar', size => 20 },
106 'binary' => { data_type => 'binary', size => 1 },
107 'binary(11)' => { data_type => 'binary', size => 11 },
108 'varbinary(20)'=> { data_type => 'varbinary', size => 20 },
109
110 'tinyblob' => { data_type => 'tinyblob' },
111 'tinytext' => { data_type => 'tinytext' },
112 'blob' => { data_type => 'blob' },
113
114 # text(M) types will map to the appropriate type, length is not stored
115 'text' => { data_type => 'text' },
116
117 'mediumblob' => { data_type => 'mediumblob' },
118 'mediumtext' => { data_type => 'mediumtext' },
119 'longblob' => { data_type => 'longblob' },
120 'longtext' => { data_type => 'longtext' },
121
33aa3462 122 "enum('foo','bar','baz')"
26334ec1 123 => { data_type => 'enum', extra => { list => [qw/foo bar baz/] } },
33aa3462 124 "set('foo','bar','baz')"
26334ec1 125 => { data_type => 'set', extra => { list => [qw/foo bar baz/] } },
98857177 126 },
3de915bc 127 extra => {
128 create => [
129 q{
130 CREATE TABLE mysql_loader_test1 (
131 id INT AUTO_INCREMENT PRIMARY KEY,
132 value varchar(100)
133 )
134 },
135 q{
136 CREATE VIEW mysql_loader_test2 AS SELECT * FROM mysql_loader_test1
137 },
138 ],
139 pre_drop_ddl => [ 'DROP VIEW mysql_loader_test2', ],
140 drop => [ 'mysql_loader_test1', ],
141 count => 1,
142 run => sub {
143 my ($schema, $monikers, $classes) = @_;
144
145 my $rsrc = $schema->resultset($monikers->{mysql_loader_test2})->result_source;
146
147 is $rsrc->column_info('value')->{data_type}, 'varchar',
148 'view introspected successfully';
149 },
150 },
a78e3fed 151);
152
9e978a19 153if( !$dsn || !$user ) {
154 $tester->skip_tests('You need to set the DBICTEST_MYSQL_DSN, _USER, and _PASS environment variables');
a78e3fed 155}
156else {
26334ec1 157 diag $skip_rels_msg if not $test_innodb;
a78e3fed 158 $tester->run_tests();
159}
26334ec1 160
161# vim:et sts=4 sw=4 tw=0: