[ [ 'code' => 'DisplayException', 'status' => '400', 'detail' => 'Cannot create additional databases on this server: limit has been reached.', ], ], ]; /** * Return all the databases that belong to the given server. */ #[Endpoint('List server databases', 'Returns databases attached to a server visible to the authenticated user.')] #[QueryParam('include', 'string', 'Comma-separated relationships to include. Supports "password" when the user can view database passwords.', required: false, example: 'password', enum: ['password'])] #[ResponseFromResource(DatabaseResource::class, Database::class, description: 'Server databases returned.', collection: true, resourceKey: 'server_database')] public function index(GetDatabasesRequest $request, Server $server): ApiResourceCollection { return DatabaseResource::collection($server->databases); } /** * Create a new database for the given server and return it. * * @throws Throwable * @throws TooManyDatabasesException * @throws DatabaseClientFeatureNotEnabledException */ #[Endpoint('Create server database', 'Creates a database for a server on an automatically selected database host.')] #[QueryParam('include', 'string', 'Comma-separated relationships to include. Supports "password" when the user can view database passwords.', required: false, example: 'password', enum: ['password'])] #[ResponseFromResource(DatabaseResource::class, Database::class, description: 'Database created.', resourceKey: 'server_database', include: ['password'])] #[ScribeResponse(self::DATABASE_LIMIT_ERROR, status: 400, description: 'The server has reached its configured database limit or client database creation is disabled.')] public function store(StoreDatabaseRequest $request, DeploysServerDatabases $deployDatabase, Server $server): DatabaseResource { $database = $deployDatabase->deploy($server, $request->actionInput()); return DatabaseResource::make($database)->withIncludes('password'); } /** * Rotates the password for the given server model and returns a fresh instance to * the caller. * * @throws Throwable */ #[Endpoint('Rotate server database password', 'Rotates the password for a database attached to a server and returns the updated database.')] #[QueryParam('include', 'string', 'Comma-separated relationships to include. Supports "password" when the user can view database passwords.', required: false, example: 'password', enum: ['password'])] #[ResponseFromResource(DatabaseResource::class, Database::class, description: 'Database password rotated.', resourceKey: 'server_database', include: ['password'])] public function rotatePassword(RotatePasswordRequest $request, RotatesDatabasePasswords $passwordService, Server $server, Database $database): DatabaseResource { $passwordService->rotate($database); return DatabaseResource::make($database->refresh())->withIncludes('password'); } /** * Removes a database from the server. */ #[Endpoint('Delete server database', 'Deletes a database attached to a server.')] #[ScribeResponse(status: 204, description: 'Database deleted.')] public function delete(DeleteDatabaseRequest $request, DeletesDatabases $deleteDatabase, Server $server, Database $database): Response { $deleteDatabase->delete($database); return new Response('', Response::HTTP_NO_CONTENT); } }