Skip to content

Commit

Permalink
LocalNeonTask: Automatic selection of first DB.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek authored Feb 25, 2020
1 parent 29a62f3 commit 0ec10e9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/InteractiveComposer/Task/ConfigLocalNeonTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,24 @@ private function generateMySqlConfig(): array
$databaseList = [];
$databaseCounter = 1;
$usedDatabase = null;
$candidateDatabases = [];
echo "\n\n";

foreach ($connection->query('SHOW DATABASES')->fetchAll() as $database) {
echo $databaseCounter . ': ' . $database[0] . "\n";
$databaseList[$databaseCounter] = $database[0];
$databaseCounter++;
if ($database[0] !== 'information_schema') {
$candidateDatabases[] = $database[0];
}
}

if (\count($candidateDatabases) === 1) {
$usedDatabase = $candidateDatabases[0];
}

while (true) {
if (preg_match('/^\d+$/', $usedDatabase = $this->ask('Which database use? Type number or specific name. Type "new" for create new.') ?? '')) {
if ($usedDatabase === null && preg_match('/^\d+$/', $usedDatabase = $this->ask('Which database use? Type number or specific name. Type "new" for create new.') ?? '')) {
if (isset($databaseList[$usedDatabaseKey = (int) $usedDatabase])) {
$usedDatabase = $databaseList[$usedDatabaseKey];
break;
Expand Down

0 comments on commit 0ec10e9

Please sign in to comment.