Skip to main content 首页 创作者 modu-ai moai-studio moai-domain-db-docs
moai-domain-db-docs Parses DB migration files (Prisma, Alembic, Rails, raw SQL) and keeps .moai/project/db/schema.md, erd.mmd, migrations.md in sync. Powers the PostToolUse hook and /moai db refresh/verify subcommands.
跳到安装 Skills Marketplace 发现并探索由社区构建的 Agent Skills
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/modu-ai/moai-studio --skill moai-domain-db-docs命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
下载 Zip 下载中... name moai-domain-db-docs description Parses DB migration files (Prisma, Alembic, Rails, raw SQL) and keeps .moai/project/db/schema.md, erd.mmd, migrations.md in sync. Powers the PostToolUse hook and /moai db refresh/verify subcommands.
license Apache-2.0 compatibility Designed for Claude Code allowed-tools Read, Write, Edit, Grep, Glob, Bash, TaskCreate, TaskUpdate user-invocable false metadata {"version":"1.0.0","category":"domain","status":"active","updated":"2026-04-20","tags":"db, schema, migration, documentation, sync, drift"} triggers {"keywords":["db docs","schema sync","migration parse","erd update"],"agents":["expert-backend"],"phases":["run","sync"]}
moai-domain-db-docs: DB Documentation Sync Skill
Purpose: Consume .moai/cache/db-sync/proposal.json and update the three DB documentation
files (schema.md, erd.mmd, migrations.md) in .moai/project/db/.
SPEC: SPEC-DB-SYNC-001
Invocation Modes
This skill is invoked in two ways:
PostToolUse approval flow (via orchestrator): After the user selects "Apply" in the
3-option AskUserQuestion dialog, the orchestrator invokes this skill with proposal.json.
Direct subcommand : Via /moai db refresh (full rebuild) or /moai db verify (drift check).
Recursion Guard (REQ-019)
Before writing any file, check that the target path is NOT in the Excluded Patterns:
.moai/project/db/**
.moai/cache/**
.moai/logs/**
If the target matches an excluded pattern, abort silently. This is a skill-level guard
complementing the hook-level guard (REQ-004).
Phase A: Apply Proposal (REQ-013, REQ-016, REQ-017, REQ-018)
Triggered when user selects "Apply" in the approval flow.
A1: Read proposal.json
Read .moai/cache/db-sync/proposal.json
Extract:
file_path: original migration file
parsed_content: normalized schema representation
timestamp: ISO-8601 creation time
A2: Update schema.md (REQ-016)
Rules for in-place update:
Read existing .moai/project/db/schema.md.
Identify sections delimited by ## headers.
For each table/collection referenced in parsed_content:
If a matching row exists, update column_count and last_migration_file.
If no matching row, append a new row preserving _TBD_ in user-managed columns.
Do NOT overwrite user-edited descriptions or _TBD_ markers.
Write updated file using Edit tool.
A3: Regenerate erd.mmd (REQ-017)
Rules:
Read existing to extract the comment header block (lines starting with ).
.moai/project/db/erd.mmd
%%
Rebuild the erDiagram body from parsed_content table definitions.
Preserve the original comment header verbatim.
Validate Mermaid syntax: must start with erDiagram after the comment header.
Write using Edit tool (or Write if file is new). %% MoAI DB ERD — auto-generated. Edit schema.md to add relationships.
%% Last updated: <ISO-8601 timestamp>
erDiagram
<TABLE_NAME> {
<type> <column_name>
}
A4: Append to migrations.md (REQ-018)
Read existing .moai/project/db/migrations.md.
Locate the ## Applied Migrations table.
Append a new row with:
filename: basename of file_path
applied_at: ISO-8601 timestamp from proposal
checksum: SHA-256 of the migration file content (compute via sha256sum or shasum -a 256)
up_summary: first non-comment line of parsed_content (truncated to 80 chars)
Write using Edit tool.
Phase B: User Approval Flow (REQ-012, REQ-014, REQ-015) This phase documents the orchestrator-level behavior that invokes this skill.
The orchestrator (not this skill) calls AskUserQuestion.
B1: 3-Option AskUserQuestion When proposal.json is present and decision == "ask-user", the orchestrator presents:
Question: "Migration file changed. Update schema documentation?"
Apply (권장) — Apply proposed schema update: invoke moai-domain-db-docs to update
schema.md, erd.mmd, and migrations.md from the parsed migration file.
Review — Review diff first: display the diff between current schema.md and proposed
changes, then re-ask Apply/Skip.
Skip — Skip this time: delete proposal.json and take no action.
B2: Review diff (REQ-014) If user selects "Review":
Read current .moai/project/db/schema.md.
Generate a unified diff between current content and proposed content from parsed_content.
Display diff (truncate to 100 lines; add note "see proposal.json for full diff" if truncated).
Re-ask with 2 options: Apply / Skip.
B3: Skip (REQ-015)
Delete .moai/cache/db-sync/proposal.json.
Output: "Schema update skipped."
Phase C: /moai db verify (REQ-020, REQ-021, REQ-022) Triggered by /moai db verify. Read-only — MUST NOT modify any files.
C1: Compute expected schema
Scan migration files using patterns from db.yaml migration_patterns.
Extract table names from each migration file (stub: grep for CREATE TABLE).
Build expected set E of table names.
C2: Read current schema.md
Read .moai/project/db/schema.md.
Extract registered table names from the ## Tables section.
Build documented set D of table names.
C3: Diff and output Compute symmetric difference: drift = (E - D) ∪ (D - E)
Print: Schema documentation is in sync
Exit 0 (REQ-022)
Print unified diff to stdout showing added/removed tables (REQ-021)
Exit 1 (REQ-021)
--- schema.md (documented)
+++ migrations (actual)
@@ -1,N +1,M @@
+ <table added in migrations, missing from schema.md>
- <table in schema.md, missing from migrations>
Phase D: /moai db refresh (REQ-023, REQ-024) Triggered by /moai db refresh. Full rebuild from all migration files.
D1: User confirmation (REQ-024) Question: "Confirm full rebuild of schema.md, erd.mmd, and migrations.md?"
Apply (권장) — Rebuild all 3 docs from scratch by rescanning all migration files.
Cancel — Cancel the rebuild. No files will be modified.
If Cancel: exit 0 with message "Refresh cancelled."
D2: Full scan
Use Glob to find all migration files matching patterns from db.yaml.
Parse each file using the stub parser (read content).
Aggregate all table definitions.
D3: Rebuild 3 docs
schema.md — regenerate table registry from aggregated tables.
erd.mmd — regenerate erDiagram from aggregated tables.
migrations.md — regenerate Applied Migrations table with all found files.
Use Write tool (not Edit) since this is a full rebuild.
Rebuilt schema.md: <N> tables
Rebuilt erd.mmd: <N> entities
Rebuilt migrations.md: <N> migration entries
Excluded Patterns Reference Do NOT write to or process these paths (recursion guard, REQ-019):
.moai/project/db/**
.moai/cache/**
.moai/logs/**
Error Handling
If any file read/write fails: log to .moai/logs/db-sync-errors.log and continue with remaining files.
If SHA-256 computation fails: use unknown as checksum value.
If erDiagram validation fails: write a minimal valid erDiagram {} and log the error.
Never block the user's workflow (always exit 0 on non-fatal errors).
MoAI unified orchestrator for autonomous development. Routes natural language or subcommands (plan, run, sync, design, db, project, fix, loop, mx, feedback, review, clean, codemaps, coverage, e2e) to specialized agents.