Files
opsxsql/数据审核平台菜单优化/data-audit-platform/README.md
T
loganandClaude Opus 4.7 439155c92e Initial commit: SQL audit platform v0.1.0
FastAPI backend with auth, user, instance, ticket, query, dashboard APIs.
React + TypeScript frontend with mock data UI (10 pages).
SQLite + async SQLAlchemy, JWT auth, role-based access control.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 11:11:57 +08:00

238 lines
5.5 KiB
Markdown
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.
# 数据审核平台
一个基于 FastAPI + Vue3 的数据库变更管理和 SQL 审核平台,支持 MySQL、Redis 等数据库的 SQL 审核、审批流程管理。
## 功能特性
### 核心功能
- **数据源管理**:支持 MySQL、Redis、PostgreSQL、MongoDB 等多种数据库
- **SQL 审核**:自动 SQL 语法检查、风险评估、规则校验
- **工单管理**:DDL/DML 工单提交、审核、执行、回滚全流程
- **审批流程**:多级审批、角色权限控制
- **SQL 查询**:在线 SQL 编辑器,支持语法高亮和自动补全
- **数据字典**:表结构查看、字段信息、索引信息
- **Redis 管理**:Redis 信息监控、命令执行
### 安全特性
- 基于角色的访问控制 (RBAC)
- SQL 注入防护
- 敏感操作审计日志
- 数据脱敏
## 技术栈
### 后端
- **框架**: FastAPI (Python 3.11+)
- **数据库**: SQLAlchemy + MySQL
- **缓存**: Redis
- **认证**: JWT + OAuth2
### 前端
- **框架**: Vue 3 + TypeScript
- **UI 组件**: Element Plus
- **状态管理**: Pinia
- **路由**: Vue Router
- **代码编辑器**: CodeMirror 6
- **图表**: ECharts
## 快速开始
### 环境要求
- Python 3.11+
- Node.js 18+
- MySQL 5.7+
- Redis 6.0+
### 后端启动
```bash
cd backend
# 创建虚拟环境
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 安装依赖
pip install -r requirements.txt
# 启动服务
python main.py
```
后端服务将在 http://localhost:8000 启动,API 文档地址: http://localhost:8000/docs
### 前端启动
```bash
cd frontend
# 安装依赖
npm install
# 启动开发服务器
npm run dev
```
前端服务将在 http://localhost:3000 启动
### 默认账号
| 账号 | 密码 | 角色 |
|------|------|------|
| admin | 123456 | 管理员 |
| dba | 123456 | DBA |
| dev1 | 123456 | 开发者 |
| dev2 | 123456 | 开发者 |
| auditor | 123456 | 审计员 |
## 项目结构
```
data-audit-platform/
├── backend/ # 后端代码
│ ├── main.py # 主入口
│ └── requirements.txt # 依赖
├── frontend/ # 前端代码
│ ├── src/
│ │ ├── api/ # API 接口
│ │ ├── components/ # 组件
│ │ ├── layouts/ # 布局
│ │ ├── router/ # 路由
│ │ ├── stores/ # 状态管理
│ │ ├── styles/ # 样式
│ │ ├── types/ # 类型定义
│ │ ├── views/ # 页面
│ │ ├── App.vue # 根组件
│ │ └── main.ts # 入口
│ ├── index.html
│ ├── package.json
│ ├── tsconfig.json
│ └── vite.config.ts
└── README.md
```
## 功能模块
### 1. 仪表盘
- 数据统计卡片
- 风险分布图表
- 数据库类型分布
- 最近工单列表
### 2. 数据源管理
- 添加/编辑/删除数据源
- 支持多种数据库类型
- 连接测试
- 环境隔离(开发/测试/预发布/生产)
### 3. SQL 工单
- 创建工单(DDL/DML)
- SQL 自动审核
- 多级审批流程
- 工单执行和回滚
### 4. SQL 查询
- 在线 SQL 编辑器
- 语法高亮
- 只读查询限制
- 查询结果展示
### 5. 数据字典
- 表结构查看
- 字段信息
- 索引信息
- DDL 生成
### 6. Redis 管理
- Redis 信息监控
- 内存使用统计
- 命中率监控
- 命令执行
### 7. 审核规则
- 内置审核规则
- 规则启用/禁用
- 风险等级设置
### 8. 用户管理
- 用户列表
- 角色分配
- 权限控制
### 9. 系统设置
- 基本设置
- 通知设置
- 安全设置
## API 接口
### 认证
- `POST /api/auth/login` - 登录
- `GET /api/auth/me` - 获取当前用户
- `POST /api/auth/logout` - 登出
### 用户
- `GET /api/users` - 用户列表
- `GET /api/users/{id}` - 用户详情
### 数据源
- `GET /api/instances` - 数据源列表
- `POST /api/instances` - 创建数据源
- `GET /api/instances/{id}` - 数据源详情
- `PUT /api/instances/{id}` - 更新数据源
- `DELETE /api/instances/{id}` - 删除数据源
- `POST /api/instances/{id}/test` - 测试连接
### SQL 工单
- `GET /api/workflows` - 工单列表
- `POST /api/workflows` - 创建工单
- `GET /api/workflows/{id}` - 工单详情
- `POST /api/workflows/{id}/review` - 审核工单
- `POST /api/workflows/{id}/execute` - 执行工单
- `POST /api/workflows/{id}/rollback` - 回滚工单
- `GET /api/workflows/statistics` - 工单统计
### SQL 查询
- `POST /api/query` - 执行查询
### 数据字典
- `GET /api/dictionary/instances/{id}/databases` - 数据库列表
- `GET /api/dictionary/instances/{id}/tables` - 表列表
- `GET /api/dictionary/instances/{id}/tables/{name}` - 表详情
### Redis
- `GET /api/redis/{id}/info` - Redis 信息
- `POST /api/redis/{id}/command` - 执行命令
### Dashboard
- `GET /api/dashboard/stats` - 统计数据
## 部署
### Docker 部署
```bash
# 构建镜像
docker build -t data-audit-platform .
# 运行容器
docker run -d -p 8000:8000 -p 3000:3000 data-audit-platform
```
### 生产环境部署
1. 配置环境变量
2. 使用 Gunicorn 启动后端
3. 使用 Nginx 反向代理前端
4. 配置 SSL 证书
## 参考项目
- [Bytebase](https://github.com/bytebase/bytebase) - Database DevOps and CI/CD for Developer, DBA and Platform Engineering teams
- [Yearning](https://github.com/cookieY/Yearning) - 开源 MySQL SQL 审核平台
- [Archery](https://github.com/hhyo/Archery) - SQL 审核查询平台
## 许可证
MIT License