- Introduced `analyst_auth_adapter.py` for managing authentication context and access control for the data analysis agent. - Added new API endpoints in `analyst.py` for chat, dashboard, asset management, and metrics, utilizing the new authentication context. - Created Pydantic models in `analyst_schemas.py` for request and response structures, ensuring consistent data handling. - Updated SQL guard logic in `sql_guard.py` to enforce access restrictions based on user roles and contexts. - Implemented migration scripts for new database tables related to the data analysis agent, enhancing data management capabilities. - Removed legacy authentication code from `auth.py`, streamlining the authentication process. This update significantly enhances the data analysis capabilities, providing a robust framework for querying and managing data securely.
62 lines
3.7 KiB
SQL
62 lines
3.7 KiB
SQL
-- =============================================================================
|
||
-- 数据分析 Agent 专用 MySQL(3 张 · 养 Agent 资产)
|
||
-- 执行:merge 数据分析 Agent 后 · jinrong_agent 库
|
||
-- 来源:docs/项目框架设计/表设计/03-mysql-analyst专用.sql
|
||
-- =============================================================================
|
||
|
||
USE jinrong_agent;
|
||
|
||
CREATE TABLE IF NOT EXISTS analytics_metric_dict (
|
||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||
metric_key VARCHAR(128) NOT NULL COMMENT '唯一键,如 holding_scale',
|
||
metric_name VARCHAR(128) NOT NULL COMMENT '持仓规模',
|
||
aliases JSON NULL COMMENT '同义词:["规模","市值"]',
|
||
definition TEXT NOT NULL COMMENT '口径定义',
|
||
formula TEXT NULL COMMENT '计算公式',
|
||
applicable_tables JSON NULL COMMENT '适用表清单',
|
||
default_time_window VARCHAR(64) NULL COMMENT '默认时间窗',
|
||
unit VARCHAR(32) NULL COMMENT '单位:元/万元/%',
|
||
status ENUM('draft','published','rolled_back') NOT NULL DEFAULT 'draft',
|
||
version INT UNSIGNED NOT NULL DEFAULT 1,
|
||
gray_roles JSON NULL COMMENT '灰度:null=全量,["advisor"]=部分角色',
|
||
created_by VARCHAR(64) NOT NULL,
|
||
published_by VARCHAR(64) NULL,
|
||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||
UNIQUE KEY uk_metric (metric_key, version),
|
||
KEY idx_status (status, metric_key)
|
||
) ENGINE=InnoDB COMMENT='【分析专用】口径字典(D-07/D-11)';
|
||
|
||
CREATE TABLE IF NOT EXISTS analytics_few_shot (
|
||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||
question TEXT NOT NULL,
|
||
sql_text TEXT NOT NULL,
|
||
tags JSON NULL,
|
||
source_session_id VARCHAR(64) NULL COMMENT '溯源会话',
|
||
status ENUM('draft','published','rolled_back') NOT NULL DEFAULT 'draft',
|
||
version INT UNSIGNED NOT NULL DEFAULT 1,
|
||
gray_roles JSON NULL,
|
||
created_by VARCHAR(64) NOT NULL,
|
||
published_by VARCHAR(64) NULL,
|
||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||
KEY idx_status (status, id)
|
||
) ENGINE=InnoDB COMMENT='【分析专用】few-shot 示例(D-11)';
|
||
|
||
CREATE TABLE IF NOT EXISTS analytics_query_template (
|
||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||
template_key VARCHAR(128) NOT NULL,
|
||
template_sql TEXT NOT NULL COMMENT '参数化 SQL,如 WHERE risk_code IN (:risk_codes)',
|
||
params_schema JSON NULL COMMENT '参数定义',
|
||
tags JSON NULL,
|
||
source_session_id VARCHAR(64) NULL,
|
||
status ENUM('draft','published','rolled_back') NOT NULL DEFAULT 'draft',
|
||
version INT UNSIGNED NOT NULL DEFAULT 1,
|
||
gray_roles JSON NULL,
|
||
created_by VARCHAR(64) NOT NULL,
|
||
published_by VARCHAR(64) NULL,
|
||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||
KEY idx_status (status, template_key)
|
||
) ENGINE=InnoDB COMMENT='【分析专用】快速模板(D-06/D-11)';
|