| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | use 5.010; | 
| 3 | 2 |  |  | 2 |  | 1660 | use strict; | 
|  | 2 |  |  |  |  | 7 |  | 
| 4 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 38 |  | 
| 5 | 2 |  |  | 2 |  | 8 | use utf8; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 49 |  | 
| 6 | 2 |  |  | 2 |  | 8 | use Moo; | 
|  | 2 |  |  |  |  | 17 |  | 
|  | 2 |  |  |  |  | 12 |  | 
| 7 | 2 |  |  | 2 |  | 44 | use App::Sqitch::Types qw(Int URI Str Bool HashRef); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 11 |  | 
| 8 | 2 |  |  | 2 |  | 730 | use Locale::TextDomain qw(App-Sqitch); | 
|  | 2 |  |  |  |  | 132 |  | 
|  | 2 |  |  |  |  | 33 |  | 
| 9 | 2 |  |  | 2 |  | 2048 | use Type::Utils qw(enum); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 14 |  | 
| 10 | 2 |  |  | 2 |  | 367 | use App::Sqitch::X qw(hurl); | 
|  | 2 |  |  |  |  | 76 |  | 
|  | 2 |  |  |  |  | 25 |  | 
| 11 | 2 |  |  | 2 |  | 980 | use List::Util qw(first); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 17 |  | 
| 12 | 2 |  |  | 2 |  | 536 | use namespace::autoclean; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 112 |  | 
| 13 | 2 |  |  | 2 |  | 11 |  | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 12 |  | 
| 14 |  |  |  |  |  |  | extends 'App::Sqitch::Command'; | 
| 15 |  |  |  |  |  |  | with 'App::Sqitch::Role::ContextCommand'; | 
| 16 |  |  |  |  |  |  | with 'App::Sqitch::Role::ConnectingCommand'; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | our $VERSION = 'v1.3.0'; # VERSION | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | has target => ( | 
| 21 |  |  |  |  |  |  | is  => 'ro', | 
| 22 |  |  |  |  |  |  | isa => Str, | 
| 23 |  |  |  |  |  |  | ); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | has to_change => ( | 
| 26 |  |  |  |  |  |  | is  => 'ro', | 
| 27 |  |  |  |  |  |  | isa => Str, | 
| 28 |  |  |  |  |  |  | ); | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | has mode => ( | 
| 31 |  |  |  |  |  |  | is  => 'ro', | 
| 32 |  |  |  |  |  |  | isa => enum([qw( | 
| 33 |  |  |  |  |  |  | change | 
| 34 |  |  |  |  |  |  | tag | 
| 35 |  |  |  |  |  |  | all | 
| 36 |  |  |  |  |  |  | )]), | 
| 37 |  |  |  |  |  |  | default => 'all', | 
| 38 |  |  |  |  |  |  | ); | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | has log_only => ( | 
| 41 |  |  |  |  |  |  | is       => 'ro', | 
| 42 |  |  |  |  |  |  | isa      => Bool, | 
| 43 |  |  |  |  |  |  | default  => 0, | 
| 44 |  |  |  |  |  |  | ); | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | has lock_timeout => ( | 
| 47 |  |  |  |  |  |  | is      => 'ro', | 
| 48 |  |  |  |  |  |  | isa     => Int, | 
| 49 |  |  |  |  |  |  | lazy    => 1, | 
| 50 |  |  |  |  |  |  | default => sub { App::Sqitch::Engine::default_lock_timeout() }, | 
| 51 |  |  |  |  |  |  | ); | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | has verify => ( | 
| 54 |  |  |  |  |  |  | is       => 'ro', | 
| 55 |  |  |  |  |  |  | isa      => Bool, | 
| 56 |  |  |  |  |  |  | default  => 0, | 
| 57 |  |  |  |  |  |  | ); | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | has variables => ( | 
| 60 |  |  |  |  |  |  | is       => 'ro', | 
| 61 |  |  |  |  |  |  | isa      => HashRef, | 
| 62 |  |  |  |  |  |  | lazy     => 1, | 
| 63 |  |  |  |  |  |  | default  => sub { {} }, | 
| 64 |  |  |  |  |  |  | ); | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | return qw( | 
| 67 |  |  |  |  |  |  | target|t=s | 
| 68 |  |  |  |  |  |  | to-change|to|change=s | 
| 69 |  |  |  |  |  |  | mode=s | 
| 70 |  |  |  |  |  |  | set|s=s% | 
| 71 |  |  |  |  |  |  | log-only | 
| 72 |  |  |  |  |  |  | lock-timeout=i | 
| 73 |  |  |  |  |  |  | verify! | 
| 74 |  |  |  |  |  |  | ); | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | my ( $class, $config, $opt ) = @_; | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | my %params = ( | 
| 80 |  |  |  |  |  |  | mode     => $opt->{mode}   || $config->get( key => 'deploy.mode' )   || 'all', | 
| 81 |  |  |  |  |  |  | verify   => $opt->{verify} // $config->get( key => 'deploy.verify', as => 'boolean' ) // 0, | 
| 82 |  |  |  |  |  |  | log_only => $opt->{log_only} || 0, | 
| 83 |  |  |  |  |  |  | ); | 
| 84 |  |  |  |  |  |  | for my $key (qw(to_change target lock_timeout)) { | 
| 85 |  |  |  |  |  |  | $params{$key} = $opt->{$key} if exists $opt->{$key}; | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  | if ( my $vars = $opt->{set} ) { | 
| 88 |  |  |  |  |  |  | $params{variables} = $vars; | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | return \%params; | 
| 92 |  |  |  |  |  |  | } | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | my ($self, $target) = @_; | 
| 95 |  |  |  |  |  |  | my $cfg = $self->sqitch->config; | 
| 96 |  |  |  |  |  |  | return ( | 
| 97 |  |  |  |  |  |  | %{ $cfg->get_section(section => 'core.variables') }, | 
| 98 | 15 |  |  | 15 |  | 449 | %{ $cfg->get_section(section => 'deploy.variables') }, | 
| 99 | 15 |  |  |  |  | 244 | %{ $target->variables }, # includes engine | 
| 100 |  |  |  |  |  |  | %{ $self->variables },   # --set | 
| 101 | 15 |  |  |  |  | 57 | ); | 
| 102 | 15 |  |  |  |  | 39 | } | 
| 103 | 15 |  |  |  |  | 242 |  | 
| 104 | 15 |  |  |  |  | 96 | my $self = shift; | 
|  | 15 |  |  |  |  | 513 |  | 
| 105 |  |  |  |  |  |  | my ($targets, $changes) = $self->parse_args( | 
| 106 |  |  |  |  |  |  | target => $self->target, | 
| 107 |  |  |  |  |  |  | args   => \@_, | 
| 108 |  |  |  |  |  |  | ); | 
| 109 | 11 |  |  | 11 | 1 | 18205 |  | 
| 110 | 11 |  |  |  |  | 50 | # Warn on multiple targets. | 
| 111 |  |  |  |  |  |  | my $target = shift @{ $targets }; | 
| 112 |  |  |  |  |  |  | $self->warn(__x( | 
| 113 |  |  |  |  |  |  | 'Too many targets specified; connecting to {target}', | 
| 114 |  |  |  |  |  |  | target => $target->name, | 
| 115 |  |  |  |  |  |  | )) if @{ $targets }; | 
| 116 | 9 |  |  |  |  | 418 |  | 
|  | 9 |  |  |  |  | 17 |  | 
| 117 |  |  |  |  |  |  | # Warn on too many changes. | 
| 118 |  |  |  |  |  |  | my $change = $self->to_change // shift @{ $changes }; | 
| 119 |  |  |  |  |  |  | $self->warn(__x( | 
| 120 | 9 | 100 |  |  |  | 13 | 'Too many changes specified; deploying to "{change}"', | 
|  | 9 |  |  |  |  | 25 |  | 
| 121 |  |  |  |  |  |  | change => $change, | 
| 122 |  |  |  |  |  |  | )) if @{ $changes }; | 
| 123 | 9 |  | 100 |  |  | 143 |  | 
|  | 6 |  |  |  |  | 15 |  | 
| 124 |  |  |  |  |  |  | # Now get to work. | 
| 125 |  |  |  |  |  |  | my $engine = $target->engine; | 
| 126 |  |  |  |  |  |  | $engine->with_verify( $self->verify ); | 
| 127 | 9 | 100 |  |  |  | 12 | $engine->log_only( $self->log_only ); | 
|  | 9 |  |  |  |  | 28 |  | 
| 128 |  |  |  |  |  |  | $engine->lock_timeout( $self->lock_timeout ); | 
| 129 |  |  |  |  |  |  | $engine->set_variables( $self->_collect_vars($target) ); | 
| 130 | 9 |  |  |  |  | 632 | $engine->deploy( $change, $self->mode ); | 
| 131 | 9 |  |  |  |  | 1556 | return $self; | 
| 132 | 9 |  |  |  |  | 308 | } | 
| 133 | 9 |  |  |  |  | 278 |  | 
| 134 | 9 |  |  |  |  | 367 | 1; | 
| 135 | 9 |  |  |  |  | 164 |  | 
| 136 | 9 |  |  |  |  | 72 |  | 
| 137 |  |  |  |  |  |  | =head1 Name | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | App::Sqitch::Command::deploy - Deploy Sqitch changes to a database | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =head1 Synopsis | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | my $cmd = App::Sqitch::Command::deploy->new(%params); | 
| 144 |  |  |  |  |  |  | $cmd->execute; | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | =head1 Description | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | If you want to know how to use the C<deploy> command, you probably want to be | 
| 149 |  |  |  |  |  |  | reading C<sqitch-deploy>. But if you really want to know how the C<deploy> command | 
| 150 |  |  |  |  |  |  | works, read on. | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | =head1 Interface | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | =head2 Class Methods | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | =head3 C<options> | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | my @opts = App::Sqitch::Command::deploy->options; | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | Returns a list of L<Getopt::Long> option specifications for the command-line | 
| 161 |  |  |  |  |  |  | options for the C<deploy> command. | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | =head2 Attributes | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | =head3 C<log_only> | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | Boolean indicating whether to log the deploy without running the scripts. | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | =head3 C<lock_timeout> | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | The number of seconds to wait for an exclusive advisory lock on the target, | 
| 172 |  |  |  |  |  |  | for engines that support the feature. | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | =head3 C<mode> | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | Deploy mode, one of "change", "tag", or "all". | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | =head3 C<target> | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | The deployment target URI. | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | =head3 C<to_change> | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  | Change up to which to deploy. | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | =head3 C<verify> | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  | Boolean indicating whether or not to run verify scripts after each change. | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | =head2 Instance Methods | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | =head3 C<execute> | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | $deploy->execute; | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  |  |  |  | Executes the deploy command. | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | =head1 See Also | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | =over | 
| 201 |  |  |  |  |  |  |  | 
| 202 |  |  |  |  |  |  | =item L<sqitch-deploy> | 
| 203 |  |  |  |  |  |  |  | 
| 204 |  |  |  |  |  |  | Documentation for the C<deploy> command to the Sqitch command-line client. | 
| 205 |  |  |  |  |  |  |  | 
| 206 |  |  |  |  |  |  | =item L<sqitch> | 
| 207 |  |  |  |  |  |  |  | 
| 208 |  |  |  |  |  |  | The Sqitch command-line client. | 
| 209 |  |  |  |  |  |  |  | 
| 210 |  |  |  |  |  |  | =back | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | =head1 Author | 
| 213 |  |  |  |  |  |  |  | 
| 214 |  |  |  |  |  |  | David E. Wheeler <david@justatheory.com> | 
| 215 |  |  |  |  |  |  |  | 
| 216 |  |  |  |  |  |  | =head1 License | 
| 217 |  |  |  |  |  |  |  | 
| 218 |  |  |  |  |  |  | Copyright (c) 2012-2022 iovation Inc., David E. Wheeler | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | Permission is hereby granted, free of charge, to any person obtaining a copy | 
| 221 |  |  |  |  |  |  | of this software and associated documentation files (the "Software"), to deal | 
| 222 |  |  |  |  |  |  | in the Software without restriction, including without limitation the rights | 
| 223 |  |  |  |  |  |  | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
| 224 |  |  |  |  |  |  | copies of the Software, and to permit persons to whom the Software is | 
| 225 |  |  |  |  |  |  | furnished to do so, subject to the following conditions: | 
| 226 |  |  |  |  |  |  |  | 
| 227 |  |  |  |  |  |  | The above copyright notice and this permission notice shall be included in all | 
| 228 |  |  |  |  |  |  | copies or substantial portions of the Software. | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
| 231 |  |  |  |  |  |  | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
| 232 |  |  |  |  |  |  | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
| 233 |  |  |  |  |  |  | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
| 234 |  |  |  |  |  |  | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
| 235 |  |  |  |  |  |  | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
| 236 |  |  |  |  |  |  | SOFTWARE. | 
| 237 |  |  |  |  |  |  |  | 
| 238 |  |  |  |  |  |  | =cut |