开发机迁移
This commit is contained in:
37
.claude/hooks/post_edit_rls_dual_schema.py
Normal file
37
.claude/hooks/post_edit_rls_dual_schema.py
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""PostToolUse hook: 编辑含 CREATE VIEW 的 SQL 文件时提醒双 Schema 规则"""
|
||||
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 文件
|
||||
if not re.search(r"^db/.*\.sql$", rel):
|
||||
sys.exit(0)
|
||||
|
||||
# 读取文件内容检查是否包含 CREATE VIEW
|
||||
try:
|
||||
with open(fp, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
except Exception:
|
||||
sys.exit(0)
|
||||
|
||||
# 检测 CREATE [OR REPLACE] VIEW 语句
|
||||
if re.search(r"CREATE\s+(OR\s+REPLACE\s+)?VIEW\s+(dws|dwd|core)\.", content, re.IGNORECASE):
|
||||
print(json.dumps({
|
||||
"hookSpecificOutput": {
|
||||
"hookEventName": "PostToolUse",
|
||||
"additionalContext": (
|
||||
f"[rls-dual-schema] 检测到 {rel} 中包含 dws/dwd/core schema 的 VIEW 定义 — "
|
||||
"根据 RLS 视图双 Schema 规则,必须同时在原 schema 和 app schema 创建对应视图,否则后端查询会失败。"
|
||||
)
|
||||
}
|
||||
}))
|
||||
Reference in New Issue
Block a user