in src/Utils/WordPress/Project.php [98:150]
public function initializeDatabase()
{
// Get the database region
$region = $this->input->getOption('db_region');
$availableDbRegions = $this->getAvailableDbRegions();
if (!in_array($region, $availableDbRegions)) {
$q = new ChoiceQuestion(
'Please select the region of your Cloud SQL instance '
. sprintf('(defaults to %s)', self::DEFAULT_DB_REGION),
$availableDbRegions,
array_search(self::DEFAULT_DB_REGION, $availableDbRegions)
);
$q->setErrorMessage('DB region %s is invalid.');
$region = $this->ask($q);
$this->output->writeln("Using db_region <info>$region</info>");
}
// Get the other DB parameters
$params = $this->askParameters([
'project_id' => '',
'db_instance' => '',
'db_name' => '',
'db_user' => 'root',
'db_password' => '',
]);
// Set the database connection string
$params['db_connection'] = sprintf(
'%s:%s:%s',
$params['project_id'],
$region,
$params['db_instance']
);
// Set parameters for a local database
$q = new ConfirmationQuestion(
'Do you want to use the same db user and password for local run? '
. '(Y/n)'
);
if ($this->ask($q)) {
$params += [
'local_db_user' => $params['db_user'],
'local_db_password' => $params['db_password'],
];
} else {
$params += $this->askParameters([
'local_db_user' => 'root',
'local_db_password' => '',
]);
}
return $params;
}