> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Project History Labels Collection

`projectHistoryLabels` holds the labels users put on versions in the History view, one document per label. project-history owns it and writes it in `services/project-history/app/js/LabelsManager.js`; there is no Mongoose schema. Web reaches it only through the project-history API.

#### Fields

| Field | Type | Meaning | Source |
| - | - | - | - |
| `_id` | ObjectId | Label id. | `LabelsManager.js:81-85` |
| `project_id` | ObjectId | The project. | `LabelsManager.js:73` |
| `comment` | String | The label text. | `LabelsManager.js:74` |
| `version` | Number | The project history version the label points at. | `LabelsManager.js:75` |
| `created_at` | Date | When the label was made; the request may pass its own time, otherwise now. | `LabelsManager.js:70`, `76` |
| `user_id` | ObjectId | Who made the label. Left out when the request has no user. | `LabelsManager.js:78-80` |

#### Who Writes It

| Code | What it does |
| - | - |
| `services/project-history/app/js/LabelsManager.js:44-90` | `createLabel`: inserts a label, for project-history `POST /project/:project_id/labels` (`services/project-history/app/js/HttpController.js:1134-1171`). Web calls it when a user adds a label, with the user's id (`services/web/app/src/Features/History/HistoryController.mjs:529-546`). |
| `LabelsManager.js:113-126` | `deleteLabel`: deletes a label of the project, for `DELETE /project/:project_id/labels/:label_id`. Web uses it when the project owner deletes a label (`HistoryController.mjs:649-670`). |
| `LabelsManager.js:92-111` | `deleteLabelForUser`: deletes a label only if the user made it, for `DELETE /project/:project_id/user/:user_id/labels/:label_id`. Web uses it for everyone else. |
| `LabelsManager.js:128-143` | `transferLabels`: moves all labels of one user to another, for `POST /user/:from_user/labels/transfer/:to_user` (`services/project-history/app/js/Router.js:52-55`). Nothing in web calls this route. |
| `LabelsManager.js:7-25` | `cloneLabels`: copies a project's labels to another project, for project-history `POST /project/:project_id/clone` (`HttpController.js:113`), which nothing in web calls. |

#### Who Reads It

| Code | What it does |
| - | - |
| `LabelsManager.js:27-42` | `getLabels`: all labels of a project, returned as `{ id, comment, version, user_id, created_at }` (`LabelsManager.js:163-171`). Used by `GET /project/:project_id/labels` (`HttpController.js:1076-1100`), which web calls for the History view and fills in user names (`HistoryController.mjs:488-499`). |
| `services/project-history/app/js/SummarizedUpdatesManager.js:57` | Adds the labels to the list of history updates. |

#### Indexes

| Name | Keys | Options | Migration |
| - | - | - | - |
| `project_id_1` | `{ project_id: 1 }` | | `tools/migrations/20190912145019_create_projectHistoryLabels_indexes.mjs` |
| `user_id_1` | `{ user_id: 1 }` | | `tools/migrations/20190912145019_create_projectHistoryLabels_indexes.mjs` |

#### Notes

* Before it inserts a label, project-history processes the project's queued updates and checks that history-v1 has a chunk for that version, unless the request sends `validate_exists: false` (`LabelsManager.js:53-59`, `173-195`; `HttpController.js:1109-1115`).
* No code deletes a project's labels when the project is deleted: project-history `DELETE /project/:project_id` only clears the sync state and the failure record (`HttpController.js:1363-1396`), and no other service touches this collection.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.