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.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
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.
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).
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)
If user selects "Skip":
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.yamlmigration_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.