Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Better database creation failure handling #50836

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Illuminate/Database/Console/Migrations/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Database\SQLiteDatabaseDoesNotExistException;
use Illuminate\Database\SqlServerConnection;
use PDOException;
use RuntimeException;
use Symfony\Component\Console\Attribute\AsCommand;
use Throwable;

Expand Down Expand Up @@ -187,6 +188,8 @@ protected function repositoryExists()
*
* @param string $path
* @return bool
*
* @throws \RuntimeException
*/
protected function createMissingSqliteDatabase($path)
{
Expand All @@ -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);
Expand All @@ -211,6 +216,8 @@ protected function createMissingSqliteDatabase($path)
* Create a missing MySQL database.
*
* @return bool
*
* @throws \RuntimeException
*/
protected function createMissingMysqlDatabase($connection)
{
Expand All @@ -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.');
}
}

Expand Down