| 1 | package DBIO::MSSQL::Diff::Schema; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Diff operations for MSSQL schemas | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 36 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 36 | ▶ | use base 'DBIO::Diff::Op'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 36 | ▶ | use DBIO::MSSQL::DDL qw(_quote_ident _schema_prefix); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 36 | __PACKAGE__->mk_diff_accessors(qw/schema_name/); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 94 | ▶ | sub diff { | ||||||||||||||||||||||||||
|
Subroutine
diff: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 94 | my ($class, $source, $target) = @_; | |||||||||||||||||||||||||||
| 19 | 94 | my $coll = $source->{collation}; | |||||||||||||||||||||||||||
| 20 | 0 | ▶ | my $fold = $coll && !$coll->{case_sensitive} ? sub { lc $_[0] } : sub { $_[0] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition100%3/3
$coll and not $coll->{"case_sensitive"}
MC/DC100%2/2
$coll and not $coll->{"case_sensitive"}
$coll
not $coll->{"case_sensitive"}
Truth table100%3/3
A and not(B)
A= $collB= not $coll->{"case_sensitive"}
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 94 | my %have = (dbo => 1); | |||||||||||||||||||||||||||
| 23 | 94 | ▶ | $have{ $fold->($_) } = 1 for keys %{ $source->{schemas} // {} }; | ||||||||||||||||||||||||||
|
Condition100%2/2
$source->{"schemas"} // {}
MC/DC100%1/1
$source->{"schemas"} // {}
$source->{"schemas"}
Truth table100%2/2
A
A= $source->{"schemas"}
| |||||||||||||||||||||||||||||
| 24 | 94 | ▶ | for my $name (keys %{ $source->{tables} // {} }) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$source->{"tables"} // {}
MC/DC0%0/1
$source->{"tables"} // {}
$source->{"tables"}
Truth table50%1/2
A
A= $source->{"tables"}
| |||||||||||||||||||||||||||||
| 25 | 128 | ▶ | $have{ $fold->($1) } = 1 if $name =~ /\A([^.]+)\./; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 94 | my (%want); | |||||||||||||||||||||||||||
| 29 | 94 | ▶ | my $tables = $target->{tables} // {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$target->{"tables"} // {}
MC/DC0%0/1
$target->{"tables"} // {}
$target->{"tables"}
Truth table50%1/2
A
A= $target->{"tables"}
| |||||||||||||||||||||||||||||
| 30 | 94 | for my $name (keys %$tables) { | |||||||||||||||||||||||||||
| 31 | 146 | ▶ | next unless $name =~ /\A([^.]+)\./; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 7 | my $schema = $1; | |||||||||||||||||||||||||||
| 33 | 7 | ▶ | $want{$schema} = 1 unless $have{ $fold->($schema) }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 94 | return map { $class->new(action => 'create', schema_name => $_) } sort keys %want; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | sub as_sql { | ||||||||||||||||||||||||||
|
Subroutine
as_sql: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 41 | 2 | return sprintf 'CREATE SCHEMA %s;', _quote_ident($self->schema_name); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub summary { | ||||||||||||||||||||||||||
|
Subroutine
summary: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 47 | 1 | return sprintf '%s schema: %s', $self->summary_prefix, $self->schema_name; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 36 | 1; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||