blib/lib/Tapper/CLI/DbDeploy/Command/upgrade.pm

filter: Statementstmt 56.1% 32 / 57 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 10 / 16 Podpod 80.0% 4 / 5 totaltotal 50.5% 46 / 91 CC 6 SCAR 18.5
CC
6
Cov
47%
validate_args
20.0
run
12.0
opt_spec
2.0
CRAP 6.4
« blib/lib/Tapper/CLI/HostFeature.pm ↑ Summary blib/lib/Tapper/CLI/DbDeploy/Command/init.pm »
1 package Tapper::CLI::DbDeploy::Command::upgrade;
2 2 our $AUTHORITY = 'cpan:TAPPER';
3 2 $Tapper::CLI::DbDeploy::Command::upgrade::VERSION = '5.0.8';
4 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use parent 'App::Cmd::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Tapper::Model 'model';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Tapper::CLI::DbDeploy;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Tapper::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use File::ShareDir 'module_dir';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Tapper::Schema; # for module_dir
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub opt_spec {
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
19 return (
20 0 [ "verbose", "some more informational output" ],
21 [ "db=s", "STRING, one of: ReportsDB, TestrunDB" ],
22 [ "env=s", "STRING, default=development; one of: live, development, test" ],
23 [ "upgradedir=s", "STRING, directory where upgradefiles are stored, default=./upgrades/" ],
24 [ "fromversion=s","STRING" ],
25 [ "toversion=s", "STRING" ],
26 );
27 }
28  
29 # aktuelle Version und Diff erzeugen zur gewünschten vorherigen
30 # perl -Ilib -MTapper::Schema::ReportsDB -e 'Tapper::Schema::TestrunDB->connect("DBI:SQLite:foo")->create_ddl_dir([qw/MySQL SQLite PostgreSQL/], undef, "upgrades/", "2.010012") or die'
31  
32 0 ▶sub abstract {
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
33 0 'Upgrade a database schema'
34 }
35  
36 sub usage_desc
37 0 ▶{
Subroutine usage_desc: not called CC=1 SCAR=6.9
Pod documented
38 0 my ($self, $opt, $args) = @_;
39  
40 0 my $allowed_opts = join ' ', map { '--'.$_ } $self->_allowed_opts();
41 0 "tapper-db-deploy upgrade --db=DBNAME [ --verbose | --env=s ]";
42 }
43  
44 0 ▶sub _allowed_opts {
Subroutine _allowed_opts: not called CC=1 SCAR=6.9
45 0 my ($self, $opt, $args) = @_;
46 0 my @allowed_opts = map { $_->[0] } $self->opt_spec();
47 }
48  
49 0 ▶sub validate_args {
Subroutine validate_args: not called CC=4 SCAR=30.0
Pod documented
50 0 my ($self, $opt, $args) = @_;
51  
52 # print "opt = ", Dumper($opt);
53 # print "args = ", Dumper($args);
54  
55 0 my $ok = 1;
56 0 ▶ if (not $opt->{db})
Branch: 2 branches
BranchTrueFalseTotal
if (not $opt->{'db'}) { } 0 0 0
elsif (not $opt->{'db'} = 'TestrunDB') { } 0 0 0
57 {
58 0 say "Missing argument --db\n";
59 0 $ok = 0;
60 }
61 elsif (not $opt->{db} = 'TestrunDB')
62 {
63 0 say "Wrong DB name '".$opt->{db}."' (must be TestrunDB)";
64 0 $ok = 0;
65 }
66  
67 0 ▶ return $ok if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
68 0 die $self->usage->text;
69 }
70  
71 sub run
72 0 ▶{
Subroutine run: not called CC=3 SCAR=24.8
Pod undocumented
73 0 my ($self, $opt, $args) = @_;
74  
75 0 local $DBIx::Class::Schema::Versioned::DBICV_DEBUG = 1;
76  
77 0 Tapper::Config::_switch_context($opt->{env});
78  
79 0 my $db = $opt->{db};
80 0 ▶ my $upgradedir = $opt->{upgradedir} || module_dir('Tapper::Schema');
Condition0%0/3
$opt->{'upgradedir'} || module_dir('Tapper::Schema')
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt->{'upgradedir'} || module_dir('Tapper::Schema')
$opt->{'upgradedir'} module_dir('Tapper::Schema')
Truth table0%0/3
A || B
A= $opt->{'upgradedir'}B= module_dir('Tapper::Schema')
ABresult
1X1
011
000
81  
82 0 ▶ model($db)->upgrade_directory($upgradedir) if $upgradedir;
Branch: 1 branch
BranchTrueFalseTotal
if $upgradedir 0 0 0
83 0 model($db)->upgrade;
84 }
85  
86  
87 # perl -Ilib bin/tapper-db-deploy upgrade --db=TestrunDB
88  
89 2 1;
90  
91 __END__
« blib/lib/Tapper/CLI/HostFeature.pm ↑ Summary blib/lib/Tapper/CLI/DbDeploy/Command/init.pm »