Skip to content

Commit

Permalink
Add skip-search-indexes option to schema CLI commands
Browse files Browse the repository at this point in the history
Currently, commands can either process all definitions (default behavior) or specify individual definitions. This allows the commands to rely on default behavior (e.g. $createOrder) but omit processing of search indexes, which may be more stringent requirements.

Note: this is similar to the disable-validators option that already existed in UpdateCommand; however, doctrine#2634 suggests renaming that if additional "skip" options are introduced.
  • Loading branch information
jmikola committed May 6, 2024
1 parent 13155ae commit 8589206
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected function configure()
->addOption(self::COLLECTION, null, InputOption::VALUE_NONE, 'Create collections')
->addOption(self::INDEX, null, InputOption::VALUE_NONE, 'Create indexes')
->addOption(self::SEARCH_INDEX, null, InputOption::VALUE_NONE, 'Create search indexes')
->addOption('skip-search-indexes', null, InputOption::VALUE_NONE, 'Skip processing of search indexes')
->addOption('background', null, InputOption::VALUE_NONE, sprintf('Create indexes in background (requires "%s" option)', self::INDEX))
->setDescription('Create databases, collections and indexes for your documents');
}
Expand All @@ -65,6 +66,10 @@ private function doExecute(InputInterface $input, OutputInterface $output): int
self::SEARCH_INDEX => 'SearchIndex',
};

if ($option === self::SEARCH_INDEX && $input->getOption('skip-search-indexes')) {
continue;
}

try {
if (isset($class)) {
$this->{'processDocument' . $method}($sm, $class, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input), $background);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected function configure()
->addOption(self::COLLECTION, null, InputOption::VALUE_NONE, 'Drop collections')
->addOption(self::INDEX, null, InputOption::VALUE_NONE, 'Drop indexes')
->addOption(self::SEARCH_INDEX, null, InputOption::VALUE_NONE, 'Drop search indexes')
->addOption('skip-search-indexes', null, InputOption::VALUE_NONE, 'Skip processing of search indexes')
->setDescription('Drop databases, collections and indexes for your documents');
}

Expand All @@ -65,6 +66,10 @@ private function doExecute(InputInterface $input, OutputInterface $output): int
self::SEARCH_INDEX => 'SearchIndex',
};

if ($option === self::SEARCH_INDEX && $input->getOption('skip-search-indexes')) {
continue;
}

try {
if (is_string($class)) {
$this->{'processDocument' . $method}($sm, $class, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function configure()
$this
->setName('odm:schema:update')
->addOption('class', 'c', InputOption::VALUE_OPTIONAL, 'Document class to process (default: all classes)')
->addOption('disable-search-indexes', null, InputOption::VALUE_NONE, 'Do not update search indexes')
->addOption('skip-search-indexes', null, InputOption::VALUE_NONE, 'Skip processing of search indexes')
->addOption('disable-validators', null, InputOption::VALUE_NONE, 'Do not update database-level validation rules')
->setDescription('Update indexes and validation rules for your documents');
}
Expand All @@ -36,7 +36,7 @@ private function doExecute(InputInterface $input, OutputInterface $output): int
{
$class = $input->getOption('class');
$updateValidators = ! $input->getOption('disable-validators');
$updateSearchIndexes = ! $input->getOption('disable-search-indexes');
$updateSearchIndexes = ! $input->getOption('skip-search-indexes');

$sm = $this->getSchemaManager();
$isErrored = false;
Expand Down

0 comments on commit 8589206

Please sign in to comment.