| 1 | package ORLite::Migrate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # See POD at end of file for documentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use File::Spec 3.2701 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use File::Path 2.04 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Params::Util 0.37 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use DBI 1.58 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use DBD::SQLite 1.21 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use ORLite 1.28 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use vars qw{$VERSION @ISA}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | $VERSION = '1.10'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | @ISA = 'ORLite'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=37 SCAR=47.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | my $class = ref $_[0] || $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Check for debug mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | if ( defined Params::Util::_STRING($_[-1]) and $_[-1] eq '-DEBUG' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined &Params::Util::_STRING($_[-1]) and $_[-1] eq "-DEBUG"
MC/DC0%0/2
defined &Params::Util::_STRING($_[-1]) and $_[-1] eq "-DEBUG"
defined &Params::Util::_STRING($_[-1])
$_[-1] eq "-DEBUG"
Truth table33%1/3
A and B
A= defined &Params::Util::_STRING($_[-1])B= $_[-1] eq "-DEBUG"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $DEBUG = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | pop @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # Check params and apply defaults | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | my %params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | if ( defined Params::Util::_STRING($_[1]) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Migrate needs at least two params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | Carp::croak("ORLite::Migrate must be invoked in HASH form"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } elsif ( Params::Util::_HASH($_[1]) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | %params = %{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | Carp::croak("Missing, empty or invalid params HASH"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | if ( $params{timeline} and not defined $params{create} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$params{"timeline"} and not defined $params{"create"}
MC/DC50%1/2
$params{"timeline"} and not defined $params{"create"}
$params{"timeline"}
not defined $params{"create"}
Truth table66%2/3
A and not(B)
A= $params{"timeline"}B= not defined $params{"create"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | $params{create} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | $params{create} = $params{create} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | unless ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined &Params::Util::_STRING($params{"file"}) and $params{"create"} || -f $params{"file"}
$params{"create"} or -f $params{"file"}
MC/DC0%0/3
defined &Params::Util::_STRING($params{"file"}) and $params{"create"} || -f $params{"file"}
defined &Params::Util::_STRING($params{"file"})
$params{"create"}
-f $params{"file"}
Truth table25%1/4
A and B or C
A= defined &Params::Util::_STRING($params{"file"})B= $params{"create"}C= -f $params{"file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | defined Params::Util::_STRING($params{file}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | and ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $params{create} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | -f $params{file} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | Carp::croak("Missing or invalid file param"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | unless ( defined $params{readonly} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | $params{readonly} = $params{create} ? 0 : ! -w $params{file}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | unless ( defined $params{tables} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | $params{tables} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | ▶ | unless ( defined $params{package} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | $params{package} = scalar caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | unless ( Params::Util::_CLASS($params{package}) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | Carp::croak("Missing or invalid package class"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | unless ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
&Params::Util::_DRIVER($params{"timeline"}, "ORLite::Migrate::Timeline") or $params{"timeline"} and -d $params{"timeline"} and -r $params{"timeline"}
$params{"timeline"} and -d $params{"timeline"} and -r $params{"timeline"}
$params{"timeline"} and -d $params{"timeline"}
MC/DC0%0/4
&Params::Util::_DRIVER($params{"timeline"}, "ORLite::Migrate::Timeline") or $params{"timeline"} and -d $params{"timeline"} and -r $params{"timeline"}
&Params::Util::_DRIVER($params{"timeline"}, "ORLite::Migrate::Timeline")
$params{"timeline"}
-d $params{"timeline"}
-r $params{"timeline"}
Truth table40%2/5
A or B and C and D
A= &Params::Util::_DRIVER($params{"timeline"}, "ORLite::Migrate::Timeline")B= $params{"timeline"}C= -d $params{"timeline"}D= -r $params{"timeline"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | Params::Util::_DRIVER($params{timeline}, 'ORLite::Migrate::Timeline') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ($params{timeline} and -d $params{timeline} and -r $params{timeline}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | Carp::croak("Missing or invalid timeline"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # We don't support readonly databases | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | if ( $params{readonly} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | Carp::croak("ORLite::Migrate does not support readonly databases"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Get the schema version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | my $file = File::Spec->rel2abs($params{file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $created = ! -f $params{file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | if ( $created ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # Create the parent directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | my $dir = File::Basename::dirname($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | ▶ | unless ( -d $dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my @dirs = File::Path::mkpath( $dir, { verbose => 0 } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $class->prune(@dirs) if $params{prune}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | $class->prune($file) if $params{prune}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | my $dsn = "dbi:SQLite:$file"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | my $dbh = DBI->connect($dsn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | my $version = $dbh->selectrow_arrayref('pragma user_version')->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | $dbh->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # We're done with the prune setting now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | $params{prune} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Handle the migration class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | if ( Params::Util::_DRIVER($params{timeline}, 'ORLite::Migrate::Timeline') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | my $timeline = $params{timeline}->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | dbh => DBI->connect($dsn), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | $timeline->upgrade( $params{user_version} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | my $timeline = File::Spec->rel2abs($params{timeline}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | my @plan = plan( $params{timeline}, $version ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # Execute the migration plan | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | if ( @plan ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Does the migration plan reach the required destination | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | my $destination = $version + scalar(@plan); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params{"user_version"} and $destination != $params{"user_version"}
MC/DC0%0/2
exists $params{"user_version"} and $destination != $params{"user_version"}
exists $params{"user_version"}
$destination != $params{"user_version"}
Truth table33%1/3
A and B
A= exists $params{"user_version"}B= $destination != $params{"user_version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | exists $params{user_version} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | $destination != $params{user_version} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | die "Schema migration destination user_version mismatch (got $destination, wanted $params{user_version})"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # Load the modules needed for the migration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | require Probe::Perl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | require File::pushd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | require IPC::Run3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Locate our Perl interpreter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | my $perl = Probe::Perl->find_perl_interpreter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | unless ( $perl ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | Carp::croak("Unable to locate your perl executable"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Execute each script | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | my $pushd = File::pushd::pushd($timeline); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | foreach my $patch ( @plan ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | my $stdin = "$file\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | ▶ | if ( $DEBUG ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | print STDERR "Applying schema patch $patch...\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | ▶ | my $ok = IPC::Run3::run3( [ $perl, $patch ], \$stdin, \undef, $DEBUG ? undef : \undef ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | ▶ | if ( ! $ok or $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $ok or $? != 0
MC/DC0%0/2
not $ok or $? != 0
not $ok
$? != 0
Truth table33%1/3
not(A) or B
A= not $okB= $? != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | Carp::croak("Migration patch $patch failed, database in unknown state"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # Migration complete, set user_version to new state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $dbh = DBI->connect($dsn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $dbh->do("pragma user_version = $destination"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | $dbh->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # Hand off to the regular constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | ▶ | $class->SUPER::import( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | \%params, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | $DEBUG ? '-DEBUG' : () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # Simple Methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | ▶ | sub patches { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
patches: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | my $dir = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # Find all files in a directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | local *DIR; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 3 | ▶ | opendir( DIR, $dir ) or die "opendir: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | ▶ | my @files = readdir( DIR ) or die "readdir: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | ▶ | closedir( DIR ) or die "closedir: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # Filter to get the patch set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | my @patches = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | foreach ( @files ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 15 | ▶ | next unless /^migrate-(\d+)\.pl$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 9 | $patches["$1"] = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | return @patches; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | ▶ | sub plan { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plan: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | my $directory = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | my $version = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # Find the list of patches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | my @patches = patches( $directory ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # Assemble the plan by integer stepping forwards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # until we run out of timeline hits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 2 | my @plan = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | ▶ | while ( $patches[++$version] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 5 | push @plan, $patches[$version]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | return @plan; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||