宇恒一号官网
This commit is contained in:
159
MongoDB/README.md
Normal file
159
MongoDB/README.md
Normal file
@@ -0,0 +1,159 @@
|
||||
# MongoDB 集合说明(yh_web)
|
||||
|
||||
默认数据库名:`yxd-agent-testing`(见 `server/config/constants.go`)。
|
||||
|
||||
以下为功能涉及的集合及文档结构,**线上已有的集合也按此结构对照**;缺失的集合可用 `create_collections.js` 创建。
|
||||
|
||||
---
|
||||
|
||||
## 1. sites(站点)
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| _id | ObjectID | 主键 |
|
||||
| name | string | 站点名称 |
|
||||
| domain | string | 域名 |
|
||||
| description | string | 描述(可选) |
|
||||
| created_at | string | 创建时间(如 RFC3339) |
|
||||
|
||||
---
|
||||
|
||||
## 2. pages(网页,属于某站点)
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| _id | ObjectID | 主键 |
|
||||
| site_id | string | 站点 ID(ObjectID 十六进制字符串) |
|
||||
| slug | string | 路径标识:index, about, ... |
|
||||
| title | string | 标题 |
|
||||
| type | string | 类型:homepage / page |
|
||||
| content | string | HTML 或 JSON 字符串(首页为 HomepageData JSON) |
|
||||
| updated_at | string | 更新时间 |
|
||||
|
||||
**索引建议**:`{ site_id: 1, slug: 1 }` 唯一,便于按站点+slug 查首页/子页。
|
||||
|
||||
---
|
||||
|
||||
## 3. site_assets(站点资源/上传文件)
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| _id | ObjectID | 主键 |
|
||||
| site_id | string | 站点 ID |
|
||||
| name | string | 文件名/显示名 |
|
||||
| file_path | string | 相对路径 |
|
||||
| size | int64 | 字节数 |
|
||||
| content_type | string | MIME 类型 |
|
||||
| created_at | string | 创建时间 |
|
||||
|
||||
**索引建议**:`{ site_id: 1 }`。
|
||||
|
||||
---
|
||||
|
||||
## 4. users(用户)
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| _id | ObjectID | 主键 |
|
||||
| username | string | 用户名 |
|
||||
| mobile | string | 手机号(可选) |
|
||||
| email | string | 邮箱 |
|
||||
| password | string | 密码哈希 |
|
||||
| role | string | 角色名 |
|
||||
| role_id | int | 9527=超级管理员,1=普通用户 |
|
||||
| is_beta | bool | 是否体验用户(可选) |
|
||||
| trial_start_date | string/date | 试用开始(可选) |
|
||||
| trial_end_date | string/date | 试用结束(可选) |
|
||||
| lastLogin | string | 最后登录(可选) |
|
||||
| llm | string | LLM 配置(可选) |
|
||||
|
||||
**索引建议**:`{ username: 1 }` 唯一,`{ mobile: 1 }` 可选。
|
||||
|
||||
---
|
||||
|
||||
## 5. workspaces(工作空间)
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| _id | ObjectID | 主键 |
|
||||
| name | string | 名称 |
|
||||
| user_id | string | 用户 ID |
|
||||
| created_at | string | 创建时间 |
|
||||
|
||||
**索引建议**:`{ user_id: 1 }`。
|
||||
|
||||
---
|
||||
|
||||
## 6. conversations(对话)
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| _id | ObjectID | 主键 |
|
||||
| title | string | 标题 |
|
||||
| user_id | string | 用户 ID |
|
||||
| workspace_id | string | 工作空间 ID |
|
||||
| created_at | string | 创建时间 |
|
||||
| updated_at | string | 更新时间 |
|
||||
|
||||
**索引建议**:`{ user_id: 1 }`,`{ workspace_id: 1 }`。
|
||||
|
||||
---
|
||||
|
||||
## 7. messages(消息,统计用)
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| _id | ObjectID | 主键 |
|
||||
| conversation_id | string | 对话 ID |
|
||||
| role | string | user / assistant / system |
|
||||
| content | string | 内容 |
|
||||
| created_at | string | 创建时间 |
|
||||
|
||||
**说明**:当前仅统计接口使用,若功能未实现可先建空集合。
|
||||
|
||||
---
|
||||
|
||||
## 8. files(文件,统计用)
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| _id | ObjectID | 主键 |
|
||||
| user_id | string | 用户 ID |
|
||||
| name | string | 文件名 |
|
||||
| file_path | string | 存储路径 |
|
||||
| size | int64 | 字节数 |
|
||||
| created_at | string | 创建时间 |
|
||||
|
||||
**说明**:当前仅统计接口使用,若功能未实现可先建空集合。
|
||||
|
||||
---
|
||||
|
||||
## 9. system_config(系统配置,按 _id 区分类型)
|
||||
|
||||
单集合,`_id` 为字符串键,不同键对应不同配置结构。
|
||||
|
||||
- ** _id: "payment"** — 支付配置
|
||||
- wechat: { app_id, mch_id, api_key, api_key_v3, enabled }
|
||||
- alipay: { app_id, private_key, alipay_public_key, enabled }
|
||||
|
||||
- **_id: "sms_platform"** — 短信配置
|
||||
- provider, access_key, secret_key, sign_name, template_id, enabled
|
||||
|
||||
**索引**:默认 _id 唯一即可。
|
||||
|
||||
---
|
||||
|
||||
## 使用方式
|
||||
|
||||
在项目根目录执行(需已安装 mongosh):
|
||||
|
||||
```bash
|
||||
mongosh "mongodb://localhost:27017" --file MongoDB/create_collections.js
|
||||
```
|
||||
|
||||
或进入 mongosh 后:
|
||||
|
||||
```js
|
||||
use("yxd-agent-testing")
|
||||
// 再粘贴 create_collections.js 中的创建与索引语句
|
||||
```
|
||||
84
MongoDB/create_collections.js
Normal file
84
MongoDB/create_collections.js
Normal file
@@ -0,0 +1,84 @@
|
||||
// 创建 yh_web 所需 MongoDB 集合及索引(mongosh 执行)
|
||||
// 用法: mongosh "mongodb://localhost:27017" --file MongoDB/create_collections.js
|
||||
// 或: mongosh "mongodb://localhost:27017" MongoDB/create_collections.js
|
||||
|
||||
const dbName = "yxd-agent-testing";
|
||||
const db = db.getSiblingDB(dbName);
|
||||
|
||||
print("使用数据库: " + dbName);
|
||||
|
||||
// 1. sites
|
||||
if (!db.getCollectionNames().includes("sites")) {
|
||||
db.createCollection("sites");
|
||||
print("已创建集合: sites");
|
||||
}
|
||||
db.sites.createIndex({ created_at: -1 }, { name: "idx_created_at", background: true });
|
||||
|
||||
// 2. pages
|
||||
if (!db.getCollectionNames().includes("pages")) {
|
||||
db.createCollection("pages");
|
||||
print("已创建集合: pages");
|
||||
}
|
||||
db.pages.createIndex(
|
||||
{ site_id: 1, slug: 1 },
|
||||
{ unique: true, name: "idx_site_slug", background: true }
|
||||
);
|
||||
|
||||
// 3. site_assets
|
||||
if (!db.getCollectionNames().includes("site_assets")) {
|
||||
db.createCollection("site_assets");
|
||||
print("已创建集合: site_assets");
|
||||
}
|
||||
db.site_assets.createIndex({ site_id: 1 }, { name: "idx_site_id", background: true });
|
||||
|
||||
// 4. users
|
||||
if (!db.getCollectionNames().includes("users")) {
|
||||
db.createCollection("users");
|
||||
print("已创建集合: users");
|
||||
}
|
||||
db.users.createIndex({ username: 1 }, { unique: true, name: "idx_username", background: true });
|
||||
db.users.createIndex({ mobile: 1 }, { name: "idx_mobile", background: true, sparse: true });
|
||||
|
||||
// 5. workspaces
|
||||
if (!db.getCollectionNames().includes("workspaces")) {
|
||||
db.createCollection("workspaces");
|
||||
print("已创建集合: workspaces");
|
||||
}
|
||||
db.workspaces.createIndex({ user_id: 1 }, { name: "idx_user_id", background: true });
|
||||
|
||||
// 6. conversations
|
||||
if (!db.getCollectionNames().includes("conversations")) {
|
||||
db.createCollection("conversations");
|
||||
print("已创建集合: conversations");
|
||||
}
|
||||
db.conversations.createIndex({ user_id: 1 }, { name: "idx_user_id", background: true });
|
||||
db.conversations.createIndex({ workspace_id: 1 }, { name: "idx_workspace_id", background: true });
|
||||
|
||||
// 7. messages(统计用,功能未实现也可先建)
|
||||
if (!db.getCollectionNames().includes("messages")) {
|
||||
db.createCollection("messages");
|
||||
print("已创建集合: messages");
|
||||
}
|
||||
db.messages.createIndex({ conversation_id: 1 }, { name: "idx_conversation_id", background: true });
|
||||
|
||||
// 8. files(统计用,功能未实现也可先建)
|
||||
if (!db.getCollectionNames().includes("files")) {
|
||||
db.createCollection("files");
|
||||
print("已创建集合: files");
|
||||
}
|
||||
db.files.createIndex({ user_id: 1 }, { name: "idx_user_id", background: true });
|
||||
|
||||
// 9. system_config(支付、短信等配置,_id 为字符串键)
|
||||
if (!db.getCollectionNames().includes("system_config")) {
|
||||
db.createCollection("system_config");
|
||||
print("已创建集合: system_config");
|
||||
}
|
||||
|
||||
// 10. role_permissions(角色权限:role_id -> permissions 数组)
|
||||
if (!db.getCollectionNames().includes("role_permissions")) {
|
||||
db.createCollection("role_permissions");
|
||||
print("已创建集合: role_permissions");
|
||||
}
|
||||
db.role_permissions.createIndex({ role_id: 1 }, { unique: true, name: "idx_role_id", background: true });
|
||||
|
||||
print("集合与索引处理完成。");
|
||||
Reference in New Issue
Block a user