create-migration
Create a new MongoDB migration for schema or data changes in Mako. Use when adding fields, indexes, or modifying data in the database.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Create a new MongoDB migration for schema or data changes in Mako. Use when adding fields, indexes, or modifying data in the database.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Load when building, editing, or debugging Mako React apps — app files, npm dependencies, data bindings, the @mako/app-sdk hooks (useQuery / useDuckDB / useLocation / useSearchParams / navigate), URL state and shareable deep links, materialized Parquet/DuckDB bindings, and the live preview runtime.
Load for dbt branches, commits, pushes, pull requests, merges, repository sync, or branch cleanup.
Load when creating, editing, scheduling, running, or debugging dbt jobs and production deployments.
Load when building, editing, running, or debugging dbt models, dbt projects, schema.yml tests, sources, seeds, snapshots, incremental models, materializations, or dbt jobs in the Transforms section.
Load when creating, editing, configuring, validating, or debugging database sync flows, connector flows, pagination, incremental sync, destination mappings, and flow form fields.
Add a new MCP server preset (connector) to Mako's MCP client system — server URL, auth model (OAuth DCR, pre-registered app, or API key), scopes, icon, tests, and docs. Use when connecting a new external MCP server (like Slack or Close CRM) or changing how MCP connections authenticate.
| name | create-migration |
| description | Create a new MongoDB migration for schema or data changes in Mako. Use when adding fields, indexes, or modifying data in the database. |
Mako uses a custom MongoDB migration system. Migrations are TypeScript files in api/src/migrations/ that run sequentially and are tracked in a migrations collection.
pnpm migrate create "description_of_change"
This creates a file matching yyyy-mm-dd-hhmmss_description_of_change.ts.
up functionEdit the generated file:
import { Db } from "mongodb";
export const description = "Add email index to users collection";
export async function up(db: Db): Promise<void> {
// MUST be idempotent — safe to re-run
const indexes = await db.collection("users").indexes();
const hasIndex = indexes.some(
idx => JSON.stringify(idx.key) === JSON.stringify({ email: 1 }),
);
if (!hasIndex) {
await db.collection("users").createIndex({ email: 1 });
}
}
pnpm migrate # Run pending migrations
pnpm migrate status # Verify it was applied
const indexes = await db.collection("items").indexes();
const hasIndex = indexes.some(
idx =>
JSON.stringify(idx.key) ===
JSON.stringify({ workspaceId: 1, createdAt: -1 }),
);
if (!hasIndex) {
await db
.collection("items")
.createIndex(
{ workspaceId: 1, createdAt: -1 },
{ name: "items_workspace_created" },
);
}
An index may already exist with an auto-generated name (from Mongoose or a partial run). Checking by name will miss it and createIndex will throw IndexOptionsConflict.
await db
.collection("users")
.updateMany(
{ newField: { $exists: false } },
{ $set: { newField: "default_value" } },
);
await db
.collection("items")
.updateMany(
{ oldField: { $exists: true } },
{ $rename: { oldField: "newField" } },
);
yyyy-mm-dd-hhmmss_snake_case_name.ts$exists checks, upserts, and key-pattern index checksMigrations run automatically after deploy via GitHub Actions. If a migration fails, the deploy exits with error but the service is already deployed.
api/src/migrations/runner.tsapi/src/migrations/cli.tsapi/src/migrations/README.md.cursor/rules/90-migrations.mdc