Files
group_xinghuo_jinrong/scripts/dev/dump_schema.py
T
zyi b19a2415f9 feat: 数据分析 Agent 实现(API/服务/表结构元数据/文档/测试)
- 新增 app/api、app/service 数据分析 Agent 全套服务与接口
- schemas.py 重构为 schemas 包(analyst schema)
- 新增 SQL 防注入、guardrail、缓存、字典、LLM 等服务
- 新增 tests 测试套件与 scripts/dev、scripts/setup 脚本
- 补充需求规格、架构说明书、开发清单、表设计等文档
2026-09-09 18:04:45 +08:00

56 lines
1.6 KiB
Python

"""导出数据分析 Agent 可读表的列结构(用于 NL2SQL 的 schema 元数据注入)。"""
import pathlib
import pymysql
def load_env(path=".env"):
env = {}
for line in pathlib.Path(path).read_text(encoding="utf-8").splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
k, v = line.split("=", 1)
env[k.strip()] = v.strip()
return env
TABLES = [
("jinrong_core", "core_customer"),
("jinrong_core", "core_customer_risk"),
("jinrong_core", "core_customer_advisor"),
("jinrong_core", "core_holding"),
("jinrong_core", "core_trade"),
("jinrong_core", "core_cash_flow"),
("jinrong_core", "core_product"),
("jinrong_core", "core_product_nav"),
("jinrong_core", "core_staff"),
("jinrong_core", "core_risk_grade"),
("jinrong_agent", "risk_alert"),
]
def main():
env = load_env()
conn = pymysql.connect(
host=env.get("MYSQL_HOST", "127.0.0.1"),
port=int(env.get("MYSQL_PORT", "3306")),
user=env.get("MYSQL_USER", "root"),
password=env.get("MYSQL_PASSWORD", ""),
charset="utf8mb4",
)
with conn.cursor() as cur:
for db, tbl in TABLES:
cur.execute(
"SELECT column_name, data_type FROM information_schema.columns "
"WHERE table_schema=%s AND table_name=%s ORDER BY ordinal_position",
(db, tbl),
)
cols = [f"{c[0]}:{c[1]}" for c in cur.fetchall()]
print(f"{tbl} ({db}) -> {', '.join(cols)}")
conn.close()
if __name__ == "__main__":
main()