引入 SQLite 数据库(Drizzle ORM + bun:sqlite),实现项目 CRUD 与归档/恢复/删除 生命周期管理,新增项目管理前端页面,migration 嵌入单文件构建产物保持部署体验。 - src/server/db: schema、connection、migration 执行器、项目数据访问层 - src/server/routes/projects: 7 个 API 端点(列表/创建/详情/更新/归档/恢复/删除) - src/web: 项目管理页面(TDesign Table/Tabs/Dialog/Form),TanStack Query hooks - scripts: 构建时嵌入 migration SQL,开发期独立 generate-migrations-data 脚本 - tests: 60 个后端测试 + 27 个前端测试,覆盖 DB/migration/API/路由/页面 - docs: 更新架构、后端、发布、配置、部署、使用文档
63 lines
2.2 KiB
Markdown
63 lines
2.2 KiB
Markdown
# 生产部署
|
||
|
||
本文档说明如何构建和运行生产环境的应用。
|
||
|
||
## 生产构建和运行
|
||
|
||
```bash
|
||
bun run build
|
||
./dist/alfred config.yaml
|
||
```
|
||
|
||
启动后:
|
||
|
||
| 地址 | 行为 |
|
||
| ------------------------------ | ------------------- |
|
||
| http://127.0.0.1:3000/ | 返回前端 SPA |
|
||
| http://127.0.0.1:3000/api/meta | 返回应用元信息 JSON |
|
||
| http://127.0.0.1:3000/health | 返回健康检查 |
|
||
|
||
## 构建流程
|
||
|
||
scripts/build.ts 执行三步流水线:
|
||
|
||
```text
|
||
1. Vite build -> dist/web/(前端静态资源,含 code splitting)
|
||
2. Code generation -> .build/static-assets.ts + .build/server-entry.ts(含版本号字面量注入)
|
||
3. Bun compile -> dist/alfred(单可执行文件)
|
||
```
|
||
|
||
- Vite 构建前端资源到 dist/web/,自动 code splitting(vendor-react、vendor-tdesign、vendor-chart)
|
||
- Code generation 扫描 dist/web/ 生成 static-assets.ts,读取 drizzle/\*.sql 生成 migrations-data.ts,生成 server-entry.ts 串联入口
|
||
- migrations-data.ts 将 migration SQL 嵌入 binary,生产部署无需额外携带 migration 文件
|
||
- Bun compile 以 .build/server-entry.ts 为入口编译最终可执行文件
|
||
- .build/ 临时目录在构建完成后自动清理
|
||
|
||
## 运行时数据存储
|
||
|
||
- 应用使用 SQLite 存储数据,数据库文件位于 `<dataDir>/alfred.db`
|
||
- 启动时自动应用 pending database migrations(无需手动迁移)
|
||
- 每次 migration 执行前自动备份现有数据库到 `<dataDir>/backups/`
|
||
- 数据库文件使用 WAL 模式,支持并发读写
|
||
|
||
## 产物
|
||
|
||
| 产物 | 用途 |
|
||
| ----------- | ---------------------------------------- |
|
||
| dist/alfred | 生产可执行文件(含前端资源,单文件部署) |
|
||
| dist/web/ | Vite 构建的前端资源(构建中间产物) |
|
||
|
||
## 构建参数
|
||
|
||
| 环境变量 | 说明 |
|
||
| ------------------------- | ------------------------------------ |
|
||
| BUN_TARGET / BUILD_TARGET | 交叉编译目标平台(如 bun-linux-x64) |
|
||
|
||
## 清理
|
||
|
||
```bash
|
||
bun run clean
|
||
```
|
||
|
||
清理 dist/ 构建产物和 .build/ 临时文件。
|