# Databases API reference

Source: `@socra/db-api@0.0.2` (DBContract).

Provision and operate project-scoped managed databases.

## API surface

Base URL: `https://db.socra.cloud`

## Databases

An isolated, project-scoped managed PostgreSQL database.

### Resource schema

- `id` custom, required
- `project_id` custom, required
- `name` string, required
- `status` "provisioning" | "ready" | "failed", required
- `storage_size_gib` integer (greater than: 0; max: 9007199254740991), required
- `host` string | null, required
- `port` integer (greater than: 0; max: 9007199254740991), required
- `database` string, required
- `username` string, required
- `error` string | null, required
- `created_at` custom, required
- `updated_at` custom, required

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {},
    "project_id": {},
    "name": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": [
        "provisioning",
        "ready",
        "failed"
      ]
    },
    "storage_size_gib": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "host": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "port": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "database": {
      "type": "string"
    },
    "username": {
      "type": "string"
    },
    "error": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "created_at": {},
    "updated_at": {}
  },
  "required": [
    "id",
    "project_id",
    "name",
    "status",
    "storage_size_gib",
    "host",
    "port",
    "database",
    "username",
    "error",
    "created_at",
    "updated_at"
  ],
  "additionalProperties": false
}
```

### Create database

`POST /v1/projects/{project_id}/databases`

Required scopes: `db.socra.cloud/databases.manage`

#### Path parameters

- `project_id` custom, required

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```


#### Request body

- `name` string (min length: 1; max length: 63; pattern: ^[a-z][a-z0-9-]*$), required
- `storage_size_gib` integer (default: 10; min: 1; max: 1024), optional

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 63,
      "pattern": "^[a-z][a-z0-9-]*$"
    },
    "storage_size_gib": {
      "default": 10,
      "type": "integer",
      "minimum": 1,
      "maximum": 1024
    }
  },
  "required": [
    "name"
  ]
}
```

#### Response

- `id` custom, required
- `project_id` custom, required
- `name` string, required
- `status` "provisioning" | "ready" | "failed", required
- `storage_size_gib` integer (greater than: 0; max: 9007199254740991), required
- `host` string | null, required
- `port` integer (greater than: 0; max: 9007199254740991), required
- `database` string, required
- `username` string, required
- `error` string | null, required
- `created_at` custom, required
- `updated_at` custom, required

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {},
    "project_id": {},
    "name": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": [
        "provisioning",
        "ready",
        "failed"
      ]
    },
    "storage_size_gib": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "host": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "port": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "database": {
      "type": "string"
    },
    "username": {
      "type": "string"
    },
    "error": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "created_at": {},
    "updated_at": {}
  },
  "required": [
    "id",
    "project_id",
    "name",
    "status",
    "storage_size_gib",
    "host",
    "port",
    "database",
    "username",
    "error",
    "created_at",
    "updated_at"
  ],
  "additionalProperties": false
}
```

### List databases

`GET /v1/projects/{project_id}/databases`

Required scopes: `db.socra.cloud/databases.read`

#### Path parameters

- `project_id` custom, required

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```


#### Query parameters

- `limit` integer (min: 1; max: 100), optional
- `after` string, optional

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "limit": {
      "type": "integer",
      "minimum": 1,
      "maximum": 100
    },
    "after": {
      "type": "string"
    }
  }
}
```

#### Response

- `data` object[], required
  - `id` custom, required
  - `project_id` custom, required
  - `name` string, required
  - `status` "provisioning" | "ready" | "failed", required
  - `storage_size_gib` integer (greater than: 0; max: 9007199254740991), required
  - `host` string | null, required
  - `port` integer (greater than: 0; max: 9007199254740991), required
  - `database` string, required
  - `username` string, required
  - `error` string | null, required
  - `created_at` custom, required
  - `updated_at` custom, required
- `has_more` boolean, required

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "data": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {},
          "project_id": {},
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "provisioning",
              "ready",
              "failed"
            ]
          },
          "storage_size_gib": {
            "type": "integer",
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991
          },
          "host": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "port": {
            "type": "integer",
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991
          },
          "database": {
            "type": "string"
          },
          "username": {
            "type": "string"
          },
          "error": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "created_at": {},
          "updated_at": {}
        },
        "required": [
          "id",
          "project_id",
          "name",
          "status",
          "storage_size_gib",
          "host",
          "port",
          "database",
          "username",
          "error",
          "created_at",
          "updated_at"
        ],
        "additionalProperties": false
      }
    },
    "has_more": {
      "type": "boolean"
    }
  },
  "required": [
    "data",
    "has_more"
  ],
  "additionalProperties": false
}
```

### Get database

`GET /v1/projects/{project_id}/databases/{database_id}`

Required scopes: `db.socra.cloud/databases.read`

#### Path parameters

- `project_id` custom, required

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```

