[Bast-commits] r3171 - in branches/DBIx-Class-Schema-Loader/current:
lib/DBIx/Class/Schema lib/DBIx/Class/Schema/Loader t/lib
blblack at dev.catalyst.perl.org
blblack at dev.catalyst.perl.org
Sat Mar 31 02:07:17 GMT 2007
Author: blblack
Date: 2007-03-31 02:07:15 +0100 (Sat, 31 Mar 2007)
New Revision: 3171
Modified:
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
Log:
added test for rescan, fixed a few issues
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm 2007-03-30 23:38:00 UTC (rev 3170)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm 2007-03-31 01:07:15 UTC (rev 3171)
@@ -209,7 +209,6 @@
bless $self => $class;
- $self->{db_schema} ||= '';
$self->_ensure_arrayref(qw/additional_classes
additional_base_classes
left_base_classes
@@ -313,14 +312,24 @@
=head2 rescan
+Arguments: schema
+
Rescan the database for newly added tables. Does
-not process drops or changes.
+not process drops or changes. Returns a list of
+the newly added table monikers.
+The schema argument should be the schema class
+or object to be affected. It should probably
+be derived from the original schema_class used
+during L</load>.
+
=cut
sub rescan {
- my $self = shift;
+ my ($self, $schema) = @_;
+ $self->{schema} = $schema;
+
my @created;
my @current = $self->_tables_list;
foreach my $table ($self->_tables_list) {
@@ -330,6 +339,8 @@
}
$self->_load_tables(@created);
+
+ return map { $self->monikers->{$_} } @created;
}
sub _load_tables {
@@ -345,7 +356,9 @@
@tables = grep { ! /$exclude/ } @tables if $exclude;
# Save the new tables to the tables list
- push(@{$self->{_tables}}, @tables);
+ foreach (@tables) {
+ $self->{_tables}->{$_} = 1;
+ }
# Set up classes/monikers
{
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm 2007-03-30 23:38:00 UTC (rev 3170)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm 2007-03-31 01:07:15 UTC (rev 3171)
@@ -290,9 +290,11 @@
load, and adds them to the schema at runtime, including relationships,
etc. Does not process drops or changes.
+Returns a list of the new monikers added.
+
=cut
-sub rescan { shift->_loader->rescan }
+sub rescan { my $self = shift; $self->_loader->rescan($self) }
=head1 EXAMPLE
Modified: branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm 2007-03-30 23:38:00 UTC (rev 3170)
+++ branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm 2007-03-31 01:07:15 UTC (rev 3171)
@@ -43,7 +43,7 @@
sub run_tests {
my $self = shift;
- plan tests => 76;
+ plan tests => 80;
$self->create();
@@ -444,6 +444,38 @@
my $obj15 = $rsobj15->find(1);
isa_ok( $obj15->loader_test14, $class14 );
}
+
+ # rescan test
+ SKIP: {
+ skip 'SQLite does not like schema changes while connected', 4
+ if $self->{vendor} =~ /sqlite/i;
+
+ my @statements_rescan = (
+ qq{
+ CREATE TABLE loader_test25 (
+ id INTEGER NOT NULL PRIMARY KEY,
+ loader_test2 INTEGER NOT NULL,
+ FOREIGN KEY (loader_test2) REFERENCES loader_test2 (id)
+ ) $self->{innodb}
+ },
+ q{ INSERT INTO loader_test25 (id,loader_test2) VALUES(123, 1) },
+ q{ INSERT INTO loader_test25 (id,loader_test2) VALUES(321, 2) },
+ );
+
+ my $dbh = $self->dbconnect(1);
+ $dbh->do($_) for @statements_rescan;
+ $dbh->disconnect;
+
+ my @new = $conn->rescan;
+ is(scalar(@new), 1);
+ is($new[0], 'LoaderTest25');
+
+ my $rsobj25 = $conn->resultset('LoaderTest25');
+ isa_ok($rsobj25, 'DBIx::Class::ResultSet');
+ my $obj25 = $rsobj25->find(123);
+ isa_ok( $obj25->loader_test2, $class2);
+ }
+
}
}
@@ -744,7 +776,7 @@
},
q{ INSERT INTO loader_test15 (id,loader_test14) VALUES (1,123) },
- );
+ );
$self->drop_tables;
@@ -817,6 +849,8 @@
loader_test14
/;
+ my @tables_rescan = qw/ loader_test25 /;
+
my $drop_fk_mysql =
q{ALTER TABLE loader_test10 DROP FOREIGN KEY loader_test11_fk;};
@@ -843,6 +877,9 @@
$dbh->do("DROP TABLE $_") for (@tables_implicit_rels);
}
}
+ unless($self->{vendor} =~ /sqlite/i) {
+ $dbh->do("DROP TABLE $_") for (@tables_rescan);
+ }
$dbh->do("DROP TABLE $_") for (@tables);
$dbh->disconnect;
}
More information about the Bast-commits
mailing list