Diff.pm

filter: Statementstmt 90.3% 84 / 93 Branchbran 85.0% 17 / 20 Conditioncond 52.7% 19 / 36 MC/DCmcdc 29.4% 5 / 17 Subroutinesub 83.3% 20 / 24 Podpod 60.0% 3 / 5 totaltotal 75.9% 148 / 195 CC 24 SCAR 22.5
CC
24
Cov
81%
state
20.0
_coerce_filter_args
20.0
filter
4.0
CRAP 9.5
« Diff/State.pm ↑ Summary Diff/Filter.pm »
1 package DBIx::Class::Schema::Diff;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: Simple Diffing of DBIC Schemas
6  
7 5 our $VERSION = 1.11;
8  
9 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 with 'DBIx::Class::Schema::Diff::Role::Common';
11  
12 5 ▶use Types::Standard qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Module::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Hash::Layout 2.00;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Array::Diff;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 5 ▶use DBIx::Class::Schema::Diff::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use DBIx::Class::Schema::Diff::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use DBIx::Class::Schema::Diff::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 sub state {
25 0 ▶ shift if ($_[0] && (try{ $_[0]->isa(__PACKAGE__) } || $_[0] eq __PACKAGE__));
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine state: not called CC=4 SCAR=30.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] and &try(sub { $_[0]->isa(__PACKAGE__); } ) || $_[0] eq __PACKAGE__ 0 0 0
Condition0%0/6
$_[0] and &try(sub {
!ll&&!rl&&r
000
&try(sub { or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/3
$_[0] and &try(sub { $_[0]->isa(__PACKAGE__); } ) || $_[0] eq __PACKAGE__
$_[0] &try(sub { $_[0]->isa(__PACKAGE__); } ) $_[0] eq __PACKAGE__
Truth table0%0/4
A and B or C
A= $_[0]B= &try(sub { $_[0]->isa(__PACKAGE__); } )C= $_[0] eq __PACKAGE__
ABCresult
0XX0
1000
11X1
1011
26 0 DBIx::Class::Schema::Diff::State->new(@_)
27 }
28  
29  
30 5 has '_schema_diff', required => 1, is => 'ro', isa => InstanceOf[
31 'DBIx::Class::Schema::Diff::Schema'
32 ], coerce => \&_coerce_schema_diff;
33  
34 has 'diff', is => 'ro', lazy => 1, default => sub {
35 22 ▶ (shift)->_schema_diff->diff
Subroutine __ANON__: called CC=1 SCAR=0.0
36 5 }, isa => Maybe[HashRef];
37  
38 has 'MatchLayout', is => 'ro', lazy => 1, default => sub {
39 31 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
40
41 31 Hash::Layout->new({
42 default_key => '*',
43 default_value => 1,
44 levels => [
45 {
46 name => 'source',
47 delimiter => ':',
48 registered_keys => [$self->_schema_diff->all_source_names]
49 },{
50 name => 'type',
51 delimiter => '/',
52 registered_keys => [&_types_list]
53 },{
54 name => 'id',
55 }
56 ]
57 });
58  
59 5 }, init_arg => undef, isa => InstanceOf['Hash::Layout'];
60  
61  
62 around BUILDARGS => sub {
63 100 ▶ my ($orig, $self, @args) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
64 100 ▶ my %opt = (ref($args[0]) eq 'HASH') ? %{ $args[0] } : @args; # <-- arg as hash or hashref
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] eq 'HASH' ? : 76 24 100
65
66 100 ▶ return $opt{_schema_diff} ? $self->$orig(%opt) : $self->$orig( _schema_diff => \%opt );
Branch: 1 branch
BranchTrueFalseTotal
$opt{'_schema_diff'} ? : 76 24 100
67 5 };
68  
69  
70 sub filter {
71 76 ▶ my ($self,@args) = @_;
Subroutine filter: called CC=4 SCAR=13.9
Pod documented
72 76 my $params = $self->_coerce_filter_args(@args);
73
74 76 my $Filter = DBIx::Class::Schema::Diff::Filter->new( $params ) ;
75 76 my $diff = $Filter->filter( $self->diff );
76
77 # Make a second pass, using the actual matched paths to filter out
78 # the intermediate paths that didn't actually match anything:
79 # (update: unless this is an empty match, in which case we will just
80 # return the whole diff as-is)
81 76 ▶ if($Filter->mode eq 'limit' && ! $Filter->empty_match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Filter->mode eq "limit" and not $Filter->empty_match) 52 24 76
Condition100%3/3
$Filter->mode eq "limit" and not $Filter->empty_match
!ll&&!rl&&r
19552
MC/DC100%2/2
$Filter->mode eq "limit" and not $Filter->empty_match
$Filter->mode eq "limit" not $Filter->empty_match
Truth table100%3/3
A and not(B)
A= $Filter->mode eq "limit"B= not $Filter->empty_match
ABresult
0X0
100
111
82 52 ▶ if(scalar(@{$Filter->matched_paths}) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$Filter->matched_paths;} > 0) { } 51 1 52
83 $params->{match} = $Filter->match->clone->reset->load( map {
84 284 $Filter->match->path_to_composite_key(@$_)
85 51 } @{$Filter->matched_paths} );
86 51 $Filter = DBIx::Class::Schema::Diff::Filter->new( $params ) ;
87 51 $diff = $Filter->filter( $diff );
88 }
89 else {
90 # If nothing was matched, in limit mode, the diff is undef:
91 1 $diff = undef;
92 }
93 }
94
95 76 return $self->chain_new($diff)
96 }
97  
98 sub chain_new {
99 76 ▶ my ($self, $diff) = @_;
Subroutine chain_new: called CC=1 SCAR=0.0
Pod undocumented
100 76 return __PACKAGE__->new({
101 _schema_diff => $self->_schema_diff,
102 diff => $diff
103 });
104 }
105  
106 sub filter_out {
107 19 ▶ my ($self,@args) = @_;
Subroutine filter_out: called CC=1 SCAR=0.0
Pod documented
108 19 my $params = $self->_coerce_filter_args(@args);
109 19 $params->{mode} = 'ignore';
110 19 return $self->filter( $params );
111 }
112  
113  
114 sub _coerce_filter_args {
115 95 ▶ my ($self,@args) = @_;
Subroutine _coerce_filter_args: called CC=16 SCAR=30.0
116
117 # This is the cleanest solution for wildcards to match as expected, not requiring the
118 # user to append a trailing '*' since they don't have to when doing an exact match
119 @args = map {
120 95 ▶ my ($one,$two) = ($_ && ! ref($_)) ? split (/\:/,$_,2) : ();
Branch: 1 branch
BranchTrueFalseTotal
$_ && !ref($_) ? : 98 29 127
Condition66%2/3
$_ and not ref $_
!ll&&!rl&&r
02998
MC/DC50%1/2
$_ and not ref $_
$_ not ref $_
Truth table66%2/3
A and not(B)
A= $_B= not ref $_
ABresult
0X0
100
111
121 (
122 127 ▶ $one && $two && $one ne '*' && ($one =~ /\*/)
Branch: 1 branch
BranchTrueFalseTotal
$one && $two && $one ne '*' && $one =~ /\*/ && ($two eq 'columns' || $two eq 'relationships' || $two eq 'constraints') ? : 0 127 127
Condition50%9/18
$one and $two and $one ne "*" and $one =~ /\*/ and $two eq "columns" || $two eq "relationships" || $two eq "constraints"
!ll&&!rl&&r
12700
$one and $two and $one ne "*" and $one =~ /\*/
!ll&&!rl&&r
113140
$one and $two and $one ne "*"
!ll&&!rl&&r
109414
$one and $two
!ll&&!rl&&r
298018
$two eq "columns" or $two eq "relationships" or $two eq "constraints"
l!l&&r!l&&!r
000
$two eq "columns" or $two eq "relationships"
l!l&&r!l&&!r
000
MC/DC0%0/7
$one and $two and $one ne "*" and $one =~ /\*/ and $two eq "columns" || $two eq "relationships" || $two eq "constraints"
$one $two $one ne "*" $one =~ /\*/ $two eq "columns" $two eq "relationships" $two eq "constraints"
Truth table50%4/8
A and B and C and D and E or F or G
A= $oneB= $twoC= $one ne "*"D= $one =~ /\*/E= $two eq "columns"F= $two eq "relationships"G= $two eq "constraints"
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110000
11111XX1
111101X1
11110011
123 && ($two eq 'columns' || $two eq 'relationships' || $two eq 'constraints')
124 ) ? $_.'*' : $_
125 } @args;
126
127 95 ▶ my $params = (
Branch: 1 branch
BranchTrueFalseTotal
scalar @args > 1 || !ref($args[0]) || ref $args[0] ne 'HASH' ? : 66 29 95
Condition83%5/6
scalar @args > 1 or not ref $args[0] or ref $args[0] ne "HASH"
l!l&&r!l&&!r
66029
scalar @args > 1 or not ref $args[0]
l!l&&r!l&&!r
214529
MC/DC66%2/3
scalar @args > 1 or not ref $args[0] or ref $args[0] ne "HASH"
scalar @args > 1 not ref $args[0] ref $args[0] ne "HASH"
Truth table75%3/4
A or not(B) or C
A= scalar @args > 1B= not ref $args[0]C= ref $args[0] ne "HASH"
ABCresult
1XX1
01X1
0011
0000
128 scalar(@args) > 1
129 || ! ref($args[0])
130 || ref($args[0]) ne 'HASH'
131 ) ? { match => \@args } : $args[0];
132
133 95 ▶ unless (exists $params->{match}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $params->{"match"}) 10 85 95
134 10 my $n = { match => $params };
135 10 my @othr = qw(events source_events);
136 10 ▶ exists $n->{match}{$_} and $n->{$_} = delete $n->{match}{$_} for (@othr);
Branch: 1 branch
BranchTrueFalseTotal
exists $n->{"match"}{$_} and $n->{$_} = delete $n->{"match"}{$_} 7 13 20
137 10 $params = $n;
138 }
139  
140 return {
141 %$params,
142 match => $self->MatchLayout->coerce($params->{match})
143 95 };
144 }
145  
146  
147  
148 sub fingerprint {
149 0 ▶ my $self = shift;
Subroutine fingerprint: not called CC=1 SCAR=6.9
Pod documented
150 0 my $sum = Digest::SHA1->new->add( $self->_string_for_signature )->hexdigest;
151 0 join('-', 'diffsum', substr($sum,0,15) )
152 }
153  
154  
155 # So far this is the only thing I could find to produce a consistent string value across all
156 # Travis tested perls (5.10,5.12,5.14,5.16,5.18,5.20,5.22,5.24,5.26)
157 sub _string_for_signature {
158 0 ▶ my $self = shift;
Subroutine _string_for_signature: not called CC=1 SCAR=6.9
159
160 0 local $Data::Dumper::Maxdepth = 0;
161 0 Data::Dumper->new([ $self->diff ])
162 ->Purity(0)
163 ->Terse(1)
164 ->Indent(0)
165 ->Useqq(1)
166 ->Sortkeys(1)
167 ->Dump()
168 }
169  
170  
171 5 1;
172  
173  
174 __END__
175  
176 =head1 NAME
177  
178 DBIx::Class::Schema::Diff - Identify differences between two DBIx::Class schemas
179  
180 =head1 SYNOPSIS
181  
182 use DBIx::Class::Schema::Diff;
183  
184 # Create new diff object using schema class names:
185 my $D = DBIx::Class::Schema::Diff->new(
186 old_schema => 'My::Schema1',
187 new_schema => 'My::Schema2'
188 );
189
190 # Create new diff object using schema objects:
191 $D = DBIx::Class::Schema::Diff->new(
192 old_schema => $schema1,
193 new_schema => $schema2
194 );
195
196 # Dump current schema data to a json file for later use:
197 $D->old_schema->dump_json_file('/tmp/my_schema1_data.json');
198
199 # Or
200 DBIx::Class::Schema::Diff::SchemaData->new(
201 schema => 'My::Schema1'
202 )->dump_json_file('/tmp/my_schema1_data.json');
203
204 # Create new diff object using previously saved
205 # schema data + current schema class:
206 $D = DBIx::Class::Schema::Diff->new(
207 old_schema => '/tmp/my_schema1_data.json',
208 new_schema => 'My::Schema1'
209 );
210
211 # Git a checksum/fingerprint of the diff data:
212 my $checksum = $D->fingerprint;
213
214  
215 Filtering the diff:
216  
217
218 # Get all differences (hash structure):
219 my $hash = $D->diff;
220
221 # Only column differences:
222 $hash = $D->filter('columns')->diff;
223
224 # Only things named 'Artist' or 'CD':
225 $hash = $D->filter(qw/Artist CD/)->diff;
226
227 # Things named 'Artist', *columns* named 'CD' and *relationships* named 'columns':
228 $hash = $D->filter(qw(Artist columns/CD relationships/columns))->diff;
229
230 # Sources named 'Artist', excluding column changes:
231 $hash = $D->filter('Artist:')->filter_out('columns')->diff;
232
233 if( $D->filter('Artist:columns/name.size')->diff ) {
234 # Do something only if there has been a change in 'size' (i.e. in column_info)
235 # to the 'name' column in the 'Artist' source
236 # ...
237 }
238
239 # Names of all sources which exist in new_schema but not in old_schema:
240 my @sources = keys %{
241 $D->filter({ source_events => 'added' })->diff || {}
242 };
243
244 # All changes to existing unique_constraints (ignoring added or deleted)
245 # excluding those named or within sources named Album or Genre:
246 $hash = $D->filter_out({ events => [qw(added deleted)] })
247 ->filter_out('Album','Genre')
248 ->filter('constraints')
249 ->diff;
250
251 # All changes to relationship attrs except for 'cascade_delete' in
252 # relationships named 'artists':
253 $hash = $D->filter_out('relationships/artists.attrs.cascade_delete')
254 ->filter('relationships/*.attrs')
255 ->diff;
256  
257  
258 =head1 DESCRIPTION
259  
260 General-purpose schema differ for L<DBIx::Class> to identify changes between two DBIC Schemas.
261 Currently tracks added/deleted/changed events and deep diffing across 5 named types of source data:
262  
263 =over
264  
265 =item *
266  
267 columns
268  
269 =item *
270  
271 relationships
272  
273 =item *
274  
275 constraints
276  
277 =item *
278  
279 table_name
280  
281 =item *
282  
283 isa
284  
285 =back
286  
287 The changes which are detected are stored in a HashRef which can be accessed by calling
288 L<diff|DBIx::Class::Schema::Diff#diff>. This data packet, which has a format that is specific to
289 this module, can either be inspected directly, or I<filtered> to be able to check for specific
290 changes as boolean test(s), making it unnecessary to know the internal diff structure for many
291 use-cases (since if there are no changes, or no changes left after being filtered, C<diff> returns
292 false/undef - see the L<FILTERING|DBIx::Class::Schema::Diff#FILTERING> section for more info).
293  
294 This tool attempts to be simple and flexible with a straightforward, "DWIM" API. It is meant
295 to be used programmatically in dynamic scenarios where schema changes are occurring but are not well
296 suited for L<DBIx::Class::Migration> or L<DBIx::Class::DeploymentHandler> for whatever reasons, or
297 some other event/action needs to take place based on certain types of changes (note that this tool
298 is NOT meant to be a replacement for Migrations/DH).
299  
300 It is also useful as a general debugging/development tool, and was designed with this in mind to
301 be "handy" and not need a lot of setup/RTFM to use.
302  
303 This tool is different from L<SQL::Translator::Diff> in that it compares DBIC schemas at the
304 I<class/code> level, not the underlying DDL, nor does it attempt to modify one schema to match
305 the other (although, it could certainly be used to write a tool that did).
306  
307 =head1 METHODS
308  
309 =head2 new
310  
311 Create a new DBIx::Class::Schema::Diff instance. The following build options are supported:
312  
313 =over 4
314  
315 =item old_schema
316  
317 The "old" (or left-side) schema to be compared.
318  
319 Can be supplied as a L<DBIx::Class::Schema> class name, connected schema object instance,
320 or previously saved L<SchemaData|DBIx::Class::Schema::Diff::SchemaData> which can be
321 supplied as an object, HashRef, or a path to a file containing serialized JSON data (as
322 produced by L<DBIx::Class::Schema::Diff::SchemaData#dump_json_file>)
323  
324 See the SYNOPSIS and L<DBIx::Class::Schema::Diff::SchemaData> for more info.
325  
326 =item new_schema
327  
328 The "new" (or right-side) schema to be compared. Accepts the same dynamic type options
329 as C<old_schema>.
330  
331 =back
332  
333 =head2 diff
334  
335 Returns the differences between the two schemas as a HashRef structure, or C<undef> if there are
336 none.
337  
338 The HashRef is divided first by source name, then by type, with the special C<_event> key
339 identifying the kind of modification (added, deleted or changed) at both the source and the type
340 level. For 'changed' events within types, a deeper, type-specific diff HashRef is provided (with
341 column_info/relationship_info diffs generated using L<Hash::Diff>).
342  
343 Here is an example of what a diff packet (with a sampling of lots of different kinds of changes)
344 might look like:
345  
346 # Example diff with sample of all 3 kinds of events and all 5 types:
347 {
348 Address => {
349 _event => "changed",
350 isa => [
351 "-Some::Removed::Component",
352 "+Test::DummyClass"
353 ],
354 relationships => {
355 customers2 => {
356 _event => "added"
357 },
358 staffs => {
359 _event => "changed",
360 diff => {
361 attrs => {
362 cascade_delete => 1
363 }
364 }
365 }
366 }
367 },
368 City => {
369 _event => "changed",
370 table_name => "city1"
371 },
372 FilmCategory => {
373 _event => "changed",
374 columns => {
375 last_update => {
376 _event => "changed",
377 diff => {
378 is_nullable => 1
379 }
380 }
381 }
382 },
383 FooBar => {
384 _event => "added"
385 },
386 FooBaz => {
387 _event => "deleted"
388 },
389 Store => {
390 _event => "changed",
391 constraints => {
392 idx_unique_store_manager => {
393 _event => "added"
394 }
395 }
396 }
397 }
398  
399 =head2 filter
400  
401 Accepts filter argument(s) to restrict the differences to consider and returns a new C<Schema::Diff>
402 instance, making it chainable (much like L<ResultSets|DBIx::Class::ResultSet#search_rs>).
403  
404 See L<FILTERING|DBIx::Class::Schema::Diff#FILTERING> for filter argument syntax.
405  
406 =head2 filter_out
407  
408 Works like C<filter()> but the arguments exclude differences rather than restrict/limit to them.
409  
410 See L<FILTERING|DBIx::Class::Schema::Diff#FILTERING> for filter argument syntax.
411  
412 =head2 fingerprint
413  
414 Returns a SHA1 checksum (as a 15 character string) of the diff data.
415  
416 =head1 FILTERING
417  
418 The L<filter|DBIx::Class::Schema::Diff#filter> (and inverse
419 L<filter_out|DBIx::Class::Schema::Diff#filter_out>) method is analogous to ResultSet's
420 L<search_rs|DBIx::Class::ResultSet#search_rs> in that it is chainable (i.e. returns a new object
421 instance) and each call further restricts the data considered. But, instead of building up an SQL
422 query, it filters the data in the HashRef returned by L<diff|DBIx::Class::Schema::Diff#diff>.
423  
424 The filter argument(s) define an expression which matches specific parts of the C<diff> packet. In
425 the case of C<filter()>, all data that B<does not> match the expression is removed from the diff
426 HashRef (of the returned, new object), while in the case of C<filter_out()>, all data that B<does>
427 match the expression is removed.
428  
429 The filter expression is designed to be simple and declarative. It can be supplied as a list of
430 strings which match schema data either broadly or narrowly. A filter string argument follows this
431 general pattern:
432  
433 '<source>:<type>/<id>'
434  
435 Where C<source> is the name of a specific source in the schema (either side), C<type> is the
436 I<type> of data, which is currently one of five (5) supported, predefined types: I<'columns'>,
437 I<'relationships'>, I<'constraints'>, I<'isa'> and I<'table_name'>, and C<id> is the name of an
438 item, specific to that type, if applicable.
439  
440 For instance, this expression would match only the I<column> named 'timestamp' in the source
441 named 'Artist':
442  
443 'Artist:columns/timestamp'
444  
445 Not all types have sub-items (only I<columns>, I<relationships> and I<constraints>). The I<isa> and
446 I<table_name> types are source-global. So, for example, to see changes to I<isa> (i.e. differences
447 in inheritance and/or loaded components in the result class) you could use the following:
448  
449 'Artist:isa'
450  
451 On the other hand, not only are there multiple I<columns> and I<relationships> within each source,
452 but each can have specific changes to their attributes (column_info/relationship_info) which can
453 also be targeted selectively. For instance, to match only changes in C<size> of a specific column:
454  
455 'Artist:columns/timestamp.size'
456  
457 Attributes with sub hashes can be matched as well. For example, to match only changes in C<list>
458 I<within> C<extra> (which is where DBIC puts the list of possible values for enum columns):
459  
460 'Artist:columns/my_enum.extra.list'
461  
462 The structure is specific to the type. The dot-separated path applies to the data returned by L<column_info|DBIx::Class::ResultSource#column_info> for columns and
463 L<relationship_info|DBIx::Class::ResultSource#relationship_info> for relationships. For instance,
464 the following matches changes to C<cascade_delete> of a specific relationship named 'some_rel'
465 in the 'Artist' source:
466  
467 'Artist:relationships/some_rel.attrs.cascade_delete'
468  
469 Filter arguments can also match I<broadly> using the wildcard asterisk character (C<*>). For
470 instance, to match I<'isa'> changes in any source:
471  
472 '*:isa'
473  
474 The system also accepts ambiguous/partial match strings and tries to "DWIM". So, the above can also
475 be written simply as:
476  
477 'isa'
478  
479 This is possible because 'isa' is understood/known as a I<type> keyword. Additionally, the system
480 knows the names of all the sources in advance, so the following filter string argument would match
481 everything in the 'Artist' source:
482  
483 'Artist'
484  
485 Sub-item names are automatically resolved, too. The following would match any column, relationship,
486 or constraint named C<'code'> in any source:
487  
488 'code'
489  
490 When you have schemas with overlapping names, such as a column named 'isa', you simply need to
491 supply more specific match strings, as ambiguous names are resolved with left-precedence. So, to
492 match any column, relationship, or constraint named 'isa', you could use the following:
493  
494 # Matches column, relationship, or constraints named 'isa':
495 '*:*/isa'
496  
497 Different delimiter characters are used for the source level (C<':'>) and the type level (C<'/'>)
498 so you can do things like match any column/relationship/constraint of a specific source, such as:
499  
500 Artist:code
501  
502 The above is equivalent to:
503  
504 Artist:*/code
505  
506 You can also supply a delimiter character to match a specific level explicitly. So, if you wanted to
507 match all changes to a I<source> named 'isa':
508  
509 # Matches a source (poorly) named 'isa'
510 'isa:'
511  
512 The same works at the type level. The following are all equivalent
513  
514 # Each of the following 3 filter strings are equivalent:
515 'columns/'
516 '*:columns/*'
517 'columns'
518  
519 Internally, L<Hash::Layout> is used to process the filter arguments.
520  
521 =head2 event filtering
522  
523 Besides matching specific parts of the schema, you can also filter by I<event>, which is either
524 I<'added'>, I<'deleted'> or I<'changed'> at both the source and type level (i.e. the event of a
525 new column is 'added' at the type level, but 'changed' at the source level).
526  
527 Filtering by event requires passing a HashRef argument to filter/filter_out, with the special
528 C<'events'> key matching 'type' events, and C<'source_events'> matching 'source' events. Both accept
529 either a string (when specifying only one event) or an ArrayRef:
530  
531 # Limit type (i.e. columns, relationships, etc) events to 'added'
532 $D = $D->filter({ events => 'added' });
533
534 # Exclude added and deleted sources:
535 $D = $D->filter_out({ source_events => ['added','deleted'] });
536
537 # Also excludes added and deleted sources:
538 $D = $D->filter({ source_events => ['changed'] });
539  
540  
541 =head1 EXAMPLES
542  
543 For examples, see the L<SYNOPSIS|DBIx::Class::Schema::Diff#SYNOPSIS> and also the unit tests in C<t/>
544 which has lots of working examples.
545  
546 =head1 BUGS/LIMITATIONS
547  
548 I'm not aware of any bugs at this point (although I'm sure there are some), but there are
549 several things to be aware of in general when using this tool that are worth mentioning:
550  
551 =over
552  
553 =item *
554  
555 Firstly, the diff packet is I<informational> only; it does not contain the information needed to
556 "patch" anything, or see the previous and new values. It assumes you already/still have access to the
557 old and new schemas to look up this info yourself. Its main purpose is simply to I<flag> which
558 items are changed.
559  
560 =item *
561  
562 Also, there is no deeper "diff" for 'added' and 'deleted' events because it is redundant. For an
563 added source, for example, you already know that every column, relationship, etc., that it contains
564 is also "added" (depending on your definition of "added"), so these are not included in the diff
565 for the purpose of reducing clutter. But, one side effect of this that you have to keep in mind is
566 that when filtering for all changes to 'columns', for example, this will not include columns in
567 added sources. This is just a design decision made early on (and it can't be both ways). It just
568 means if you want to check for the expanded definition of 'modified' columns, which include
569 added/deleted via a source, you must also test for added/deleted sources.
570  
571 In a later version, an additional layer of sugar methods could be added to provide convenient access
572 to some of these concepts.
573  
574 =item *
575  
576 As of version 1.1 filter string arguments I<are> glob patterns, so you can also do things like
577 C<'Arti*'> to match sub-strings. See the unit tests for examples.
578  
579 =item *
580  
581 Also, the special C<*> character can only be used in place of the predefined first 3 levels
582 (C<'*:*/*'>) and not within deeper column_info/relationship_info sub-hashes (so you can't match
583 C<'Artist:columns/foo.*.list'>). We're really splitting hairs at this point, but it is still worth
584 noting. (Internally, L<Hash::Layout> is used to process the filter arguments, so these limitations
585 have to do with the design of that package which provides more-useful flexibility in other areas)
586  
587 =item *
588  
589 In many practical cases, differences in loaded components will produce many more changes than just
590 'isa'. It depends on whether or not the components in question change the column/relationship infos.
591 One common example is L<InflateColumn::DateTime|DBIx::Class::InflateColumn::DateTime> which sets
592 inflator/deflators on all date columns. This is more of a feature than it is a limitation, but it
593 is something to keep in mind. If one side loads a component(s) like this but the other doesn't,
594 you'll have lots of differences to contend with that you might not actually care about. And, in
595 order to filter out these differences, you have to filter out a lot more than 'isa', which is
596 trivial. This is more about how DBIC works than anything else.
597  
598 One thing that I did to overcome this when there were lots of different loaded components that I
599 couldn't do anything about was to deploy both sides to a temp SQLite file, then create new schemas
600 (in memory) from those files with L<Schema::Loader|DBIx::Class::Schema::Loader>, using the same
601 options (and thus the same loaded components), and then run the diff on the two I<new> schemas.
602 This type of approach may not work or be appropriate in all scenarios; it obviously depends on
603 what exactly you are trying to accomplish.
604  
605  
606 =back
607  
608 =head1 SEE ALSO
609  
610 =over
611  
612 =item *
613  
614 L<DBIx::Class>
615  
616 =item *
617  
618 L<SQL::Translator::Diff>
619  
620 =item *
621  
622 L<DBIx::Class::Migration>
623  
624 =item *
625  
626 L<DBIx::Class::DeploymentHandler>
627  
628 =back
629  
630 =head1 AUTHOR
631  
632 Henry Van Styn <vanstyn@cpan.org>
633  
634 =head1 COPYRIGHT AND LICENSE
635  
636 This software is copyright (c) 2014 by IntelliTree Solutions llc.
637  
638 This is free software; you can redistribute it and/or modify it under
639 the same terms as the Perl 5 programming language system itself.
640  
641 =cut
« Diff/State.pm ↑ Summary Diff/Filter.pm »