Files
Neo-ZQYY/.claude/hooks/post_edit_db_doc_sync.py
2026-04-10 06:24:13 +08:00

27 lines
830 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""PostToolUse hook: 编辑 db/ 下 SQL 文件后提醒同步 docs/database/"""
import json, re, sys
try:
data = json.load(sys.stdin)
except Exception:
sys.exit(0)
fp = (data.get("tool_input") or {}).get("file_path", "")
if not fp:
sys.exit(0)
rel = re.sub(r"^.*?NeoZQYY[/\\]", "", fp.replace("\\", "/"))
# 匹配 db/ 下的 SQL 文件schemas、migrations、脚本等
if re.search(r"^db/.*\.sql$", rel):
print(json.dumps({
"hookSpecificOutput": {
"hookEventName": "PostToolUse",
"additionalContext": (
f"[db-doc-sync] 已编辑数据库文件: {rel}"
"根据 Schema 变更规则,完成后须同步更新 docs/database/(变更说明、兼容性、回滚策略、验证 SQL"
)
}
}))