数据层可插拔(SQLite/MariaDB) + 后端 services 骨架

- database.ts 改为按 DB_TYPE 切换 SQLite / MariaDB(mysql2),sqlite3 按需动态导入
- index.ts 改为初始化数据库后再监听端口
- 新增 AuthService / HealthService / AnalysisService / GarminService
- 新增 .gitignore、server/.env(忽略) 与 .env.example
- README 增加数据库配置说明;package.json 增加 mysql2/@types
This commit is contained in:
ericwyuan
2026-08-23 11:58:07 +08:00
parent d73405decb
commit 6b05d04773
11 changed files with 22362 additions and 122 deletions

View File

@@ -75,6 +75,25 @@ JWT_SECRET=your_jwt_secret_here
CORS_ORIGIN=http://localhost:3000
```
### 数据库SQLite / MariaDB 可插拔
数据层通过 `DB_TYPE` 环境变量切换后端,**业务代码无需改动**
- **SQLite默认本地开发**:零配置,由 `DATABASE_PATH` 指定文件位置。
- **MariaDB生产运行在 NAS 上)**:经 `mysql2` 连接,优先走 socket`MARIADB_SOCKET`),也可用 `MARIADB_HOST` + `MARIADB_PORT`
生产使用 NAS 上的独立库 `garmin_health_lab`(与 `sentinel_home_ai` 隔离)。完整配置见 `server/.env.example`
```env
DB_TYPE=mariadb
MARIADB_SOCKET=/run/mysqld/mysqld10.sock
MARIADB_USER=root
MARIADB_PASSWORD=your_nas_mariadb_root_password
MARIADB_DATABASE=garmin_health_lab
```
> 复制 `server/.env.example` 为 `server/.env` 并填入真实值;`.env` 已被 `.gitignore` 忽略,不会进入版本库。
### 启动开发服务器
```bash