-immediate stuff for 0.04:
---------------------------
-
-avinash240 wants a rescan method to pick up new tables at runtime
-
--------
-
support multiple/all schemas, instead of just one
support pk/uk/fk info on views, possibly. May or may not be a sane thing to try to do.
__PACKAGE__->mk_classaccessor('dump_to_dir');
__PACKAGE__->mk_classaccessor('_loader_args' => {});
__PACKAGE__->mk_classaccessor('_loader_invoked');
+__PACKAGE__->mk_classaccessor('_loader');
=head1 NAME
croak qq/Could not load storage_type loader "$impl": / .
qq/"$UNIVERSAL::require::ERROR"/;
- $impl->new(%$args)->load;
+ $self->_loader($impl->new(%$args));
+ $self->_loader->load;
$self->_loader_invoked(1);
$self;
$target->connection(@$connect_info);
}
+=head2 rescan
+
+Re-scans the database for newly added tables since the initial
+load, and adds them to the schema at runtime, including relationships,
+etc. Does not process drops or changes.
+
+=cut
+
+sub rescan { shift->_loader->rescan }
+
=head1 EXAMPLE
Using the example in L<DBIx::Class::Manual::ExampleSchema> as a basis
sub load {
my $self = shift;
+ $self->_load_tables($self->_tables_list);
+}
+
+=head2 rescan
+
+Rescan the database for newly added tables. Does
+not process drops or changes.
+
+=cut
+
+sub rescan {
+ my $self = shift;
+
+ my @created;
+ my @current = $self->_tables_list;
+ foreach my $table ($self->_tables_list) {
+ if(!exists $self->{_tables}->{$table}) {
+ push(@created, $table);
+ }
+ }
+
+ $self->_load_tables(@created);
+}
+
+sub _load_tables {
+ my ($self, @tables) = @_;
+
# First, use _tables_list with constraint and exclude
# to get a list of tables to operate on
my $constraint = $self->constraint;
my $exclude = $self->exclude;
- my @tables = sort $self->_tables_list;
- if(!@tables) {
- warn "No tables found in database, nothing to load";
- }
- else {
- @tables = grep { /$constraint/ } @tables if $constraint;
- @tables = grep { ! /$exclude/ } @tables if $exclude;
-
- warn "All tables excluded by constraint/exclude, nothing to load"
- if !@tables;
- }
+ @tables = grep { /$constraint/ } @tables if $constraint;
+ @tables = grep { ! /$exclude/ } @tables if $exclude;
- # Save the tables list
- $self->{_tables} = \@tables;
+ # Save the new tables to the tables list
+ push(@{$self->{_tables}}, @tables);
# Set up classes/monikers
{
sub tables {
my $self = shift;
- return @{$self->_tables};
+ return keys %{$self->_tables};
}
# Make a moniker from a table
{
'Some::Source::Class' => [
- { method => 'belongs_to', arguments => [ 'col1', 'AnotherTableMoniker' ],
- { method => 'has_many', arguments => [ 'anothers', 'AnotherTableMoniker', 'col15' ],
+ { method => 'belongs_to', arguments => [ 'col1', 'Another::Source::Class' ],
+ { method => 'has_many', arguments => [ 'anothers', 'Yet::Another::Source::Class', 'col15' ],
],
'Another::Source::Class' => [
# ...