Skip to content

Commit b8587d0

Browse files
driesvintsjessarchertaylorotwell
authored
Prevent using unavailable databases (#334)
* Prevent using unavailable databases * wip * wip * wip * wip * wip * Add missing extension label * wip * Update src/NewCommand.php Co-authored-by: Jess Archer <[email protected]> * Update src/NewCommand.php Co-authored-by: Jess Archer <[email protected]> * Update src/NewCommand.php Co-authored-by: Jess Archer <[email protected]> * wip * Update NewCommand.php * Update NewCommand.php --------- Co-authored-by: Jess Archer <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent 54e99db commit b8587d0

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
uses: shivammathur/setup-php@v2
6666
with:
6767
php-version: ${{ matrix.php }}
68-
extensions: dom, curl, libxml, mbstring, zip, fileinfo
68+
extensions: dom, curl, libxml, mbstring, zip, fileinfo, sqlsrv, pdo, pdo_sqlsrv
6969
ini-values: error_reporting=E_ALL, memory_limit=512M
7070
tools: composer:v2
7171
coverage: none

src/NewCommand.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -448,29 +448,47 @@ protected function installJetstream(string $directory, InputInterface $input, Ou
448448
*/
449449
protected function promptForDatabaseOptions(string $directory, InputInterface $input)
450450
{
451-
$defaultDatabase = 'sqlite';
451+
$defaultDatabase = collect(
452+
$databaseOptions = $this->databaseOptions()
453+
)->keys()->first();
452454

453455
if (! $input->getOption('database') && $input->isInteractive()) {
454456
$input->setOption('database', select(
455457
label: 'Which database will your application use?',
456-
options: [
457-
'mysql' => 'MySQL',
458-
'mariadb' => 'MariaDB',
459-
'pgsql' => 'PostgreSQL',
460-
'sqlite' => 'SQLite',
461-
'sqlsrv' => 'SQL Server',
462-
],
463-
default: $defaultDatabase
458+
options: $databaseOptions,
459+
default: $defaultDatabase,
464460
));
465461

466-
if ($input->getOption('database') !== $defaultDatabase) {
467-
$migrate = confirm(label: 'Default database updated. Would you like to run the default database migrations?', default: true);
462+
if ($input->getOption('database') !== 'sqlite') {
463+
$migrate = confirm(
464+
label: 'Default database updated. Would you like to run the default database migrations?',
465+
default: true
466+
);
468467
}
469468
}
470469

471470
return [$input->getOption('database') ?? $defaultDatabase, $migrate ?? false];
472471
}
473472

473+
/**
474+
* Get the available database options.
475+
*
476+
* @return array
477+
*/
478+
protected function databaseOptions(): array
479+
{
480+
return collect([
481+
'sqlite' => ['SQLite', extension_loaded('pdo_sqlite')],
482+
'mysql' => ['MySQL', extension_loaded('pdo_mysql')],
483+
'mariadb' => ['MariaDB', extension_loaded('pdo_mysql')],
484+
'pgsql' => ['PostgreSQL', extension_loaded('pdo_pgsql')],
485+
'sqlsrv' => ['SQL Server', extension_loaded('pdo_sqlsrv')],
486+
])
487+
->sortBy(fn ($database) => $database[1] ? 0 : 1)
488+
->map(fn ($database) => $database[0].($database[1] ? '' : ' (Missing PDO extension)'))
489+
->all();
490+
}
491+
474492
/**
475493
* Determine the stack for Breeze.
476494
*

0 commit comments

Comments
 (0)