Agent Skillstheopenco/llmgateway › migrations

migrations

GitHub

处理 Drizzle 数据库迁移的生成、审查、编辑及冲突解决。默认使用生成的 SQL,禁止手动修改元数据,仅允许为锁表优化调整 SQL,并提供详细的冲突处理流程。

.agents/skills/migrations/SKILL.md theopenco/llmgateway

Trigger Scenarios

更改 packages/db/src/schema.ts 运行 pnpm migrations 或 pnpm migrate 处理 packages/db/migrations 下的文件变更 审查迁移差异 解决迁移合并冲突

Install

npx skills add theopenco/llmgateway --skill migrations -g -y
More Options

Non-standard path

npx skills add https://github.com/theopenco/llmgateway/tree/main/.agents/skills/migrations -g -y

Use without installing

npx skills use theopenco/llmgateway@migrations

指定 Agent (Claude Code)

npx skills add theopenco/llmgateway --skill migrations -a claude-code -g -y

安装 repo 全部 skill

npx skills add theopenco/llmgateway --all -g -y

预览 repo 内 skill

npx skills add theopenco/llmgateway --list

SKILL.md

Frontmatter
{
    "name": "migrations",
    "description": "Generate, review, edit, apply, or resolve conflicts for Drizzle database migrations in this repo. Use when changing packages\/db\/src\/schema.ts, running pnpm migrations or pnpm migrate, touching packages\/db\/migrations, reviewing migration diffs, or handling migration merge conflicts."
}

Migrations

Use this workflow for database schema changes and migration conflicts.

Default: use generated SQL

Assume Drizzle applies migrations cleanly, in order, and tracks which have run. Generate, review, and commit the migration without adapting its SQL by default.

Do not add IF NOT EXISTS, IF EXISTS, existence probes, or duplicate-object handlers for hypothetical reruns, partial application, or schema drift. Regenerating an unmerged migration after syncing with main does not justify compatibility with its earlier branch version. A speculative review warning is not evidence that a migration ran outside the normal workflow.

Generate migrations

  • Run all commands from the repository root.
  • Make schema changes in packages/db/src/schema.ts.
  • Generate Drizzle migration artifacts with pnpm migrations.
  • Review the generated diff under packages/db/migrations/.
  • Drizzle may generate:
    • packages/db/migrations/<timestamp>_<name>.sql
    • packages/db/migrations/meta/<timestamp>_snapshot.json
    • packages/db/migrations/meta/_journal.json

Editing generated migrations

  • Do not write a migration by hand from scratch. Generate it first with pnpm migrations.
  • The operational exception is avoiding locks on huge tables, especially when creating indexes. Treat all history tables as large when reviewing locking behavior.
  • If that requires adaptation, edit only the generated .sql file.
  • Never manually edit any *_snapshot.json file.
  • Never manually edit packages/db/migrations/meta/_journal.json.
  • If the TypeScript schema is wrong, fix packages/db/src/schema.ts and regenerate instead of patching snapshot or journal metadata.
  • Use snake_case column names in SQL because Drizzle maps camelCase TypeScript fields to snake_case database columns.

For a large-table index change, a staged rollout may require splitting the change into two generated migrations and running CREATE INDEX CONCURRENTLY manually between them, outside a transaction. Document the required order in the SQL. Keep the generated snapshot and journal exactly as Drizzle wrote them.

Conflict resolution

Never resolve merge conflicts in migration SQL, snapshot JSON, or journal files manually.

When merging with main and migration conflicts appear:

  1. The reset in step 1 rewrites packages/db/migrations/ from origin/main, and it acts on tracked files only. Two consequences:
  • An untracked .sql (one you just generated but have not committed) survives the reset and then collides with what step 2 regenerates. It is also invisible to git diff, so the capture below would miss it.
  • Any necessary locking adaptation of a generated .sql is reverted, and pnpm migrations emits vanilla SQL from the schema diff, so it will not come back on its own.

Commit (or delete) everything under the directory first, so nothing is untracked and the capture sees all of it:

git status --porcelain packages/db/migrations/   # must print nothing before continuing
git diff origin/main -- packages/db/migrations/ > /tmp/migration-adaptations.patch

Keep that patch as your reference and re-apply the adaptations by hand in step 3. Do not use git stash for this — lint-staged inserts its own backup stashes at position 0 in this repo, so a bare git stash pop can restore the wrong entry.

  1. Reset migrations to origin/main:
git restore --source=origin/main packages/db/migrations/
  1. Re-run generation from the repository root:
pnpm migrations
  1. Review the regenerated SQL, then re-apply only still-required locking adaptations captured in step 0. Do not carry speculative fallbacks forward. Adapt only the generated .sql file.

Validation

  • Inspect git diff packages/db/src/schema.ts packages/db/migrations/.
  • Confirm any snapshot JSON and journal changes came from pnpm migrations, not manual edits.
  • Run pnpm format after changes.
  • Run pnpm build after schema or migration changes.

Version History

  • bf6473c Current 2026-09-09 03:58

    修正迁移指南中不必要的防御性 SQL,默认信任生成的 Drizzle SQL,拒绝推测性兼容性保护,并文档化大表和历史表的并发索引创建作为操作异常。

  • 8fdff5b 2026-08-16 07:59
  • 8c03315 2026-07-24 16:53

Same Skill Collection

.agents/skills/add-model/SKILL.md
.agents/skills/blog/SKILL.md
.agents/skills/changelog/SKILL.md
.agents/skills/core-web-vitals/SKILL.md
.agents/skills/knowledge-base/SKILL.md
.agents/skills/pull-request/SKILL.md
.agents/skills/skill-authoring/SKILL.md
.agents/skills/verify/SKILL.md
.claude/skills/verify/SKILL.md

Metadata

Files
0
Version
bf6473c
Hash
4a6b4c4e
Indexed
2026-07-24 16:53

ホーム - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-09 20:47
浙ICP备14020137号-1 $お客様$