# Change a database's properties

`POST /v1/databases/{databaseId}/schema`

Adds, changes and removes properties in one step. update can rename (name), change the type (values are converted), the frontmatter key or the config (options, relation, number format, formula expression). Removed properties keep their values in the rows.

Scope: `docs:write`. Undoable.

## Request

```bash
curl -X POST "https://api.lydie.co/v1/databases/01JCQ3V5MZ8G4ZK2X7T9R6N1PB/schema" \
  -H "Authorization: Bearer $LYDIE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'
```

## Path parameters

- `databaseId` (ULID, required)

## Body

- `add` (object[], optional): Default: `[]`.
  - `name` (string, required): (1–200 chars)
  - `type` (string, required): One of: `title`, `text`, `number`, `select`, `multiSelect`, `status`, `date`, `checkbox`, `url`, `email`, `phone`, `person`, `files`, `relation`, `rollup`, `formula`, `uniqueId`, `createdTime`, `updatedTime`, `createdBy`, `updatedBy`.
  - `key` (string, optional): (1–128 chars)
  - `config` (PropertyConfigSpecInput, optional)
    - `options` (object[], optional): select, multiSelect, status
      - `id` (ULID, optional)
      - `name` (string, required): (1–200 chars)
      - `color` (string, optional): One of: `default`, `gray`, `brown`, `orange`, `yellow`, `green`, `blue`, `purple`, `pink`, `red`. Default: `"default"`.
      - `group` (string, optional): One of: `todo`, `inProgress`, `complete`.
    - `numberFormat` (string, optional): One of: `number`, `integer`, `commas`, `percent`, `currency`.
    - `decimals` (integer, optional): (0–10)
    - `currency` (string, optional): ISO 4217 code, with numberFormat currency (3–3 chars)
    - `includeTime` (boolean, optional): date: values carry a time
    - `range` (boolean, optional): date: values may carry an end (start/end)
    - `relation` (RelationConfigInput, optional)
      - `databaseId` (ULID, required): The database whose rows this relation points at.
      - `twoWay` (boolean, optional): Default: `false`.
      - `reversePropertyId` (ULID, optional, nullable): The synced property on the other database (two-way relations). Default: `null`.
      - `limit` (string, optional): One of: `one`, `many`. Default: `"many"`.
    - `rollup` (RollupConfigInput, optional)
      - `relationPropertyId` (ULID, required)
      - `targetPropertyId` (ULID, required): A property of the related database.
      - `function` (string, required): One of: `showOriginal`, `showUnique`, `count`, `countValues`, `countUnique`, `countEmpty`, `countNotEmpty`, `percentEmpty`, `percentNotEmpty`, `sum`, `average`, `median`, `min`, `max`, `range`, `earliest`, `latest`, `checked`, `unchecked`, `percentChecked`, `percentUnchecked`.
    - `expression` (string, optional): formula: an Obsidian Bases expression
    - `prefix` (string, optional): uniqueId: shown before the number ("LYD" → LYD-12) (≤ 16 chars)
    - `extra` (object, optional)
- `update` (object[], optional): Default: `[]`.
  - `property` (string, required): A property's id, frontmatter key or name (case-insensitive). (≥ 1 chars)
  - `name` (string, optional): (1–200 chars)
  - `type` (string, optional): One of: `title`, `text`, `number`, `select`, `multiSelect`, `status`, `date`, `checkbox`, `url`, `email`, `phone`, `person`, `files`, `relation`, `rollup`, `formula`, `uniqueId`, `createdTime`, `updatedTime`, `createdBy`, `updatedBy`.
  - `key` (string, optional): (1–128 chars)
  - `config` (PropertyConfigSpecInput, optional)
    - `options` (object[], optional): select, multiSelect, status
      - `id` (ULID, optional)
      - `name` (string, required): (1–200 chars)
      - `color` (string, optional): One of: `default`, `gray`, `brown`, `orange`, `yellow`, `green`, `blue`, `purple`, `pink`, `red`. Default: `"default"`.
      - `group` (string, optional): One of: `todo`, `inProgress`, `complete`.
    - `numberFormat` (string, optional): One of: `number`, `integer`, `commas`, `percent`, `currency`.
    - `decimals` (integer, optional): (0–10)
    - `currency` (string, optional): ISO 4217 code, with numberFormat currency (3–3 chars)
    - `includeTime` (boolean, optional): date: values carry a time
    - `range` (boolean, optional): date: values may carry an end (start/end)
    - `relation` (RelationConfigInput, optional)
      - `databaseId` (ULID, required): The database whose rows this relation points at.
      - `twoWay` (boolean, optional): Default: `false`.
      - `reversePropertyId` (ULID, optional, nullable): The synced property on the other database (two-way relations). Default: `null`.
      - `limit` (string, optional): One of: `one`, `many`. Default: `"many"`.
    - `rollup` (RollupConfigInput, optional)
      - `relationPropertyId` (ULID, required)
      - `targetPropertyId` (ULID, required): A property of the related database.
      - `function` (string, required): One of: `showOriginal`, `showUnique`, `count`, `countValues`, `countUnique`, `countEmpty`, `countNotEmpty`, `percentEmpty`, `percentNotEmpty`, `sum`, `average`, `median`, `min`, `max`, `range`, `earliest`, `latest`, `checked`, `unchecked`, `percentChecked`, `percentUnchecked`.
    - `expression` (string, optional): formula: an Obsidian Bases expression
    - `prefix` (string, optional): uniqueId: shown before the number ("LYD" → LYD-12) (≤ 16 chars)
    - `extra` (object, optional)
- `remove` (string[], optional): Default: `[]`.

## Response

- `id` (ULID, required)
- `properties` (object[], required)
  - `id` (ULID, required)
  - `name` (string, required)
  - `type` (string, required): One of: `title`, `text`, `number`, `select`, `multiSelect`, `status`, `date`, `checkbox`, `url`, `email`, `phone`, `person`, `files`, `relation`, `rollup`, `formula`, `uniqueId`, `createdTime`, `updatedTime`, `createdBy`, `updatedBy`.
  - `key` (string, required)
- `views` (object[], required)
  - `id` (ULID, required)
  - `name` (string, required)
  - `type` (string, required): One of: `table`, `board`, `list`, `calendar`, `gallery`.

```json
{
  "id": "01JCQ3V5MZ8G4ZK2X7T9R6N1PB",
  "properties": [
    {
      "id": "01JCQ3V5MZ8G4ZK2X7T9R6N1PB",
      "name": "Notes",
      "type": "title",
      "key": "string"
    }
  ],
  "views": [
    {
      "id": "01JCQ3V5MZ8G4ZK2X7T9R6N1PB",
      "name": "Notes",
      "type": "table"
    }
  ]
}
```

Errors use the envelope described at https://developers.lydie.co/errors.md.
