CockroachDB Databases API

Manage databases within a CockroachDB cluster, including creation, listing, updating, and deletion.

OpenAPI Specification

cockroachdb-databases-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: CockroachDB Cloud APIKeys Databases API
  description: The CockroachDB Cloud API is a REST interface that provides programmatic access to manage the lifecycle of clusters within a CockroachDB Cloud organization. It enables developers and operators to create, configure, scale, and delete CockroachDB Serverless and Dedicated clusters without using the web console. The API supports cluster provisioning, node management, network authorization, customer-managed encryption keys, backup and restore, log and metric export, role management, and folder organization. Authentication is handled via bearer tokens, and the API is rate-limited to 10 requests per second per user.
  version: '2024-09-16'
  contact:
    name: Cockroach Labs Support
    url: https://support.cockroachlabs.com
  termsOfService: https://www.cockroachlabs.com/cloud-terms-and-conditions/
servers:
- url: https://cockroachlabs.cloud
  description: CockroachDB Cloud Production Server
security:
- bearerAuth: []
tags:
- name: Databases
  description: Manage databases within a CockroachDB cluster, including creation, listing, updating, and deletion.
paths:
  /api/v1/clusters/{cluster_id}/databases:
    get:
      operationId: ListDatabases
      summary: List databases
      description: Returns a list of databases for the specified cluster. Supports pagination via page, limit, asOfTime, and sortOrder parameters.
      tags:
      - Databases
      parameters:
      - $ref: '#/components/parameters/clusterId'
      - $ref: '#/components/parameters/paginationPage'
      - $ref: '#/components/parameters/paginationLimit'
      - $ref: '#/components/parameters/paginationAsOfTime'
      - $ref: '#/components/parameters/paginationSortOrder'
      responses:
        '200':
          description: List of databases returned successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListDatabasesResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      operationId: CreateDatabase
      summary: Create a database
      description: Creates a new database within the specified cluster. Requires CLUSTER_ADMIN role at organization, folder, or cluster scope.
      tags:
      - Databases
      parameters:
      - $ref: '#/components/parameters/clusterId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateDatabaseRequest'
      responses:
        '200':
          description: Database created successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Database'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /api/v1/clusters/{cluster_id}/databases/{name}:
    patch:
      operationId: EditDatabase
      summary: Update a database
      description: Updates the configuration of an existing database within the specified cluster. Requires CLUSTER_ADMIN role.
      tags:
      - Databases
      parameters:
      - $ref: '#/components/parameters/clusterId'
      - $ref: '#/components/parameters/databaseName'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateDatabaseRequest'
      responses:
        '200':
          description: Database updated successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Database'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
    delete:
      operationId: DeleteDatabase
      summary: Delete a database
      description: Deletes a database from the specified cluster by name. Requires CLUSTER_ADMIN role at organization, folder, or cluster scope.
      tags:
      - Databases
      parameters:
      - $ref: '#/components/parameters/clusterId'
      - $ref: '#/components/parameters/databaseName'
      responses:
        '200':
          description: Database deleted successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Database'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  responses:
    BadRequest:
      description: The request body or parameters are invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Authentication credentials are missing or invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: The requested resource was not found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  parameters:
    paginationSortOrder:
      name: pagination.sort_order
      in: query
      description: Sort direction for paginated results. Accepted values are ASC and DESC.
      schema:
        type: string
        enum:
        - ASC
        - DESC
    paginationAsOfTime:
      name: pagination.as_of_time
      in: query
      description: RFC3339 timestamp to return results as they were at a specific point in time (time-travel query).
      schema:
        type: string
        format: date-time
    clusterId:
      name: cluster_id
      in: path
      required: true
      description: Unique identifier of the CockroachDB Cloud cluster.
      schema:
        type: string
    databaseName:
      name: name
      in: path
      required: true
      description: Name of the database.
      schema:
        type: string
    paginationLimit:
      name: pagination.limit
      in: query
      description: Maximum number of results to return per page.
      schema:
        type: integer
        format: int32
        minimum: 1
        maximum: 500
    paginationPage:
      name: pagination.page
      in: query
      description: Page number for paginated results, starting from 1.
      schema:
        type: string
  schemas:
    UpdateDatabaseRequest:
      type: object
      description: Request body for updating an existing database.
      properties:
        new_name:
          type: string
          description: New name for the database.
    Database:
      type: object
      description: Represents a database within a CockroachDB cluster.
      properties:
        name:
          type: string
          description: Name of the database.
        table_count:
          type: integer
          description: Number of tables in the database.
    CreateDatabaseRequest:
      type: object
      description: Request body for creating a new database.
      required:
      - name
      properties:
        name:
          type: string
          description: Name for the new database.
    ListDatabasesResponse:
      type: object
      description: Paginated list of databases in a cluster.
      properties:
        databases:
          type: array
          description: Array of database objects.
          items:
            $ref: '#/components/schemas/Database'
        pagination:
          $ref: '#/components/schemas/PaginationResponse'
    Error:
      type: object
      description: Standard error response returned by the API.
      properties:
        code:
          type: integer
          description: HTTP status code of the error.
        message:
          type: string
          description: Human-readable description of the error.
        details:
          type: array
          description: Additional detail objects providing error context.
          items:
            type: object
    PaginationResponse:
      type: object
      description: Pagination metadata included in list responses.
      properties:
        next:
          type: string
          description: Token or cursor for retrieving the next page of results.
        last:
          type: string
          description: Token or cursor for the last page of results.
        time:
          type: string
          format: date-time
          description: Server time at which the paginated query was executed.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Generate a token in the CockroachDB Cloud Console under Organization Settings > API Access.
externalDocs:
  description: CockroachDB Cloud API Documentation
  url: https://www.cockroachlabs.com/docs/cockroachcloud/cloud-api