> ## 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 集合

`migrations` 记录哪些数据库迁移已经运行。一个文档对应 `tools/migrations/` 中的一个迁移。它由迁移工具 [east](https://github.com/okv/east) 的适配器 `tools/migrations/lib/adapter.mjs` 写入，而不是由运行中的服务写入。

#### 字段

| 字段 | 类型 | 含义 | 来源 |
| - | - | - | - |
| `_id` | ObjectId | 文档 id。 | `adapter.mjs:103` |
| `name` | String | 不含扩展名的迁移文件名，例如 `20190912145029_create_tags_indexes`。 | `adapter.mjs:104` |
| `migratedAt` | Date | 迁移完成的时间。 | `adapter.mjs:105` |

#### 谁写入

| 代码 | 作用 |
| - | - |
| `adapter.mjs:101-107` (`markExecuted`) | 迁移运行后插入一个文档。 |
| `adapter.mjs:109-114` (`unmarkExecuted`) | 回滚迁移时再次删除该文档。 |

CE 在每次容器启动时运行 `yarn run migrations migrate -t server-ce`（`server-ce/init_scripts/900_run_web_migrations.sh:4-12`；当 `OVERLEAF_IS_SERVER_PRO=true` 时为 `-t server-pro`）。只有 `tags` 包含该环境的迁移才会运行，因此只有它们会在这里留下文档。

#### 谁读取

| 代码 | 作用 |
| - | - |
| `adapter.mjs:72-99` (`getExecutedMigrationNames`) | east 会跳过名称已在此处的所有迁移。 |
| `tools/migrations/lib/helpers.mjs:67-75` (`assertDependency`) | 需要另一个迁移先运行的迁移，在该名称缺失时会抛出错误。 |

#### 索引

| 名称 | 键 | 选项 | 迁移 |
| - | - | - | - |
| `name_1` | `{ name: 1 }` | unique | `tools/migrations/20190720165251_create_migrations.mjs` |

#### 说明

* 删除某个文档后，如果标签匹配，该迁移会在下次容器启动时再次运行。
* 使用辅助 Mongo 集群（`mongo.auxUrl`）时，带 `auxiliary` 标签的迁移会改为记录在该集群的 `migrations` 集合中（`adapter.mjs:8-15`、`:64-70`）。`mongo.auxUrl` 来自 `MONGO_AUX_CONNECTION_STRING`（`tools/migrations/config/settings.defaults.js:19`），默认未设置。


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