Skip to content

Commit 5f0c92e

Browse files
committed
fix: init command should always add staging and production databases
1 parent 778b5e4 commit 5f0c92e

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

src/Command/Project/InitializeProjectCommand.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -158,37 +158,33 @@ protected function perform(InputInterface $input, OutputInterface $output)
158158
*/
159159
private function addEnvironmentDatabaseNodes(Collection $environments, OutputInterface $output, string $projectName, string $region): Collection
160160
{
161-
$databasePrefix = '';
162161
$databaseServer = $this->determineDatabaseServer($output, $region);
163162

164163
if (empty($databaseServer['name'])) {
165164
return $environments;
166-
} elseif (!empty($databaseServer['publicly_accessible']) && $output->confirm(sprintf('Would you like to create staging and production databases for your project on the "<comment>%s</comment>" database server?', $databaseServer['name']))) {
167-
$databasePrefix = $output->askSlug('What database prefix would you like to use for this project?', $projectName);
168165
}
169166

170-
return $environments->map(function (array $options, string $environment) use ($databasePrefix, $databaseServer) {
171-
if (empty($databasePrefix)) {
172-
Arr::set($options, 'database', $databaseServer['name']);
173-
} else {
174-
Arr::set($options, 'database.server', $databaseServer['name']);
175-
Arr::set($options, 'database.name', sprintf('%s_%s', rtrim($databasePrefix, '_'), $environment));
176-
}
167+
$databasePrefix = trim($output->askSlug('What database prefix would you like to use for this project?', $projectName));
168+
$environments->map(function (array $options, string $environment) use ($databasePrefix, $databaseServer) {
169+
Arr::set($options, 'database.server', $databaseServer['name']);
170+
Arr::set($options, 'database.name', $databasePrefix ? sprintf('%s_%s', rtrim($databasePrefix, '_'), $environment) : $environment);
177171

178172
return $options;
179-
})->each(function (array $options) {
180-
if (!Arr::has($options, ['database.server', 'database.name'])) {
181-
return;
182-
}
173+
});
183174

184-
$this->invoke(new NullOutput(), CreateDatabaseCommand::NAME, ['name' => Arr::get($options, 'database.name'), '--server' => Arr::get($options, 'database.server')]);
185-
})->map(function (array $options) {
186-
if (empty($options)) {
187-
$options = null;
188-
}
175+
if (!empty($databaseServer['publicly_accessible']) && $output->confirm(sprintf('Would you like to create the staging and production databases for your project on the "<comment>%s</comment>" database server?', $databaseServer['name']))) {
176+
$environments->each(function (array $options) {
177+
$this->invoke(new NullOutput(), CreateDatabaseCommand::NAME, ['name' => Arr::get($options, 'database.name'), '--server' => Arr::get($options, 'database.server')]);
178+
});
179+
}
189180

190-
return $options;
191-
});
181+
if (empty($databaseServer['publicly_accessible']) || !$output->confirm(sprintf('Would you like to create staging and production databases for your project on the "<comment>%s</comment>" database server?', $databaseServer['name']))) {
182+
return $environments->map(function (array $options) use ($databaseServer) {
183+
Arr::set($options, 'database', $databaseServer['name']);
184+
});
185+
}
186+
187+
return $environments;
192188
}
193189

194190
/**

0 commit comments

Comments
 (0)