Skip to content

Commit c4a3b5f

Browse files
Kwadzenzolutions
authored andcommitted
Add --default option to database:add (#4143)
This option allows to set the database as the default one instead of adding a new database in addition to the default one. See: #4142
1 parent 3c83f02 commit c4a3b5f

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/Command/Database/AddCommand.php

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ protected function configure()
8383
InputOption::VALUE_OPTIONAL,
8484
$this->trans('commands.database.add.options.driver')
8585
)
86+
->addOption(
87+
'default',
88+
null,
89+
InputOption::VALUE_NONE,
90+
$this->trans('commands.database.query.options.default')
91+
)
8692
->setHelp($this->trans('commands.database.add.help'))
8793
->setAliases(['dba']);
8894
}

src/Generator/DatabaseSettingsGenerator.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ public function generate(array $parameters)
2626
if (!is_writable($settingsFile)) {
2727
return false;
2828
}
29+
$template = 'database/add.php.twig';
30+
if ($parameters['default']) {
31+
$template = 'database/add-default.php.twig';
32+
}
2933
return $this->renderFile(
30-
'database/add.php.twig',
34+
$template,
3135
$settingsFile,
3236
$parameters,
3337
FILE_APPEND
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
$databases['default']['default'] = [
3+
'database' => '{{ database }}',
4+
'username' => '{{ username }}',
5+
'password' => '{{ password }}',
6+
'host' => '{{ host }}',
7+
'port' => '{{ port }}',
8+
'driver' => '{{ driver }}',
9+
'prefix' => '{{ prefix }}',
10+
];

0 commit comments

Comments
 (0)