Skip to content

Commit c3887a4

Browse files
author
Gaetano Giunta
committed
allow to work on only some dbs at a time
1 parent 06cd8a9 commit c3887a4

File tree

8 files changed

+20
-13
lines changed

8 files changed

+20
-13
lines changed

app/src/Command/DatabaseCreate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3939
$this->setOutput($output);
4040
$this->setVerbosity($output->getVerbosity());
4141

42-
$dbList = $this->dbManager->listInstances();
42+
$dbList = $this->dbManager->listInstances($input->getOption('only-instances'), $input->getOption('except-instances'));
4343
$userName = $input->getOption('user');
4444
$password = $input->getOption('password');
4545
$dbName = $input->getOption('database');

app/src/Command/DatabaseDrop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3838
$this->setOutput($output);
3939
$this->setVerbosity($output->getVerbosity());
4040

41-
$dbList = $this->dbManager->listInstances();
41+
$dbList = $this->dbManager->listInstances($input->getOption('only-instances'), $input->getOption('except-instances'));
4242
$userName = $input->getOption('user');
4343
$dbName = $input->getOption('database');
4444

app/src/Command/DatabaseList.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3636
$this->setOutput($output);
3737
$this->setVerbosity($output->getVerbosity());
3838

39-
$dbList = $this->dbManager->listInstances();
39+
$dbList = $this->dbManager->listInstances($input->getOption('only-instances'), $input->getOption('except-instances'));
4040

4141
$timeout = $input->getOption('timeout');
4242
$maxParallel = $input->getOption('max-parallel');
@@ -54,22 +54,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
5454
$this->writeln('<info>Analyzing databases...</info>', OutputInterface::VERBOSITY_VERBOSE);
5555
}
5656

57-
$results = $this->listInstances($dbList, $maxParallel, $timeout, $format);
57+
$results = $this->listDatabases($dbList, $maxParallel, $timeout, $format);
5858

5959
$time = microtime(true) - $start;
6060

6161
$this->writeResults($results, $time, $format);
6262
}
6363

64-
protected function listInstances($dbList, $maxParallel, $timeout, $format = self::DEFAULT_OUTPUT_FORMAT)
64+
protected function listDatabases($dbList, $maxParallel, $timeout, $format = self::DEFAULT_OUTPUT_FORMAT)
6565
{
6666
$processes = [];
6767

6868
foreach ($dbList as $dbName) {
6969
$rootDbConnectionSpec = $this->dbManager->getDatabaseConnectionSpecification($dbName);
7070

7171
$schemaManager = new DatabaseSchemaManager($rootDbConnectionSpec);
72-
$sql = $schemaManager->getListInstancesSQL();
72+
$sql = $schemaManager->getListDatabasesSQL();
7373

7474
$executor = $this->executorFactory->createForkedExecutor($rootDbConnectionSpec, 'NativeClient', false);
7575
$process = $executor->getExecuteCommandProcess($sql);

app/src/Command/DatabaseManagingCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ protected function addCommonOptions()
4141
->addOption('timeout', null, InputOption::VALUE_REQUIRED, 'The maximum time to wait for execution (secs)', self::DEFAULT_PROCESS_TIMEOUT)
4242
->addOption('max-parallel', null, InputOption::VALUE_REQUIRED, 'The maximum number of processes to run in parallel', self::DEFAULT_PARALLEL_PROCESSES)
4343
->addOption('dont-force-enabled-sigchild', null, InputOption::VALUE_NONE, "When using a separate php process to run each sql command, do not force Symfony to believe that php was compiled with --enable-sigchild option")
44-
->addOption('instances', null, InputOption::VALUE_REQUIRED, 'Filter the database servers to run this command against. Usage of * and ? wildcards is allowed. To see all instances available, use `db3v4l:instance:list`', null)
44+
->addOption('only-instances', null, InputOption::VALUE_REQUIRED, 'Filter the database servers to run this command against. Usage of * and ? wildcards is allowed. To see all instances available, use `db3v4l:instance:list`', null)
45+
->addOption('except-instances', null, InputOption::VALUE_REQUIRED, 'Filter the database servers to run this command against.', null)
4546
;
4647
}
4748

@@ -215,5 +216,4 @@ protected function writeResults(array $results, $time, $format = 'text')
215216
$this->writeln("<info>Time taken: ".sprintf('%.2f', $time)." secs</info>");
216217
}
217218
}
218-
219219
}

app/src/Command/SqlExecute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3939
$this->setOutput($output);
4040
$this->setVerbosity($output->getVerbosity());
4141

42-
$dbList = $this->dbManager->listInstances();
42+
$dbList = $this->dbManager->listInstances($input->getOption('only-instances'), $input->getOption('except-instances'));
4343
$sql = $input->getOption('sql');
4444
$file = $input->getOption('file');
4545
$timeout = $input->getOption('timeout');

app/src/Command/UserList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3636
$this->setOutput($output);
3737
$this->setVerbosity($output->getVerbosity());
3838

39-
$dbList = $this->dbManager->listInstances();
39+
$dbList = $this->dbManager->listInstances($input->getOption('only-instances'), $input->getOption('except-instances'));
4040

4141
$timeout = $input->getOption('timeout');
4242
$maxParallel = $input->getOption('max-parallel');

app/src/Core/DatabaseSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function getDropDatabaseQL($userName, $dbName = null)
9494
/**
9595
* @return string
9696
*/
97-
public function getListInstancesSQL()
97+
public function getListDatabasesSQL()
9898
{
9999
$dbType = $this->getDbTypeFromDriver($this->databaseConfiguration['driver']);
100100

app/src/Service/DatabaseConfigurationManager.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ public function __construct(array $instanceList)
1212
}
1313

1414
/**
15+
* @param string $includeFilter accepts 'glob' wildcards
16+
* @param string $excludeFilter accepts 'glob' wildcards
1517
* @return string[]
1618
*/
17-
public function listInstances()
19+
public function listInstances($includeFilter = null, $excludeFilter = null)
1820
{
19-
return array_keys($this->instanceList);
21+
$names = [];
22+
foreach(array_keys($this->instanceList) as $name) {
23+
if (($includeFilter == '' || fnmatch($includeFilter, $name)) && ($excludeFilter == '' || !fnmatch($includeFilter, $name)))
24+
$names[] = $name;
25+
}
26+
return $names;
2027
}
2128

2229
/**

0 commit comments

Comments
 (0)