[DBIx-Class-Devel] RFC: Comparison Helper

fREW Schmidt frioux at gmail.com
Thu Dec 13 14:09:29 GMT 2012


A few times now I've wanted to be able to compare a schema against
another schema.  The general use case is that my tests are SQLite and
should have the same data as my real database, but should not run all
the actual migrations (slow tests are a drag.)  Having thought about
it for nearly three months I think I have some ideas on how it could
be done.  Here's the interface I'd use:

   # scalar context returns true for "same"
   # void dies
   my @differences = compare_resultsets({
      left => {
         starting_points => [
            $schema->resultset('User'),
         ],
         included_sources => [
            $schema->source('User'),
            $schema->source('Permission'),
            $schema->source('Role'),
         ],
      },
      right => {
         starting_points => [
            $schema->resultset('User'),
         ],
         included_sources => [
            $schema->source('User'),
            $schema->source('Permission'),
            $schema->source('Role'),
         ],
      }
   });

The API might be able to get a little bit better, like allowing
strings to automatically inflate where possible:

   compare_resultsets({
      included_sources => [ qw(User Permission Role) ],
      starting_points => ['User'],
      left_schema => $left_schema,
      right_schema => $right_schema,
   });

And of course the above is just a whitelist, but blacklisting sources
could be done if the user doesn't want to whitelist sources.  The
general idea is that I compare the (raw) values of the columns of each
object, excluding auto_inc columns and fk columns pointing to an
autoincs.  Then I will traverse relationships (has_many only?) until I
hit a source that is not included.  I'm not sure how to avoid loops,
but I'll cross that bridge when I get there.

I have considered adding a way to whitelist/blackist down to the
column level too, and that the autoinc/fk thing would just generate
that, but that might be a level of configuration that's worthless.
Not sure yet.

Aside from the loop issue I'm fairly confident that this is doable and
it is certainly useful to me.  What do you guys think?

--
fREW Schmidt
http://blog.afoolishmanifesto.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class-devel/attachments/20121213/855b8709/attachment.pgp


More information about the DBIx-Class-Devel mailing list