Skip to content

【迁移计划】将 MongoDB 数据库迁移至 MySQL (2026.3.30) #7

@Ink-dark

Description

@Ink-dark

当前 HalloChat 项目使用 MongoDB (Mongoose 7.5.0) 作为数据库。经过技术评估,计划将数据库从 MongoDB 迁移到 MySQL,以提升系统稳定性与兼容性。

迁移目标

  • 将现有 MongoDB 数据库迁移到 MySQL
  • 修改数据模型适配 MySQL (SQL 关系型数据库)
  • 更新项目依赖 (移除 mongoose,安装 mysql2)
  • 修改配置文件中的数据库连接

涉及文件

根据仓库分析,主要涉及以下文件需要修改:

序号 文件路径 说明
1 server/config/conf.json 数据库连接配置
2 server/package.json 修改依赖
3 server/src/models/user.js 用户模型
4 server/src/models/channel.js 频道模型
5 server/src/models/group.js 群组模型
6 server/src/models/message.js 消息模型
7 server/mongodb/index.js MongoDB 连接
8 server/.env.example 环境变量配置

迁移方案要点

  1. 依赖更换: npm install mysql2 替换 mongoose
  2. 配置更新: MONGO_URIMYSQL_URI
  3. 模型重写: Mongoose Schema → SQL 表结构
  4. 数据迁移: 导出 MongoDB 数据 → 导入 MySQL

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions