use List::MoreUtils 'any';
use Try::Tiny;
use namespace::clean;
+use DBIx::Class::Schema::Loader::Table ();
our $VERSION = '0.07010';
my @f_cols = map { s/$qt//g; $self->_lc($_) }
split(/$qt?\s*$qt?,$qt?\s*$qt?/, $f_cols);
- my $remote_table = first {
- lc($_->name) eq lc($f_table)
- && ((not $f_schema) || lc($_->schema) eq lc($f_schema))
- } $self->_tables_list;
+ my $remote_table = do {
+ # Get ->tables_list to return tables from the remote schema, in case it is not in the db_schema list.
+ local $self->{db_schema} = [ $f_schema ] if $f_schema;
+
+ first {
+ lc($_->name) eq lc($f_table)
+ && ((not $f_schema) || lc($_->schema) eq lc($f_schema))
+ } $self->_tables_list;
+ };
+
+ # The table may not be in any database, or it may not have been found by the previous code block for whatever reason.
+ if (not $remote_table) {
+ my $remote_schema = $f_schema || $self->db_schema && @{ $self->db_schema } == 1 && $self->db_schema->[0];
+
+ $remote_table = DBIx::Class::Schema::Loader::Table->new(
+ loader => $self,
+ name => $f_table,
+ ($remote_schema ? (
+ schema => $remote_schema,
+ ) : ()),
+ );
+ }
push(@rels, {
local_columns => \@cols,
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;
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',
};
}
- 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`");
}