From 2c86247a053019f78cb881342cffb965be15e49e Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 29 Mar 2024 11:27:41 +0100 Subject: [PATCH 1/3] Better database creation failure handling --- .../Database/Console/Migrations/MigrateCommand.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Console/Migrations/MigrateCommand.php b/src/Illuminate/Database/Console/Migrations/MigrateCommand.php index 2b07dc94a540..1af988e2213b 100755 --- a/src/Illuminate/Database/Console/Migrations/MigrateCommand.php +++ b/src/Illuminate/Database/Console/Migrations/MigrateCommand.php @@ -10,6 +10,7 @@ use Illuminate\Database\SQLiteDatabaseDoesNotExistException; use Illuminate\Database\SqlServerConnection; use PDOException; +use RuntimeException; use Symfony\Component\Console\Attribute\AsCommand; use Throwable; @@ -187,6 +188,8 @@ protected function repositoryExists() * * @param string $path * @return bool + * + * @throws \RuntimeException */ protected function createMissingSqliteDatabase($path) { @@ -201,7 +204,9 @@ protected function createMissingSqliteDatabase($path) $this->components->warn('The SQLite database configured for this application does not exist: '.$path); if (! confirm('Would you like to create it?', default: true)) { - return false; + $this->components->info('Operation cancelled! No database was created.'); + + throw new RuntimeException('Database was not created. Aborting migration.'); } return touch($path); @@ -211,6 +216,8 @@ protected function createMissingSqliteDatabase($path) * Create a missing MySQL database. * * @return bool + * + * @throws \RuntimeException */ protected function createMissingMysqlDatabase($connection) { @@ -226,7 +233,9 @@ protected function createMissingMysqlDatabase($connection) $this->components->warn("The database '{$connection->getDatabaseName()}' does not exist on the '{$connection->getName()}' connection."); if (! confirm('Would you like to create it?', default: true)) { - return false; + $this->components->info('Operation cancelled! No database was created.'); + + throw new RuntimeException('Database was not created. Aborting migration.'); } } From 5e25916c555b99912fbc3fc4e61e6d971aa65a0b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 29 Mar 2024 09:38:29 -0500 Subject: [PATCH 2/3] Update MigrateCommand.php --- src/Illuminate/Database/Console/Migrations/MigrateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Console/Migrations/MigrateCommand.php b/src/Illuminate/Database/Console/Migrations/MigrateCommand.php index 1af988e2213b..946f0d8bc481 100755 --- a/src/Illuminate/Database/Console/Migrations/MigrateCommand.php +++ b/src/Illuminate/Database/Console/Migrations/MigrateCommand.php @@ -204,7 +204,7 @@ protected function createMissingSqliteDatabase($path) $this->components->warn('The SQLite database configured for this application does not exist: '.$path); if (! confirm('Would you like to create it?', default: true)) { - $this->components->info('Operation cancelled! No database was created.'); + $this->components->info('Operation cancelled. No database was created.'); throw new RuntimeException('Database was not created. Aborting migration.'); } From 817d8b8460907332744fd298fd2a31d79a55fbea Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 29 Mar 2024 09:38:52 -0500 Subject: [PATCH 3/3] Update MigrateCommand.php --- src/Illuminate/Database/Console/Migrations/MigrateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Console/Migrations/MigrateCommand.php b/src/Illuminate/Database/Console/Migrations/MigrateCommand.php index 946f0d8bc481..2db166a88937 100755 --- a/src/Illuminate/Database/Console/Migrations/MigrateCommand.php +++ b/src/Illuminate/Database/Console/Migrations/MigrateCommand.php @@ -233,7 +233,7 @@ protected function createMissingMysqlDatabase($connection) $this->components->warn("The database '{$connection->getDatabaseName()}' does not exist on the '{$connection->getName()}' connection."); if (! confirm('Would you like to create it?', default: true)) { - $this->components->info('Operation cancelled! No database was created.'); + $this->components->info('Operation cancelled. No database was created.'); throw new RuntimeException('Database was not created. Aborting migration.'); }