Skip to content

Commit

Permalink
make DB_CONNECTION replacement more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 21, 2024
1 parent c1c8511 commit 2276a8d
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/Console/Concerns/InteractsWithDockerComposeServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,31 @@ protected function replaceEnvVariables(array $services)
{
$environment = file_get_contents($this->laravel->basePath('.env'));

if (in_array('pgsql', $services)) {
$environment = str_replace('DB_CONNECTION=mysql', "DB_CONNECTION=pgsql", $environment);
if (in_array('mysql', $services) ||
in_array('mariadb', $services) ||
in_array('pgsql', $services)) {
$defaults = [
'# DB_HOST=127.0.0.1',
'# DB_PORT=3306',
'# DB_DATABASE=laravel',

This comment has been minimized.

Copy link
@ivenspontes

ivenspontes Mar 12, 2024

when install with curl -s "https://laravel.build/test" | bash
this default is # DB_DATABASE=test
and don't remove the # from line

'# DB_USERNAME=root',
'# DB_PASSWORD=',
];

foreach ($defaults as $default) {
$environment = str_replace($default, substr($default, 2), $environment);
}
}

if (in_array('mysql', $services)) {
$environment = preg_replace('/DB_CONNECTION=.*/', 'DB_CONNECTION=mysql', $environment);
$environment = str_replace('DB_HOST=127.0.0.1', "DB_HOST=mysql", $environment);
}elseif (in_array('pgsql', $services)) {
$environment = preg_replace('/DB_CONNECTION=.*/', 'DB_CONNECTION=pgsql', $environment);
$environment = str_replace('DB_HOST=127.0.0.1', "DB_HOST=pgsql", $environment);
$environment = str_replace('DB_PORT=3306', "DB_PORT=5432", $environment);
} elseif (in_array('mariadb', $services)) {
$environment = str_replace('DB_HOST=127.0.0.1', "DB_HOST=mariadb", $environment);
} else {
$environment = str_replace('DB_HOST=127.0.0.1', "DB_HOST=mysql", $environment);
}

$environment = str_replace('DB_USERNAME=root', "DB_USERNAME=sail", $environment);
Expand Down

0 comments on commit 2276a8d

Please sign in to comment.