| 1 | package App::DBICx::Backend::Move; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Run a database migration with DBICx::Backend::Move | ||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use base qw(App::Cmd::Simple); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use DBI; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Module::Load 'load'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | my $user = getlogin || getpwuid($<) || "unknown"; | ||||||||||||||||||||||||||||
|
Condition40%2/5
getlogin || getpwuid $< || 'unknown'
getlogin or getpwuid $<
MC/DC0%0/2
getlogin || getpwuid $< || 'unknown'
getlogin
getpwuid $<
Truth table33%1/3
A or B
A= getloginB= getpwuid $<
| |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 16 | return ( | ||||||||||||||||||||||||||||||
| 17 | 1 | [ "schema|s=s", "Name of the database schema", { required => 1 } ], | |||||||||||||||||||||||||||||
| 18 | [ "from_dsn|f=s", "DSN for source database", { required => 1 } ], | ||||||||||||||||||||||||||||||
| 19 | [ "to_dsn|t=s", "DSN for destination database", { required => 1 } ], | ||||||||||||||||||||||||||||||
| 20 | [ "from_user=s", "Username for source database; \$USER ($user) by default" ], | ||||||||||||||||||||||||||||||
| 21 | [ "from_pass=s", "Password for source database; empty by default" ], | ||||||||||||||||||||||||||||||
| 22 | [ "to_user=s", "Username for source database; \$USER ($user) by default" ], | ||||||||||||||||||||||||||||||
| 23 | [ "to_pass=s", "Password for source database; empty by default" ], | ||||||||||||||||||||||||||||||
| 24 | [ "rawmode", "Transfer raw values, without inflate/deflate" ], | ||||||||||||||||||||||||||||||
| 25 | [ "verbose|v+", "Be more verbose"], | ||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub validate_args { | ||||||||||||||||||||||||||||
|
Subroutine
validate_args: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 30 | 1 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | # no args allowed but options! | ||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | $self->usage_error("No args allowed") if @$args; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub execute { | ||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=6 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 37 | 1 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | my (undef, $driver ) = DBI->parse_dsn($opt->{to_dsn}) or die "Can't parse DBI DSN '$opt->{from_dsn}'"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 41 | 1 | my $module; | |||||||||||||||||||||||||||||
| 42 | 1 | given (lc($driver)) { | |||||||||||||||||||||||||||||
| 43 | 1 | when ('sqlite') { $module='DBICx::Backend::Move::SQLite' }; | |||||||||||||||||||||||||||||
| 44 | 0 | when ('pg') { $module='DBICx::Backend::Move::Psql' }; | |||||||||||||||||||||||||||||
| 45 | 0 | default { die "There is no migrator for driver '$driver'. This was parsed from $opt->{to_dsn}" }; | |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | 1 | load $module; | |||||||||||||||||||||||||||||
| 49 | 1 | my $migrator; | |||||||||||||||||||||||||||||
| 50 | 1 | $migrator = $module->new; | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | my $connect_from = [ $opt->{from_dsn}, $opt->{from_user} || $user, $opt->{from_pass} || '' ]; | ||||||||||||||||||||||||||||
|
Condition40%2/5
$opt->{'from_user'} || $user
$opt->{'from_pass'} || ''
MC/DC0%0/2
$opt->{'from_user'} || $user
$opt->{'from_user'}
$user
MC/DC0%0/1
$opt->{'from_pass'} || ''
$opt->{'from_pass'}
Truth table33%1/3
A || B
A= $opt->{'from_user'}B= $user
Truth table50%1/2
A
A= $opt->{'from_pass'}
| |||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | my $connect_to = [ $opt->{to_dsn}, $opt->{to_user} || $user, $opt->{to_pass} || '' ]; | ||||||||||||||||||||||||||||
|
Condition40%2/5
$opt->{'to_user'} || $user
$opt->{'to_pass'} || ''
MC/DC0%0/2
$opt->{'to_user'} || $user
$opt->{'to_user'}
$user
MC/DC0%0/1
$opt->{'to_pass'} || ''
$opt->{'to_pass'}
Truth table33%1/3
A || B
A= $opt->{'to_user'}B= $user
Truth table50%1/2
A
A= $opt->{'to_pass'}
| |||||||||||||||||||||||||||||||
| 55 | 1 | my $retval = $migrator->migrate($connect_from, $connect_to, $opt); | |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | 2 | 1; | |||||||||||||||||||||||||||||