Skip to content

Commit 4a642a7

Browse files
fix: add diagnostic context to Mittwald createMysqlDatabase error handling
1 parent 91bdb3c commit 4a642a7

1 file changed

Lines changed: 36 additions & 20 deletions

File tree

src/Database/Manager/MittwaldApi.php

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,46 @@ class MittwaldApi extends AbstractManager implements ManagerInterface
4949
*/
5050
public function create(): void
5151
{
52-
debug('Creating database');
53-
$response = $this->initClient()
54-
->database()
55-
->createMysqlDatabase(
56-
new CreateMysqlDatabaseRequest(
57-
projectId: get('mittwald_project_id'),
58-
body: new CreateMysqlDatabaseRequestBody(
59-
database: (new CreateMySqlDatabase(
60-
$this->getFeatureName(),
61-
get('mittwald_project_id'),
62-
get('mittwald_database_version', '8.4')
63-
))->withCharacterSettings(
64-
new CharacterSettings(
65-
characterSet: get('mittwald_database_character_set', 'utf8mb4'),
66-
collation: get('mittwald_database_collation', 'utf8mb4_unicode_ci')
52+
$projectId = get('mittwald_project_id');
53+
$featureName = $this->getFeatureName();
54+
$databaseVersion = get('mittwald_database_version', '8.4');
55+
$characterSet = get('mittwald_database_character_set', 'utf8mb4');
56+
$collation = get('mittwald_database_collation', 'utf8mb4_unicode_ci');
57+
58+
debug("Creating database '{$featureName}' for project '{$projectId}' (MySQL {$databaseVersion}, {$characterSet}/{$collation})");
59+
60+
try {
61+
$response = $this->initClient()
62+
->database()
63+
->createMysqlDatabase(
64+
new CreateMysqlDatabaseRequest(
65+
projectId: $projectId,
66+
body: new CreateMysqlDatabaseRequestBody(
67+
database: (new CreateMySqlDatabase(
68+
$featureName,
69+
$projectId,
70+
$databaseVersion,
71+
))->withCharacterSettings(
72+
new CharacterSettings(
73+
characterSet: $characterSet,
74+
collation: $collation,
75+
)
76+
),
77+
user: new CreateMySqlUserWithDatabase(
78+
CreateMySqlUserWithDatabaseAccessLevel::full,
79+
VarUtility::getDatabasePassword()
6780
)
68-
),
69-
user: new CreateMySqlUserWithDatabase(
70-
CreateMySqlUserWithDatabaseAccessLevel::full,
71-
VarUtility::getDatabasePassword()
7281
)
7382
)
74-
)
83+
);
84+
} catch (UnexpectedResponseException $e) {
85+
throw new \RuntimeException(
86+
"Failed to create database '{$featureName}' for project '{$projectId}' "
87+
. "(MySQL {$databaseVersion}, {$characterSet}/{$collation}): {$e->getMessage()}",
88+
0,
89+
$e,
7590
);
91+
}
7692

7793
$responseBody = $response->getBody();
7894

0 commit comments

Comments
 (0)