Skip to content

Commit

Permalink
Check all dependencies before reverting.
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Dec 21, 2012
1 parent 2fd5f68 commit 23f802d
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 90 deletions.
7 changes: 4 additions & 3 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ Revision history for Perl extension App::Sqitch
converted to Sqitch, and you need to log changes as deployed because
they have been deployed by other means in the past.
- Now check that dependencies are required for all changes to be deployed
before deploying anything, rather than checkint for each change just
before deploying it. This allows a deploy to fail sooner, with no
database changes, when dependencies are not met.
or reverted before deploying or reverting anything, rather than
checking depdencies for each change just before deploying or reverting
it. This allows a or revert deploy to fail sooner, with no database
changes, when dependencies are not met.

0.940 2012-12-04T05:49:45Z
- Fixed tests that failed due to I18N issues, with thanks to Arnaud
Expand Down
63 changes: 46 additions & 17 deletions lib/App/Sqitch/Engine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ sub revert {
$c;
} reverse @changes;

# XXX Check for conflicts before reverting anything.
# Check that all dependencies will be satisfied.
$self->check_revert_dependencies(@changes);

# Do we want to support modes, where failures would re-deploy to previous
# tag or all the way back to the starting point? This would be very much
Expand Down Expand Up @@ -289,6 +290,35 @@ sub check_deploy_dependencies {
hurl deploy => join $/ => @msg;
}

sub check_revert_dependencies {
my $self = shift;
my $proj = $self->plan->project;
my (%seen, @msg);

for my $change (@_) {
$seen{ $change->id } = 1;
my @requiring = grep {
!$seen{ $_->{change_id} }
} $self->changes_requiring_change($change) or next;

# XXX Include change_id in the output?
push @msg => __nx(
'Change "{change}" required by currently deployed change: {changes}',
'Change "{change}" required by currently deployed changes: {changes}',
scalar @requiring,
change => $change->format_name_with_tags,
changes => join ' ', map {
($_->{project} eq $proj ? '' : "$_->{project}:" )
. $_->{change}
. ($_->{asof_tag} // '')
} @requiring
);
}

hurl revert => join $/, @msg if @msg;
return $self;
}

sub change_id_for_depend {
my ( $self, $dep ) = @_;
hurl engine => __x(
Expand Down Expand Up @@ -490,21 +520,6 @@ sub revert_change {
$self->sqitch->info(' - ', $change->format_name_with_tags);
$self->begin_work($change);

if (my @requiring = $self->changes_requiring_change($change)) {
my $proj = $self->plan->project;
# XXX Include change_id in the output?
hurl revert => __nx(
'Required by currently deployed change: {changes}',
'Required by currently deployed changes: {changes}',
scalar @requiring,
changes => join ' ', map {
($_->{project} eq $proj ? '' : "$_->{project}:" )
. $_->{change}
. ($_->{asof_tag} // '')
} @requiring,
);
}

try {
$self->run_file($change->revert_file) unless $log_only;
try {
Expand Down Expand Up @@ -849,7 +864,21 @@ scripts>.
Validates that all dependencies will be met for all changes to be deployed,
starting with the currently-deployed change up to the specified index, or to
the last change in the plan if no index is passed.
the last change in the plan if no index is passed. If any of the changes to be
deployed would conflict with previously-deployed changes or are missing any
required changes, an exception will be thrown. Used internally by C<deploy()>
to ensure that dependencies will be satisfied before deploying any changes.
=head3 C<check_revert_dependencies>
$engine->check_revert_dependencies(@changes);
Validates that the list of changes to be reverted, which should be passed in
the order in which they will be reverted, are not depended upon by other
changes. If any are depended upon by other changes, an exception will be
thrown listing the changes that cannot be reverted and what changes depend on
them. Used internally by C<revert()> to ensure no dependencies will be
violated before revering any changes.
=head3 C<deploy_change>
Expand Down
Loading

0 comments on commit 23f802d

Please sign in to comment.