introspect ON DELETE/UPDATE clauses for MySQL FKs
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_02mysql_common.t
CommitLineData
a78e3fed 1use strict;
c4a69b87 2use warnings;
26334ec1 3use Test::More;
c4a69b87 4use Test::Exception;
5use Try::Tiny;
6use File::Path 'rmtree';
7use DBIx::Class::Schema::Loader::Utils 'slurp_file';
8use DBIx::Class::Schema::Loader 'make_schema_at';
9
c2849787 10use lib qw(t/lib);
c4a69b87 11
fbd83464 12use dbixcsl_common_tests;
c4a69b87 13use dbixcsl_test_dir '$tdir';
14
15use constant EXTRA_DUMP_DIR => "$tdir/mysql_extra_dump";
a78e3fed 16
9e978a19 17my $dsn = $ENV{DBICTEST_MYSQL_DSN} || '';
18my $user = $ENV{DBICTEST_MYSQL_USER} || '';
19my $password = $ENV{DBICTEST_MYSQL_PASS} || '';
20my $test_innodb = $ENV{DBICTEST_MYSQL_INNODB} || 0;
a78e3fed 21
c4a69b87 22my $skip_rels_msg = 'You need to set the environment variable DBICTEST_MYSQL_INNODB=1 to test relationships.';
a78e3fed 23
e00d61ac 24my $innodb = $test_innodb ? q{Engine=InnoDB} : '';
25
c4a69b87 26my ($schema, $databases_created); # for cleanup in END for extra tests
27
fbd83464 28my $tester = dbixcsl_common_tests->new(
52bf3f26 29 vendor => 'Mysql',
30 auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT',
e00d61ac 31 innodb => $innodb,
52bf3f26 32 dsn => $dsn,
33 user => $user,
34 password => $password,
309e2aa1 35 connect_info_opts=> { on_connect_call => 'set_strict_mode' },
eb040f78 36 loader_options => { preserve_case => 1 },
8ff3a23a 37 skip_rels => $test_innodb ? 0 : $skip_rels_msg,
6ebd0f33 38 quote_char => '`',
52bf3f26 39 no_inline_rels => 1,
40 no_implicit_rels => 1,
98857177 41 data_types => {
42 # http://dev.mysql.com/doc/refman/5.5/en/data-type-overview.html
43 # Numeric Types
26334ec1 44 'bit' => { data_type => 'bit', size => 1 },
45 'bit(11)' => { data_type => 'bit', size => 11 },
46
47 'bool' => { data_type => 'tinyint' },
48 'boolean' => { data_type => 'tinyint' },
49 'tinyint' => { data_type => 'tinyint' },
50 'tinyint unsigned'
51 => { data_type => 'tinyint', extra => { unsigned => 1 } },
52 'smallint' => { data_type => 'smallint' },
53 'smallint unsigned'
54 => { data_type => 'smallint', extra => { unsigned => 1 } },
55 'mediumint' => { data_type => 'mediumint' },
56 'mediumint unsigned'
57 => { data_type => 'mediumint', extra => { unsigned => 1 } },
58 'int' => { data_type => 'integer' },
59 'int unsigned'
60 => { data_type => 'integer', extra => { unsigned => 1 } },
61 'integer' => { data_type => 'integer' },
62 'integer unsigned'
63 => { data_type => 'integer', extra => { unsigned => 1 } },
33aa3462 64 'integer not null'
65 => { data_type => 'integer' },
26334ec1 66 'bigint' => { data_type => 'bigint' },
67 'bigint unsigned'
68 => { data_type => 'bigint', extra => { unsigned => 1 } },
69
70 'serial' => { data_type => 'bigint', is_auto_increment => 1, extra => { unsigned => 1 } },
71
72 'float' => { data_type => 'float' },
73 'float unsigned'
74 => { data_type => 'float', extra => { unsigned => 1 } },
75 'double' => { data_type => 'double precision' },
76 'double unsigned'
77 => { data_type => 'double precision', extra => { unsigned => 1 } },
98857177 78 'double precision' =>
26334ec1 79 { data_type => 'double precision' },
80 'double precision unsigned'
81 => { data_type => 'double precision', extra => { unsigned => 1 } },
82
83 # we skip 'real' because its alias depends on the 'REAL AS FLOAT' setting
84
85 'float(2)' => { data_type => 'float' },
86 'float(24)' => { data_type => 'float' },
87 'float(25)' => { data_type => 'double precision' },
88
89 'float(3,3)' => { data_type => 'float', size => [3,3] },
90 'double(3,3)' => { data_type => 'double precision', size => [3,3] },
91 'double precision(3,3)'
92 => { data_type => 'double precision', size => [3,3] },
93
94 'decimal' => { data_type => 'decimal' },
95 'decimal unsigned'
96 => { data_type => 'decimal', extra => { unsigned => 1 } },
97 'dec' => { data_type => 'decimal' },
98 'numeric' => { data_type => 'decimal' },
99 'fixed' => { data_type => 'decimal' },
100
101 'decimal(3)' => { data_type => 'decimal', size => [3,0] },
102
103 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] },
104 'dec(3,3)' => { data_type => 'decimal', size => [3,3] },
105 'numeric(3,3)' => { data_type => 'decimal', size => [3,3] },
106 'fixed(3,3)' => { data_type => 'decimal', size => [3,3] },
107
98857177 108 # Date and Time Types
58333f16 109 'date' => { data_type => 'date', datetime_undef_if_invalid => 1 },
110 'datetime' => { data_type => 'datetime', datetime_undef_if_invalid => 1 },
6e566cc4 111 'timestamp default current_timestamp'
58333f16 112 => { data_type => 'timestamp', default_value => \'current_timestamp', datetime_undef_if_invalid => 1 },
26334ec1 113 'time' => { data_type => 'time' },
114 'year' => { data_type => 'year' },
115 'year(4)' => { data_type => 'year' },
116 'year(2)' => { data_type => 'year', size => 2 },
117
98857177 118 # String Types
26334ec1 119 'char' => { data_type => 'char', size => 1 },
120 'char(11)' => { data_type => 'char', size => 11 },
121 'varchar(20)' => { data_type => 'varchar', size => 20 },
122 'binary' => { data_type => 'binary', size => 1 },
123 'binary(11)' => { data_type => 'binary', size => 11 },
124 'varbinary(20)'=> { data_type => 'varbinary', size => 20 },
125
126 'tinyblob' => { data_type => 'tinyblob' },
127 'tinytext' => { data_type => 'tinytext' },
128 'blob' => { data_type => 'blob' },
129
130 # text(M) types will map to the appropriate type, length is not stored
131 'text' => { data_type => 'text' },
132
133 'mediumblob' => { data_type => 'mediumblob' },
134 'mediumtext' => { data_type => 'mediumtext' },
135 'longblob' => { data_type => 'longblob' },
136 'longtext' => { data_type => 'longtext' },
137
33aa3462 138 "enum('foo','bar','baz')"
26334ec1 139 => { data_type => 'enum', extra => { list => [qw/foo bar baz/] } },
e00d61ac 140 "enum('foo \\'bar\\' baz', 'foo ''bar'' quux')"
141 => { data_type => 'enum', extra => { list => [q{foo 'bar' baz}, q{foo 'bar' quux}] } },
142 "set('foo \\'bar\\' baz', 'foo ''bar'' quux')"
143 => { data_type => 'set', extra => { list => [q{foo 'bar' baz}, q{foo 'bar' quux}] } },
33aa3462 144 "set('foo','bar','baz')"
26334ec1 145 => { data_type => 'set', extra => { list => [qw/foo bar baz/] } },
698c11d8 146
147 # RT#68717
148 "enum('11,10 (<500)/0 DUN','4,90 (<120)/0 EUR') NOT NULL default '11,10 (<500)/0 DUN'"
149 => { data_type => 'enum', extra => { list => ['11,10 (<500)/0 DUN', '4,90 (<120)/0 EUR'] }, default_value => '11,10 (<500)/0 DUN' },
150 "set('11_10 (<500)/0 DUN','4_90 (<120)/0 EUR') NOT NULL default '11_10 (<500)/0 DUN'"
151 => { data_type => 'set', extra => { list => ['11_10 (<500)/0 DUN', '4_90 (<120)/0 EUR'] }, default_value => '11_10 (<500)/0 DUN' },
0da287c8 152 "enum('19,90 (<500)/0 EUR','4,90 (<120)/0 EUR','7,90 (<200)/0 CHF','300 (<6000)/0 CZK','4,90 (<100)/0 EUR','39 (<900)/0 DKK','299 (<5000)/0 EEK','9,90 (<250)/0 EUR','3,90 (<100)/0 GBP','3000 (<70000)/0 HUF','4000 (<70000)/0 JPY','13,90 (<200)/0 LVL','99 (<2500)/0 NOK','39 (<1000)/0 PLN','1000 (<20000)/0 RUB','49 (<2500)/0 SEK','29 (<600)/0 USD','19,90 (<600)/0 EUR','0 EUR','0 CHF') NOT NULL default '19,90 (<500)/0 EUR'"
153 => { data_type => 'enum', extra => { list => ['19,90 (<500)/0 EUR','4,90 (<120)/0 EUR','7,90 (<200)/0 CHF','300 (<6000)/0 CZK','4,90 (<100)/0 EUR','39 (<900)/0 DKK','299 (<5000)/0 EEK','9,90 (<250)/0 EUR','3,90 (<100)/0 GBP','3000 (<70000)/0 HUF','4000 (<70000)/0 JPY','13,90 (<200)/0 LVL','99 (<2500)/0 NOK','39 (<1000)/0 PLN','1000 (<20000)/0 RUB','49 (<2500)/0 SEK','29 (<600)/0 USD','19,90 (<600)/0 EUR','0 EUR','0 CHF'] }, default_value => '19,90 (<500)/0 EUR' },
98857177 154 },
3de915bc 155 extra => {
156 create => [
e00d61ac 157 qq{
6ebd0f33 158 CREATE TABLE `mysql_loader-test1` (
5c06aa08 159 id INT AUTO_INCREMENT PRIMARY KEY COMMENT 'The\15\12Column',
3de915bc 160 value varchar(100)
5c06aa08 161 ) $innodb COMMENT 'The\15\12Table'
3de915bc 162 },
163 q{
6ebd0f33 164 CREATE VIEW mysql_loader_test2 AS SELECT * FROM `mysql_loader-test1`
3de915bc 165 },
e00d61ac 166 # RT#68717
167 qq{
168 CREATE TABLE `mysql_loader_test3` (
169 `ISO3_code` char(3) NOT NULL default '',
170 `lang_pref` enum('de','en','fr','nl','dk','es','se') NOT NULL,
171 `vat` decimal(4,2) default '16.00',
172 `price_group` enum('EUR_DEFAULT','GBP_GBR','EUR_AUT_BEL_FRA_IRL_NLD','EUR_DNK_SWE','EUR_AUT','EUR_BEL','EUR_FIN','EUR_FRA','EUR_IRL','EUR_NLD','EUR_DNK','EUR_POL','EUR_PRT','EUR_SWE','CHF_CHE','DKK_DNK','SEK_SWE','NOK_NOR','USD_USA','CZK_CZE','PLN_POL','RUB_RUS','HUF_HUN','SKK_SVK','JPY_JPN','LVL_LVA','ROL_ROU','EEK_EST') NOT NULL default 'EUR_DEFAULT',
173 `del_group` enum('19,90 (<500)/0 EUR','4,90 (<120)/0 EUR','7,90 (<200)/0 CHF','300 (<6000)/0 CZK','4,90 (<100)/0 EUR','39 (<900)/0 DKK','299 (<5000)/0 EEK','9,90 (<250)/0 EUR','3,90 (<100)/0 GBP','3000 (<70000)/0 HUF','4000 (<70000)/0 JPY','13,90 (<200)/0 LVL','99 (<2500)/0 NOK','39 (<1000)/0 PLN','1000 (<20000)/0 RUB','49 (<2500)/0 SEK','29 (<600)/0 USD','19,90 (<600)/0 EUR','0 EUR','0 CHF') NOT NULL default '19,90 (<500)/0 EUR',
174 `express_del_group` enum('NO','39 EUR (EXPRESS)','59 EUR (EXPRESS)','79 CHF (EXPRESS)','49 EUR (EXPRESS)','990 CZK (EXPRESS)','19,9 EUR (EXPRESS)','290 DKK (EXPRESS)','990 EEK (EXPRESS)','39 GBP (EXPRESS)','14000 HUF (EXPRESS)','49 LVL (EXPRESS)','590 NOK (EXPRESS)','250 PLN (EXPRESS)','490 SEK (EXPRESS)') NOT NULL default 'NO',
175 `pmethod` varchar(255) NOT NULL default 'VISA,MASTER',
176 `delivery_time` varchar(5) default NULL,
177 `express_delivery_time` varchar(5) default NULL,
178 `eu` int(1) default '0',
179 `cod_costs` varchar(12) default NULL,
180 PRIMARY KEY (`ISO3_code`)
181 ) $innodb
182 },
9dedee1f 183 # 4 through 10 are used for the multi-schema tests
184 qq{
185 create table mysql_loader_test11 (
186 id int auto_increment primary key
187 ) $innodb
188 },
189 qq{
190 create table mysql_loader_test12 (
191 id int auto_increment primary key,
192 eleven_id int,
193 foreign key (eleven_id) references mysql_loader_test11(id)
194 on delete restrict on update set null
195 ) $innodb
196 },
3de915bc 197 ],
198 pre_drop_ddl => [ 'DROP VIEW mysql_loader_test2', ],
9dedee1f 199 drop => [ 'mysql_loader-test1', 'mysql_loader_test3', 'mysql_loader_test11', 'mysql_loader_test12' ],
200 count => 8 + 30 * 2,
3de915bc 201 run => sub {
c4a69b87 202 my ($monikers, $classes);
203 ($schema, $monikers, $classes) = @_;
3de915bc 204
6ebd0f33 205 is $monikers->{'mysql_loader-test1'}, 'MysqlLoaderTest1',
206 'table with dash correctly monikerized';
207
e00d61ac 208 my $rsrc = $schema->source('MysqlLoaderTest2');
3de915bc 209
210 is $rsrc->column_info('value')->{data_type}, 'varchar',
211 'view introspected successfully';
e00d61ac 212
213 $rsrc = $schema->source('MysqlLoaderTest3');
214
215 is_deeply $rsrc->column_info('del_group')->{extra}{list}, ['19,90 (<500)/0 EUR','4,90 (<120)/0 EUR','7,90 (<200)/0 CHF','300 (<6000)/0 CZK','4,90 (<100)/0 EUR','39 (<900)/0 DKK','299 (<5000)/0 EEK','9,90 (<250)/0 EUR','3,90 (<100)/0 GBP','3000 (<70000)/0 HUF','4000 (<70000)/0 JPY','13,90 (<200)/0 LVL','99 (<2500)/0 NOK','39 (<1000)/0 PLN','1000 (<20000)/0 RUB','49 (<2500)/0 SEK','29 (<600)/0 USD','19,90 (<600)/0 EUR','0 EUR','0 CHF'],
216 'hairy enum introspected correctly';
5c06aa08 217
218 my $class = $classes->{'mysql_loader-test1'};
ea998e8e 219 my $filename = $schema->loader->get_dump_filename($class);
5c06aa08 220
ea998e8e 221 my $code = slurp_file $filename;
5c06aa08 222
223 like $code, qr/^=head1 NAME\n\n^$class - The\nTable\n\n^=cut\n/m,
224 'table comment';
225
226 like $code, qr/^=head2 id\n\n(.+:.+\n)+\nThe\nColumn\n\n/m,
227 'column comment and attrs';
228
9dedee1f 229 # test on delete/update fk clause introspection
230 ok ((my $rel_info = $schema->source('MysqlLoaderTest12')->relationship_info('eleven')),
231 'got rel info');
232
233 is $rel_info->{attrs}{on_delete}, 'RESTRICT',
234 'ON DELETE clause introspected correctly';
235
236 is $rel_info->{attrs}{on_update}, 'SET NULL',
237 'ON UPDATE clause introspected correctly';
238
239 # multischema tests follow
c4a69b87 240 SKIP: {
241 my $dbh = $schema->storage->dbh;
242
243 try {
244 $dbh->do('CREATE DATABASE `dbicsl-test`');
245 }
246 catch {
4c2e2ce9 247 diag "CREATE DATABASE returned error: '$_'";
5975bbe6 248 skip "no CREATE DATABASE privileges", 30 * 2;
c4a69b87 249 };
250
251 $dbh->do(<<"EOF");
252 CREATE TABLE `dbicsl-test`.mysql_loader_test4 (
253 id INT AUTO_INCREMENT PRIMARY KEY,
254 value VARCHAR(100)
255 ) $innodb
256EOF
257 $dbh->do(<<"EOF");
258 CREATE TABLE `dbicsl-test`.mysql_loader_test5 (
259 id INT AUTO_INCREMENT PRIMARY KEY,
260 value VARCHAR(100),
5975bbe6 261 four_id INTEGER,
262 CONSTRAINT loader_test5_uniq UNIQUE (four_id),
c4a69b87 263 FOREIGN KEY (four_id) REFERENCES `dbicsl-test`.mysql_loader_test4 (id)
264 ) $innodb
265EOF
5975bbe6 266
c4a69b87 267 $dbh->do('CREATE DATABASE `dbicsl.test`');
5975bbe6 268
269 # Test that keys are correctly cached by naming the primary and
270 # unique keys in this table with the same name as a table in
271 # the `dbicsl-test` schema differently.
272 $dbh->do(<<"EOF");
273 CREATE TABLE `dbicsl.test`.mysql_loader_test5 (
274 pk INT AUTO_INCREMENT PRIMARY KEY,
275 value VARCHAR(100),
276 four_id INTEGER,
277 CONSTRAINT loader_test5_uniq UNIQUE (four_id),
278 FOREIGN KEY (four_id) REFERENCES `dbicsl-test`.mysql_loader_test4 (id)
279 ) $innodb
280EOF
281
c4a69b87 282 $dbh->do(<<"EOF");
283 CREATE TABLE `dbicsl.test`.mysql_loader_test6 (
284 id INT AUTO_INCREMENT PRIMARY KEY,
285 value VARCHAR(100),
286 mysql_loader_test4_id INTEGER,
287 FOREIGN KEY (mysql_loader_test4_id) REFERENCES `dbicsl-test`.mysql_loader_test4 (id)
288 ) $innodb
289EOF
290 $dbh->do(<<"EOF");
291 CREATE TABLE `dbicsl.test`.mysql_loader_test7 (
292 id INT AUTO_INCREMENT PRIMARY KEY,
293 value VARCHAR(100),
294 six_id INTEGER UNIQUE,
295 FOREIGN KEY (six_id) REFERENCES `dbicsl.test`.mysql_loader_test6 (id)
296 ) $innodb
297EOF
298 $dbh->do(<<"EOF");
299 CREATE TABLE `dbicsl-test`.mysql_loader_test8 (
300 id INT AUTO_INCREMENT PRIMARY KEY,
301 value VARCHAR(100),
302 mysql_loader_test7_id INTEGER,
303 FOREIGN KEY (mysql_loader_test7_id) REFERENCES `dbicsl.test`.mysql_loader_test7 (id)
304 ) $innodb
305EOF
2fa86d8b 306 # Test dumping a rel to a table that's not part of the dump.
307 $dbh->do('CREATE DATABASE `dbicsl_test_ignored`');
308 $dbh->do(<<"EOF");
309 CREATE TABLE `dbicsl_test_ignored`.mysql_loader_test9 (
310 id INT AUTO_INCREMENT PRIMARY KEY,
311 value VARCHAR(100)
312 ) $innodb
313EOF
314 $dbh->do(<<"EOF");
315 CREATE TABLE `dbicsl-test`.mysql_loader_test10 (
316 id INT AUTO_INCREMENT PRIMARY KEY,
317 value VARCHAR(100),
318 mysql_loader_test9_id INTEGER,
319 FOREIGN KEY (mysql_loader_test9_id) REFERENCES `dbicsl_test_ignored`.mysql_loader_test9 (id)
320 ) $innodb
321EOF
c4a69b87 322
323 $databases_created = 1;
324
325 SKIP: foreach my $db_schema (['dbicsl-test', 'dbicsl.test'], '%') {
326 if ($db_schema eq '%') {
327 try {
328 $dbh->selectall_arrayref('SHOW DATABASES');
329 }
330 catch {
331 skip 'no SHOW DATABASES privileges', 28;
332 }
333 }
334
335 lives_and {
336 rmtree EXTRA_DUMP_DIR;
337
338 my @warns;
339 local $SIG{__WARN__} = sub {
340 push @warns, $_[0] unless $_[0] =~ /\bcollides\b/;
341 };
342
343 make_schema_at(
344 'MySQLMultiSchema',
345 {
346 naming => 'current',
347 db_schema => $db_schema,
348 dump_directory => EXTRA_DUMP_DIR,
349 quiet => 1,
350 },
351 [ $dsn, $user, $password ],
352 );
353
354 diag join "\n", @warns if @warns;
355
356 is @warns, 0;
357 } 'dumped schema for "dbicsl-test" and "dbicsl.test" databases with no warnings';
358
359 my ($test_schema, $rsrc, $rs, $row, %uniqs, $rel_info);
360
361 lives_and {
362 ok $test_schema = MySQLMultiSchema->connect($dsn, $user, $password);
363 } 'connected test schema';
364
365 lives_and {
4c2e2ce9 366 ok $rsrc = $test_schema->source('MysqlLoaderTest4');
c4a69b87 367 } 'got source for table in database name with dash';
368
369 is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
370 'column in database name with dash';
371
372 is try { $rsrc->column_info('value')->{data_type} }, 'varchar',
373 'column in database name with dash';
374
375 is try { $rsrc->column_info('value')->{size} }, 100,
376 'column in database name with dash';
377
378 lives_and {
4c2e2ce9 379 ok $rs = $test_schema->resultset('MysqlLoaderTest4');
c4a69b87 380 } 'got resultset for table in database name with dash';
381
382 lives_and {
383 ok $row = $rs->create({ value => 'foo' });
384 } 'executed SQL on table in database name with dash';
385
386 SKIP: {
387 skip 'set the environment variable DBICTEST_MYSQL_INNODB=1 to test relationships', 3 unless $test_innodb;
388
5975bbe6 389 $rel_info = try { $rsrc->relationship_info('dbicsl_dash_test_mysql_loader_test5') };
c4a69b87 390
391 is_deeply $rel_info->{cond}, {
392 'foreign.four_id' => 'self.id'
393 }, 'relationship in database name with dash';
394
395 is $rel_info->{attrs}{accessor}, 'single',
396 'relationship in database name with dash';
397
398 is $rel_info->{attrs}{join_type}, 'LEFT',
399 'relationship in database name with dash';
400 }
401
402 lives_and {
5975bbe6 403 ok $rsrc = $test_schema->source('DbicslDashTestMysqlLoaderTest5');
c4a69b87 404 } 'got source for table in database name with dash';
405
406 %uniqs = try { $rsrc->unique_constraints };
407
408 is keys %uniqs, 2,
409 'got unique and primary constraint in database name with dash';
410
5975bbe6 411 delete $uniqs{primary};
412
413 is_deeply ((values %uniqs)[0], ['four_id'],
414 'unique constraint is correct in database name with dash');
415
c4a69b87 416 lives_and {
4c2e2ce9 417 ok $rsrc = $test_schema->source('MysqlLoaderTest6');
c4a69b87 418 } 'got source for table in database name with dot';
419
420 is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
421 'column in database name with dot introspected correctly';
422
423 is try { $rsrc->column_info('value')->{data_type} }, 'varchar',
424 'column in database name with dot introspected correctly';
425
426 is try { $rsrc->column_info('value')->{size} }, 100,
427 'column in database name with dot introspected correctly';
428
429 lives_and {
4c2e2ce9 430 ok $rs = $test_schema->resultset('MysqlLoaderTest6');
c4a69b87 431 } 'got resultset for table in database name with dot';
432
433 lives_and {
434 ok $row = $rs->create({ value => 'foo' });
435 } 'executed SQL on table in database name with dot';
436
437 SKIP: {
438 skip 'set the environment variable DBICTEST_MYSQL_INNODB=1 to test relationships', 3 unless $test_innodb;
439
440 $rel_info = try { $rsrc->relationship_info('mysql_loader_test7') };
441
442 is_deeply $rel_info->{cond}, {
443 'foreign.six_id' => 'self.id'
444 }, 'relationship in database name with dot';
445
446 is $rel_info->{attrs}{accessor}, 'single',
447 'relationship in database name with dot';
448
449 is $rel_info->{attrs}{join_type}, 'LEFT',
450 'relationship in database name with dot';
451 }
452
453 lives_and {
4c2e2ce9 454 ok $rsrc = $test_schema->source('MysqlLoaderTest7');
c4a69b87 455 } 'got source for table in database name with dot';
456
457 %uniqs = try { $rsrc->unique_constraints };
458
459 is keys %uniqs, 2,
460 'got unique and primary constraint in database name with dot';
461
5975bbe6 462 delete $uniqs{primary};
463
464 is_deeply ((values %uniqs)[0], ['six_id'],
465 'unique constraint is correct in database name with dot');
466
c4a69b87 467 SKIP: {
468 skip 'set the environment variable DBICTEST_MYSQL_INNODB=1 to test relationships', 4 unless $test_innodb;
469
470 lives_and {
4c2e2ce9 471 ok $test_schema->source('MysqlLoaderTest6')
c4a69b87 472 ->has_relationship('mysql_loader_test4');
473 } 'cross-database relationship in multi-db_schema';
474
475 lives_and {
4c2e2ce9 476 ok $test_schema->source('MysqlLoaderTest4')
c4a69b87 477 ->has_relationship('mysql_loader_test6s');
478 } 'cross-database relationship in multi-db_schema';
479
480 lives_and {
4c2e2ce9 481 ok $test_schema->source('MysqlLoaderTest8')
c4a69b87 482 ->has_relationship('mysql_loader_test7');
483 } 'cross-database relationship in multi-db_schema';
484
485 lives_and {
4c2e2ce9 486 ok $test_schema->source('MysqlLoaderTest7')
c4a69b87 487 ->has_relationship('mysql_loader_test8s');
488 } 'cross-database relationship in multi-db_schema';
489 }
490 }
491 }
3de915bc 492 },
493 },
a78e3fed 494);
495
9e978a19 496if( !$dsn || !$user ) {
5c06aa08 497 $tester->skip_tests('You need to set the DBICTEST_MYSQL_DSN, DBICTEST_MYSQL_USER, and DBICTEST_MYSQL_PASS environment variables');
a78e3fed 498}
499else {
26334ec1 500 diag $skip_rels_msg if not $test_innodb;
a78e3fed 501 $tester->run_tests();
502}
26334ec1 503
c4a69b87 504END {
505 if (not $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}) {
506 if ($databases_created && (my $dbh = try { $schema->storage->dbh })) {
2fa86d8b 507 foreach my $table ('`dbicsl-test`.mysql_loader_test10',
508 'dbicsl_test_ignored.mysql_loader_test9',
509 '`dbicsl-test`.mysql_loader_test8',
c4a69b87 510 '`dbicsl.test`.mysql_loader_test7',
511 '`dbicsl.test`.mysql_loader_test6',
5975bbe6 512 '`dbicsl.test`.mysql_loader_test5',
c4a69b87 513 '`dbicsl-test`.mysql_loader_test5',
514 '`dbicsl-test`.mysql_loader_test4') {
515 try {
516 $dbh->do("DROP TABLE $table");
517 }
518 catch {
519 diag "Error dropping table: $_";
520 };
521 }
522
2fa86d8b 523 foreach my $db (qw/dbicsl-test dbicsl.test dbicsl_test_ignored/) {
c4a69b87 524 try {
525 $dbh->do("DROP DATABASE `$db`");
526 }
527 catch {
528 diag "Error dropping test database $db: $_";
529 };
530 }
531 }
532 rmtree EXTRA_DUMP_DIR;
533 }
534}
26334ec1 535# vim:et sts=4 sw=4 tw=0: