PRIMARY KEY (`ISO3_code`)
) $innodb
},
+ # 4 through 10 are used for the multi-schema tests
+ qq{
+ create table mysql_loader_test11 (
+ id int auto_increment primary key
+ ) $innodb
+ },
+ qq{
+ create table mysql_loader_test12 (
+ id int auto_increment primary key,
+ eleven_id int,
+ foreign key (eleven_id) references mysql_loader_test11(id)
+ on delete restrict on update set null
+ ) $innodb
+ },
],
pre_drop_ddl => [ 'DROP VIEW mysql_loader_test2', ],
- drop => [ 'mysql_loader-test1', 'mysql_loader_test3' ],
- count => 5 + 28 * 2,
+ drop => [ 'mysql_loader-test1', 'mysql_loader_test3', 'mysql_loader_test11', 'mysql_loader_test12' ],
+ count => 8 + 30 * 2,
run => sub {
my ($monikers, $classes);
($schema, $monikers, $classes) = @_;
like $code, qr/^=head2 id\n\n(.+:.+\n)+\nThe\nColumn\n\n/m,
'column comment and attrs';
+ # test on delete/update fk clause introspection
+ ok ((my $rel_info = $schema->source('MysqlLoaderTest12')->relationship_info('eleven')),
+ 'got rel info');
+
+ is $rel_info->{attrs}{on_delete}, 'RESTRICT',
+ 'ON DELETE clause introspected correctly';
+
+ is $rel_info->{attrs}{on_update}, 'SET NULL',
+ 'ON UPDATE clause introspected correctly';
+
+ # multischema tests follow
SKIP: {
my $dbh = $schema->storage->dbh;
$dbh->do('CREATE DATABASE `dbicsl-test`');
}
catch {
- skip "no CREATE DATABASE privileges", 28 * 2;
+ diag "CREATE DATABASE returned error: '$_'";
+ skip "no CREATE DATABASE privileges", 30 * 2;
};
$dbh->do(<<"EOF");
CREATE TABLE `dbicsl-test`.mysql_loader_test5 (
id INT AUTO_INCREMENT PRIMARY KEY,
value VARCHAR(100),
- four_id INTEGER UNIQUE,
+ four_id INTEGER,
+ CONSTRAINT loader_test5_uniq UNIQUE (four_id),
FOREIGN KEY (four_id) REFERENCES `dbicsl-test`.mysql_loader_test4 (id)
) $innodb
EOF
+
$dbh->do('CREATE DATABASE `dbicsl.test`');
+
+ # Test that keys are correctly cached by naming the primary and
+ # unique keys in this table with the same name as a table in
+ # the `dbicsl-test` schema differently.
+ $dbh->do(<<"EOF");
+ CREATE TABLE `dbicsl.test`.mysql_loader_test5 (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ value VARCHAR(100),
+ four_id INTEGER,
+ CONSTRAINT loader_test5_uniq UNIQUE (four_id),
+ FOREIGN KEY (four_id) REFERENCES `dbicsl-test`.mysql_loader_test4 (id)
+ ) $innodb
+EOF
+
$dbh->do(<<"EOF");
CREATE TABLE `dbicsl.test`.mysql_loader_test6 (
id INT AUTO_INCREMENT PRIMARY KEY,
FOREIGN KEY (mysql_loader_test7_id) REFERENCES `dbicsl.test`.mysql_loader_test7 (id)
) $innodb
EOF
+ # Test dumping a rel to a table that's not part of the dump.
+ $dbh->do('CREATE DATABASE `dbicsl_test_ignored`');
+ $dbh->do(<<"EOF");
+ CREATE TABLE `dbicsl_test_ignored`.mysql_loader_test9 (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ value VARCHAR(100)
+ ) $innodb
+EOF
+ $dbh->do(<<"EOF");
+ CREATE TABLE `dbicsl-test`.mysql_loader_test10 (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ value VARCHAR(100),
+ mysql_loader_test9_id INTEGER,
+ FOREIGN KEY (mysql_loader_test9_id) REFERENCES `dbicsl_test_ignored`.mysql_loader_test9 (id)
+ ) $innodb
+EOF
$databases_created = 1;
SKIP: {
skip 'set the environment variable DBICTEST_MYSQL_INNODB=1 to test relationships', 3 unless $test_innodb;
- $rel_info = try { $rsrc->relationship_info('mysql_loader_test5') };
+ $rel_info = try { $rsrc->relationship_info('dbicsl_dash_test_mysql_loader_test5') };
is_deeply $rel_info->{cond}, {
'foreign.four_id' => 'self.id'
}
lives_and {
- ok $rsrc = $test_schema->source('MysqlLoaderTest5');
+ ok $rsrc = $test_schema->source('DbicslDashTestMysqlLoaderTest5');
} 'got source for table in database name with dash';
%uniqs = try { $rsrc->unique_constraints };
is keys %uniqs, 2,
'got unique and primary constraint in database name with dash';
+ delete $uniqs{primary};
+
+ is_deeply ((values %uniqs)[0], ['four_id'],
+ 'unique constraint is correct in database name with dash');
+
lives_and {
ok $rsrc = $test_schema->source('MysqlLoaderTest6');
} 'got source for table in database name with dot';
is keys %uniqs, 2,
'got unique and primary constraint in database name with dot';
+ delete $uniqs{primary};
+
+ is_deeply ((values %uniqs)[0], ['six_id'],
+ 'unique constraint is correct in database name with dot');
+
SKIP: {
skip 'set the environment variable DBICTEST_MYSQL_INNODB=1 to test relationships', 4 unless $test_innodb;
END {
if (not $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}) {
if ($databases_created && (my $dbh = try { $schema->storage->dbh })) {
- foreach my $table ('`dbicsl-test`.mysql_loader_test8',
+ foreach my $table ('`dbicsl-test`.mysql_loader_test10',
+ 'dbicsl_test_ignored.mysql_loader_test9',
+ '`dbicsl-test`.mysql_loader_test8',
'`dbicsl.test`.mysql_loader_test7',
'`dbicsl.test`.mysql_loader_test6',
+ '`dbicsl.test`.mysql_loader_test5',
'`dbicsl-test`.mysql_loader_test5',
'`dbicsl-test`.mysql_loader_test4') {
try {
};
}
- foreach my $db (qw/dbicsl-test dbicsl.test/) {
+ foreach my $db (qw/dbicsl-test dbicsl.test dbicsl_test_ignored/) {
try {
$dbh->do("DROP DATABASE `$db`");
}