[PATCH] Schema::Loader add components per-class

3 messages Options
Embed this post
Permalink
Tom Lanyon

[PATCH] Schema::Loader add components per-class

Reply Threaded More More options
Print post
Permalink
Hi list,

I needed to add some components to some classes but not others; I  
expected this to be a fairly normal operation but DBIC-Schema-Loader  
didn't seem to be able to do it...

Attached is a simple patch that 'works for me' against current SVN  
trunk. Comments? Suggestions?

-Tom





_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...

loader-component_overrides.patch (2K) Download Attachment
Kieren Diment

Re: [PATCH] Schema::Loader add components per-class

Reply Threaded More More options
Print post
Permalink
On 07/07/2009, at 10:14 AM, Tom Lanyon wrote:

> Hi list,
>
> I needed to add some components to some classes but not others; I  
> expected this to be a fairly normal operation but DBIC-Schema-Loader  
> didn't seem to be able to do it...
>
> Attached is a simple patch that 'works for me' against current SVN  
> trunk. Comments? Suggestions?
>
> -Tom
>
> <loader-component_overrides.patch>

Here's a script from the new Catalyst book that seems to achieve what  
you wanted, at least to some degree.  In this case you regenerate the  
classes  for particular tables to which you want to add specific  
components, so for lots of tables and lots of specific components this  
approach is repetitive.  I don't know how close this is to doing what  
your patch achieves, but I do note that to be accepted into DBIC, your  
patch would need to include suitable tests.

  #!/usr/bin/perl
  use warnings;
  use strict;
  use FindBin qw/$Bin/;
  use DBIx::Class::Schema::Loader qw/ make_schema_at /;

  my %options;
  if (@ARGV) {
      my $table = shift @ARGV;
      %options = ( constraint => $table,
                   components => [@ARGV]);
  }

  make_schema_at("Zotero::Schema",
                 {
                     %options,
                     debug => 1,
                     relationships => 1,
                     use_namespaces => 1,
                     dump_directory => "$Bin/../lib" ,
                 },
                 ["dbi:SQLite:dbname=$Bin/../zotero.sqlite",
                  "",""]);


=head1 make_zotero_schema.pl [table name] [components]

      Make the DBIC schema from the zotero db, optionally limit it to a
      particular table, and adding specific components to the table.

=cut

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Tom Lanyon

Re: [PATCH] Schema::Loader add components per-class

Reply Threaded More More options
Print post
Permalink
On 07/07/2009, at 9:55 AM, Kieren Diment wrote:
> Here's a script from the new Catalyst book that seems to achieve  
> what you wanted, at least to some degree.  In this case you  
> regenerate the classes  for particular tables to which you want to  
> add specific components, so for lots of tables and lots of specific  
> components this approach is repetitive.  I don't know how close this  
> is to doing what your patch achieves, but I do note that to be  
> accepted into DBIC, your patch would need to include suitable tests.


Thanks - your script does pretty much the same thing, but the patch to  
Schema::Loader is designed so that you can simply have a pre-defined  
hash of tables and associated components in your loader scripts, in  
hope to avoid the repetitive re-generation if you have many tables  
with extra required components.

I imagine a test could just involve adding another TestComponent-style  
library and then adding it to only one table in the  
dbixcsl_common_tests and testing whether a component-provided method  
is available on that table and not the others - but I'd need guidance  
on the best place to insert this from someone more familiar with the  
Schema::Loader test packages...

Tom

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...