| 1 | package Tapper::CLI::DbDeploy::Command::saveschema; | ||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||
| 3 | 2 | $Tapper::CLI::DbDeploy::Command::saveschema::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 | |||||||||||||||||||||
| 16 | 0 | ▶ | sub opt_spec { | ||||||||||||||||||
|
Subroutine
opt_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 17 | return ( | ||||||||||||||||||||
| 18 | 0 | [ "verbose", "some more informational output" ], | |||||||||||||||||||
| 19 | [ "really", "Really do something." ], | ||||||||||||||||||||
| 20 | [ "db=s", "STRING, one of: ReportsDB, TestrunDB" ], | ||||||||||||||||||||
| 21 | [ "env=s", "STRING, default=development; one of: live, development, test" ], | ||||||||||||||||||||
| 22 | [ "upgradedir=s", "STRING, directory here upgradefiles are stored" ], | ||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | sub abstract { | ||||||||||||||||||
|
Subroutine
abstract: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 27 | 0 | 'Save an initial database schema if no previous schema exists' | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | sub usage_desc | ||||||||||||||||||||
| 31 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
usage_desc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 32 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||
| 33 | 0 | my $allowed_opts = join ' ', map { '--'.$_ } $self->_allowed_opts(); | |||||||||||||||||||
| 34 | 0 | "tapper-db-deploy saveschema --db=DBNAME [ --verbose | --env=s ]*"; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | ▶ | sub _allowed_opts { | ||||||||||||||||||
|
Subroutine
_allowed_opts: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 38 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||
| 39 | 0 | my @allowed_opts = map { $_->[0] } $self->opt_spec(); | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | sub validate_args { | ||||||||||||||||||
|
Subroutine
validate_args: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 43 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | # print "opt = ", Dumper($opt); | ||||||||||||||||||||
| 46 | # print "args = ", Dumper($args); | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | my $ok = 1; | |||||||||||||||||||
| 49 | 0 | ▶ | if (not $opt->{db}) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 50 | { | ||||||||||||||||||||
| 51 | 0 | say "Missing argument --db\n"; | |||||||||||||||||||
| 52 | 0 | $ok = 0; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | elsif (not $opt->{db} = 'TestrunDB') | ||||||||||||||||||||
| 55 | { | ||||||||||||||||||||
| 56 | 0 | say "Wrong DB name '".$opt->{db}."' (must be TestrunDB)"; | |||||||||||||||||||
| 57 | 0 | $ok = 0; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | return $ok if $ok; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | die $self->usage->text; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | sub run | ||||||||||||||||||||
| 65 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
run: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 66 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | ▶ | unless ($opt->{really}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 0 | say "You nearly never want to call me -- only if no previous schema exists."; | |||||||||||||||||||
| 70 | 0 | say "You probably want to call: tapper-db-deploy makeschemadiffs ..."; | |||||||||||||||||||
| 71 | 0 | say "Or use option --really if you know what you do"; | |||||||||||||||||||
| 72 | 0 | exit 1; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 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}; | |||||||||||||||||||
| 81 | 0 | ▶ | model($db)->upgrade_directory($upgradedir) if $upgradedir; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 0 | ▶ | model($db)->create_ddl_dir([qw/MySQL SQLite PostgreSQL/], | ||||||||||||||||||
|
Condition0%0/3
$upgradedir || model($db)->upgrade_directory
MC/DC0%0/2
$upgradedir || model($db)->upgrade_directory
$upgradedir
model($db)->upgrade_directory
Truth table0%0/3
A || B
A= $upgradedirB= model($db)->upgrade_directory
| |||||||||||||||||||||
| 83 | undef, | ||||||||||||||||||||
| 84 | ($upgradedir || model($db)->upgrade_directory) | ||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | # perl -Ilib bin/tapper-db-deploy saveschema --db=TestrunDB | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 2 | 1; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||