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