> ## 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.

# Migrations Collection

`migrations` records which database migrations have run. One document is one migration from `tools/migrations/`. It is written by the adapter of the [east](https://github.com/okv/east) migration tool, `tools/migrations/lib/adapter.mjs`, not by a running service.

#### Fields

| Field | Type | Meaning | Source |
| - | - | - | - |
| `_id` | ObjectId | Document id. | `adapter.mjs:103` |
| `name` | String | File name of the migration without the extension, for example `20190912145029_create_tags_indexes`. | `adapter.mjs:104` |
| `migratedAt` | Date | When the migration finished. | `adapter.mjs:105` |

#### Who Writes It

| Code | What it does |
| - | - |
| `adapter.mjs:101-107` (`markExecuted`) | Inserts a document after a migration ran. |
| `adapter.mjs:109-114` (`unmarkExecuted`) | Deletes it again when a migration is rolled back. |

CE runs `yarn run migrations migrate -t server-ce` at every container start (`server-ce/init_scripts/900_run_web_migrations.sh:4-12`; `-t server-pro` when `OVERLEAF_IS_SERVER_PRO=true`). Only migrations whose `tags` include that environment run, so only those get a document here.

#### Who Reads It

| Code | What it does |
| - | - |
| `adapter.mjs:72-99` (`getExecutedMigrationNames`) | east skips every migration whose name is already here. |
| `tools/migrations/lib/helpers.mjs:67-75` (`assertDependency`) | A migration that needs another one to have run first throws when that name is missing. |

#### Indexes

| Name | Keys | Options | Migration |
| - | - | - | - |
| `name_1` | `{ name: 1 }` | unique | `tools/migrations/20190720165251_create_migrations.mjs` |

#### Notes

* Deleting a document makes that migration run again at the next container start, if its tags match.
* With an auxiliary Mongo cluster (`mongo.auxUrl`), migrations tagged `auxiliary` are recorded in the `migrations` collection of that cluster instead (`adapter.mjs:8-15`, `:64-70`). `mongo.auxUrl` comes from `MONGO_AUX_CONNECTION_STRING` (`tools/migrations/config/settings.defaults.js:19`), which is unset by default.


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