This repository has been archived on 2026-03-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
YLHP_HR_2.0/migrations/README.md
JiaoTianBo a40c239996 feat(database): 初始化数据库结构及添加默认评价方案
- 创建候选人主表 candidates,包含基本信息和索引
- 创建简历内容表 resumes,支持附件和版本控制
- 创建职位信息表 jobs,包含职位详情及状态索引
- 创建评价方案表 evaluation_schemas,支持多维度配置及权重
- 创建评价记录表 evaluations,关联候选人、方案及职位,支持多维评分及推荐
- 创建通知记录表 notifications,涵盖多渠道通知及状态管理
- 插入通用和Java后端岗位的默认评价方案,支持重复时更新
- 添加详细的数据库配置指南和常用查询示例文档README.md
2026-03-24 11:34:27 +08:00

185 lines
4.2 KiB
Markdown
Raw Permalink 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.
# 数据库配置指南
## 1. 数据库设计文档
### 核心表结构
| 表名 | 说明 | 主要字段 |
|------|------|----------|
| `candidates` | 候选人主表 | 基本信息、职业信息、联系方式、状态 |
| `resumes` | 简历内容表 | 原始内容、解析内容、附件、版本 |
| `jobs` | 职位信息表 | 职位名称、部门、薪资、要求 |
| `evaluation_schemas` | 评价方案表 | 维度配置、权重、提示词模板 |
| `evaluations` | 评价记录表 | 评分结果、AI分析、推荐意见 |
| `notifications` | 通知记录表 | 通知渠道、状态、发送时间 |
### ER 关系图
```
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ candidates │────<│ resumes │ │ jobs │
│ (候选人) │ │ (简历) │ │ (职位) │
└──────┬──────┘ └─────────────┘ └──────┬──────┘
│ │
│ ┌─────────────┐ │
└────────>│ evaluations │<─────────────┘
│ (评价记录) │
└──────┬──────┘
┌──────┴──────┐
│ notifications│
│ (通知记录) │
└─────────────┘
```
## 2. 数据库配置方法
### 方法一SQLite (开发测试)
无需额外配置,默认使用 SQLite
```bash
# 在项目根目录创建 .env 文件
echo "DB_URL=sqlite:///./hr_agent.db" > .env
```
### 方法二MySQL (生产环境)
#### 2.1 创建数据库
```sql
CREATE DATABASE hr_agent CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'hr_agent'@'%' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON hr_agent.* TO 'hr_agent'@'%';
FLUSH PRIVILEGES;
```
#### 2.2 配置连接
```bash
# .env 文件
echo "DB_URL=mysql+pymysql://hr_agent:your_password@localhost:3306/hr_agent" > .env
```
#### 2.3 安装依赖
```bash
uv add pymysql cryptography
```
### 方法三PostgreSQL
#### 3.1 创建数据库
```sql
CREATE DATABASE hr_agent ENCODING 'UTF8';
CREATE USER hr_agent WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE hr_agent TO hr_agent;
```
#### 3.2 配置连接
```bash
# .env 文件
echo "DB_URL=postgresql+asyncpg://hr_agent:your_password@localhost:5432/hr_agent" > .env
```
#### 3.3 安装依赖
```bash
uv add asyncpg
```
## 3. 初始化数据库
### 3.1 执行 SQL 脚本
```bash
# MySQL
mysql -u hr_agent -p hr_agent < migrations/001_init_schema.sql
# SQLite
sqlite3 hr_agent.db < migrations/001_init_schema.sql
# PostgreSQL
psql -U hr_agent -d hr_agent -f migrations/001_init_schema.sql
```
### 3.2 验证初始化
```sql
-- 查看表结构
SHOW TABLES;
-- 查看默认评价方案
SELECT * FROM evaluation_schemas;
```
## 4. 环境变量配置
在项目根目录创建 `.env` 文件:
```env
# 数据库配置
DB_URL=sqlite:///./hr_agent.db
DB_ECHO=false
# LLM 配置
LLM_PROVIDER=mock
LLM_API_KEY=
LLM_MODEL=gpt-4
# 爬虫配置
CRAWLER_BOSS_WT_TOKEN=your_boss_token
# 通知配置 (可选)
NOTIFY_WECHAT_WORK_WEBHOOK=
NOTIFY_DINGTALK_WEBHOOK=
```
## 5. 常用查询示例
### 查询候选人列表
```sql
SELECT
c.id,
c.name,
c.source,
c.current_company,
c.current_position,
c.status,
e.overall_score,
e.recommendation
FROM candidates c
LEFT JOIN evaluations e ON c.id = e.candidate_id
WHERE c.status = 'NEW'
ORDER BY c.created_at DESC;
```
### 查询高分候选人
```sql
SELECT
c.name,
c.current_company,
e.overall_score,
e.summary
FROM candidates c
JOIN evaluations e ON c.id = e.candidate_id
WHERE e.overall_score >= 80
AND e.recommendation IN ('strong_recommend', 'recommend')
ORDER BY e.overall_score DESC;
```
### 统计各渠道候选人数量
```sql
SELECT
source,
COUNT(*) as total,
SUM(CASE WHEN status = 'ANALYZED' THEN 1 ELSE 0 END) as analyzed
FROM candidates
GROUP BY source;
```