Skip to content

Commit f9f7dea

Browse files
committed
mapping script: require specifying a source index if copying
1 parent 967b34e commit f9f7dea

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/MetaCPAN/Script/Mapping.pm

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ has skip_existing_mapping => (
8686
documentation => 'do NOT copy mappings other than patch_mapping',
8787
);
8888

89+
has copy_from_index => (
90+
is => 'ro',
91+
isa => Str,
92+
documentation => 'index to copy type from',
93+
);
94+
8995
has copy_to_index => (
9096
is => 'ro',
9197
isa => Str,
@@ -336,9 +342,13 @@ sub create_index {
336342

337343
sub copy_type {
338344
my ( $self, $index, $type ) = @_;
339-
$index //= $self->copy_to_index;
345+
my $from_index = $self->copy_from_index
346+
or die "can't copy without a source index";
347+
$index //= $self->copy_to_index
348+
or die "can't copy without a destination index";
340349

341-
$self->_check_index_exists( $index, EXPECTED );
350+
$self->_check_index_exists( $from_index, EXPECTED );
351+
$self->_check_index_exists( $index, EXPECTED );
342352
$type //= $self->arg_copy_type;
343353
$type or die "can't copy without a type\n";
344354

@@ -358,7 +368,7 @@ sub copy_type {
358368
};
359369
}
360370

361-
return $self->_copy_slice( $query, $index, $type ) if $query;
371+
return $self->_copy_slice( $query, $from_index, $index, $type ) if $query;
362372

363373
# else ... do copy by monthly slices
364374

@@ -374,7 +384,7 @@ sub copy_type {
374384

375385
log_info {"copying data for month: $gte"};
376386
eval {
377-
$self->_copy_slice( $q, $index, $type );
387+
$self->_copy_slice( $q, $from_index, $index, $type );
378388
1;
379389
} or do {
380390
my $err = $@ || 'zombie error';
@@ -384,12 +394,12 @@ sub copy_type {
384394
}
385395

386396
sub _copy_slice {
387-
my ( $self, $query, $index, $type ) = @_;
397+
my ( $self, $query, $from_index, $index, $type ) = @_;
388398

389399
my $scroll = $self->es->scroll_helper(
390400
size => 250,
391401
scroll => '10m',
392-
index => $self->index->name,
402+
index => $from_index,
393403
type => $type,
394404
body => {
395405
query => $query,

0 commit comments

Comments
 (0)