- `database_id` custom, required

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```


#### Response

- `id` custom, required
- `project_id` custom, required
- `name` string, required
- `status` "provisioning" | "ready" | "failed", required
- `storage_size_gib` integer (greater than: 0; max: 9007199254740991), required
- `host` string | null, required
- `port` integer (greater than: 0; max: 9007199254740991), required
- `database` string, required
- `username` string, required
- `error` string | null, required
- `created_at` custom, required
- `updated_at` custom, required

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {},
    "project_id": {},
    "name": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": [
        "provisioning",
        "ready",
        "failed"
      ]
    },
    "storage_size_gib": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "host": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "port": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "database": {
      "type": "string"
    },
    "username": {
      "type": "string"
    },
    "error": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "created_at": {},
    "updated_at": {}
  },
  "required": [
    "id",
    "project_id",
    "name",
    "status",
    "storage_size_gib",
    "host",
    "port",
    "database",
    "username",
    "error",
    "created_at",
    "updated_at"
  ],
  "additionalProperties": false
}
```

### Update database

`PATCH /v1/projects/{project_id}/databases/{database_id}`

Required scopes: `db.socra.cloud/databases.manage`

#### Path parameters

- `project_id` custom, required

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```

- `database_id` custom, required

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```


#### Request body

- `name` string (min length: 1; max length: 63; pattern: ^[a-z][a-z0-9-]*$), required

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 63,
      "pattern": "^[a-z][a-z0-9-]*$"
    }
  },
  "required": [
    "name"
  ]
}
```

#### Response

- `id` custom, required
- `project_id` custom, required
- `name` string, required
- `status` "provisioning" | "ready" | "failed", required
- `storage_size_gib` integer (greater than: 0; max: 9007199254740991), required
- `host` string | null, required
- `port` integer (greater than: 0; max: 9007199254740991), required
- `database` string, required
- `username` string, required
- `error` string | null, required
- `created_at` custom, required
- `updated_at` custom, required

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {},
    "project_id": {},
    "name": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": [
        "provisioning",
        "ready",
        "failed"
      ]
    },
    "storage_size_gib": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "host": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "port": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "database": {
      "type": "string"
    },
    "username": {
      "type": "string"
    },
    "error": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "created_at": {},
    "updated_at": {}
  },
  "required": [
    "id",
    "project_id",
    "name",
    "status",
    "storage_size_gib",
    "host",
    "port",
    "database",
    "username",
    "error",
    "created_at",
    "updated_at"
  ],
  "additionalProperties": false
}
```

### Delete database

`DELETE /v1/projects/{project_id}/databases/{database_id}`

Required scopes: `db.socra.cloud/databases.manage`

#### Path parameters

- `project_id` custom, required

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```

- `database_id` custom, required

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```


#### Response

No response body.

## Database connections

A write-only database connection stored as an immutable Socra Secret version.

### Resource schema

- `database_id` custom, required
- `secret_id` custom, required
- `secret_version_id` custom, required
- `environment_variable` "DATABASE_URL", required

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "database_id": {},
    "secret_id": {},
    "secret_version_id": {},
    "environment_variable": {
      "type": "string",
      "const": "DATABASE_URL"
    }
  },
  "required": [
    "database_id",
    "secret_id",
    "secret_version_id",
    "environment_variable"
  ],
  "additionalProperties": false
}
```

### Create database connection

`POST /v1/projects/{project_id}/databases/{database_id}/connection`

Store DATABASE_URL in Socra Secret and return only its metadata reference.

Required scopes: `db.socra.cloud/databases.manage`

#### Path parameters

- `project_id` custom, required

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```

- `database_id` custom, required

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```


#### Request body

- `secret_name` string (min length: 1; max length: 63; pattern: ^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$), optional

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "secret_name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 63,
      "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
    }
  }
}
```

#### Response

- `database_id` custom, required
- `secret_id` custom, required
- `secret_version_id` custom, required
- `environment_variable` "DATABASE_URL", required

JSON Schema:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "database_id": {},
    "secret_id": {},
    "secret_version_id": {},
    "environment_variable": {
      "type": "string",
      "const": "DATABASE_URL"
    }
  },
  "required": [
    "database_id",
    "secret_id",
    "secret_version_id",
    "environment_variable"
  ],
  "additionalProperties": false
}
```

---

Company: Socra — Multiply Your Judgment
Canonical URL: https://cloud.socra.com/docs/db/reference/api
