Sybase/Diff.pm

filter: Statementstmt 100% 59 / 59 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 100% 68 / 68 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Sybase.pm ↑ Summary
1 package DBIO::Sybase::Diff;
2 # ABSTRACT: Compare two introspected Sybase ASE models
3  
4 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 31 our $VERSION = '0.900007';
8  
9 31 ▶use base 'DBIO::Diff::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 31 ▶use DBIO::Sybase::Diff::Table ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 31 ▶use DBIO::Sybase::Diff::Column ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 31 ▶use DBIO::Sybase::Diff::Index ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 31 ▶use DBIO::Sybase::Diff::ForeignKey ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 31 ▶use DBIO::Sybase::Diff::View ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 50 ▶sub _build_operations {
Subroutine _build_operations: called CC=1 SCAR=0.0
19 50 my ($self) = @_;
20 50 my @ops;
21  
22 # Foreign keys are diffed once, then split: drops must precede table/column
23 # drops, adds must follow table/column creates. ASE FKs are not altered in
24 # place, so an attribute change is already a drop+create pair from ::ForeignKey.
25 my @fk_ops = DBIO::Sybase::Diff::ForeignKey->diff(
26 $self->source->{foreign_keys}, $self->target->{foreign_keys},
27 $self->source->{tables}, $self->target->{tables},
28 50 );
29 50 my @fk_drops = grep { $_->action eq 'drop' } @fk_ops;
30 50 my @fk_adds = grep { $_->action eq 'create' } @fk_ops;
31  
32 # Indexes are diffed once, then split the same way FKs are: ASE refuses to
33 # drop a column while an index still references it, so an index DROP must
34 # precede the column diff. A CREATE/ALTER must FOLLOW it -- a new or changed
35 # column has to exist before an index can name it (an ::Index alter is itself
36 # a DROP+CREATE pair whose create half references the column, so it belongs
37 # with the creates).
38 my @idx_ops = DBIO::Sybase::Diff::Index->diff(
39 $self->source->{indexes}, $self->target->{indexes},
40 50 );
41 50 my @idx_drops = grep { $_->action eq 'drop' } @idx_ops;
42 50 my @idx_creates = grep { $_->action ne 'drop' } @idx_ops;
43  
44 # Primary keys of retained tables (karr k53), split like the indexes: the
45 # drop before the column diff (a key column may be about to go), the add
46 # after it (a key column may be about to be added or made NOT NULL) and
47 # before the FK adds (a new reference may need the new key).
48 my @pk_ops = DBIO::Sybase::Diff::Table->diff_primary_keys(
49 $self->source->{tables}, $self->target->{tables},
50 $self->source->{columns}, $self->target->{columns},
51 $self->source->{indexes},
52 50 );
53 50 my @pk_drops = grep { $_->action eq 'drop' } @pk_ops;
54 50 my @pk_adds = grep { $_->action ne 'drop' } @pk_ops;
55  
56 # Views (karr k98): the ones removed or changed go before any change to the
57 # tables under them, the new and changed ones are created last, when every
58 # table and column they read exists. Between views the order is that of their
59 # dependencies.
60 my @view_ops = DBIO::Sybase::Diff::View->diff(
61 50 $self->source->{views}, $self->target->{views});
62 50 my @view_drops = grep { $_->action eq 'drop' } @view_ops;
63 50 my @view_creates = grep { $_->action eq 'create' } @view_ops;
64  
65 50 push @ops, @fk_drops;
66 50 push @ops, @view_drops;
67 push @ops, DBIO::Sybase::Diff::Table->diff(
68 $self->source->{tables}, $self->target->{tables},
69 $self->target->{columns}, $self->target->{foreign_keys},
70 50 );
71 50 push @ops, @pk_drops;
72 50 push @ops, @idx_drops;
73 push @ops, DBIO::Sybase::Diff::Column->diff(
74 $self->source->{columns}, $self->target->{columns},
75 $self->source->{tables}, $self->target->{tables},
76 50 );
77 50 push @ops, @pk_adds;
78 50 push @ops, @idx_creates;
79 50 push @ops, @fk_adds;
80 50 push @ops, @view_creates;
81  
82 50 return \@ops;
83 }
84  
85  
86 31 1;
87  
88 __END__
« Sybase.pm ↑ Summary