# Turn existing notes (not rows of any table yet) into rows of `table`, keeping their body and

`POST /datanotes/operations/adopt_rows/` (operation `adopt_rows`)

Turn existing notes (not rows of any table yet) into rows of `table`, keeping their body and
links: `rename` keys (`{"data": "occurred_at"}`), `set` for all, `per_row` values by
note path (`{"Home/x.md": {"zone": "[[Kitchen]]"}}`), `drop` keys the table does not have.
Every note gets `table` and a system `id`; with `relocate` (default true, unlike move_rows:
notes become rows where the table keeps its rows) it moves to the table's folder, named by its filename pattern (links to it are rewritten). All notes are validated first
(as rows of `table`, so notes of the same call may link to one another):
unknown keys and bad values are listed and nothing is written. Run with `dry_run` first; undo
with `undo_migration`. Many notes: adopt them in calls of about 1,000 `paths` each, so a
stop or a crash interrupts less (each call is one journal entry).

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `X-Datanotes-Actor` | header | `string` | no | JSON: on whose behalf the write is made, recorded in the journal (`harness`, `model`, `session`). |

## Request body

`application/json`, required

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `table` | `string` | yes |  |  |
| `paths` | `string[]` | yes |  |  |
| `rename` | `object \| null` | no | `null` |  |
| `set` | `object \| null` | no | `null` |  |
| `per_row` | `object \| null` | no | `null` |  |
| `drop` | `string[] \| null` | no | `null` |  |
| `relocate` | `boolean` | no | `true` |  |
| `dry_run` | `boolean` | no | `false` |  |

## Responses

| Status | Description | Body |
| --- | --- | --- |
| 200 | Done. | `OpResult` (application/json) |
| 400 | Bad input: the body is not a JSON object, or an argument is unknown, missing or of the wrong type. | `Error` (application/json) |
| 401 | Missing or wrong bearer token. | `Error` (application/json) |
| 403 | A named token beyond its permissions (the engine's administration, tables outside its `write` patterns, schema changes without `ddl`). | `Error` (application/json) |
| 404 | Unknown table, view, migration, note or folder. | `Error` (application/json) |
| 409 | Ambiguous table name: it matches several tables (`paths` or `tables` lists them). | `AmbiguousName` (application/json) |
| 422 | Refused (validation failures, conflicts, an unmet `expect`): nothing written. Same body as 200, with `ok: false` and the reasons. | `OpResult` (application/json) |
| 500 | Unexpected error (`{error}`), or a write that failed partway and could not be rolled back: `rolled_back: false`, `failed` lists the files left (undo_migration on `migration_id` retries the rollback). | `OpResult \| Error` (application/json) |
| 503 | A write that failed partway (a file another program holds) and was rolled back: `rolled_back: true`, nothing written. Send it again later. Same body as 200, with `ok: false` and `failed`. | `OpResult` (application/json) |

The schemas named here are in [openapi.json](https://datanotes.dev/openapi.json) (`components.schemas`).
