docs: 更新项目架构与数据模型文档
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
# 数据库迁移策略
|
||||
|
||||
> 所属模块:[数据库切换支持](./概览.md)
|
||||
> 所属模块:[数据库支持](./概览.md)
|
||||
|
||||
---
|
||||
|
||||
## 1. 迁移命令
|
||||
## 1. 本地库迁移
|
||||
|
||||
### SQLite
|
||||
|
||||
```bash
|
||||
# 添加迁移
|
||||
dotnet ef migrations add InitialCreate --output-dir Migrations/SQLite
|
||||
dotnet ef migrations add InitialCreate --output-dir Migrations/SQLite \
|
||||
--context WctMinerDbContext --project src/Gpulse.WCT.DataAnalyzer.Core
|
||||
|
||||
# 应用迁移
|
||||
dotnet ef database update
|
||||
@@ -20,42 +21,43 @@ dotnet ef database update
|
||||
|
||||
```bash
|
||||
# 切换配置后添加迁移
|
||||
dotnet ef migrations add InitialCreate --output-dir Migrations/PostgreSQL -- --environment PostgreSQL
|
||||
|
||||
# 应用迁移
|
||||
dotnet ef database update -- --environment PostgreSQL
|
||||
dotnet ef migrations add InitialCreate --output-dir Migrations/PostgreSQL \
|
||||
--context WctMinerDbContext --project src/Gpulse.WCT.DataAnalyzer.Core \
|
||||
-- --environment Production
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. 切换步骤
|
||||
## 2. 发布库迁移
|
||||
|
||||
### 从 SQLite 切换到 PostgreSQL
|
||||
发布库的迁移需要使用 `ReleaseDbContext`:
|
||||
|
||||
| 步骤 | 操作 | 说明 |
|
||||
|------|------|------|
|
||||
| 1 | 修改配置 | `appsettings.json` 中 `Database:Type` 改为 `postgresql` |
|
||||
| 2 | 设置连接 | 配置 `Host`, `Port`, `Name`, `User`, `Password` |
|
||||
| 3 | 创建数据库 | `CREATE DATABASE wctminer;` |
|
||||
| 4 | 应用迁移 | `dotnet ef database update` |
|
||||
| 5 | 数据迁移 | 使用工具迁移 SQLite 数据到 PostgreSQL |
|
||||
```bash
|
||||
# 添加迁移
|
||||
dotnet ef migrations add InitialCreate --output-dir Migrations/Release \
|
||||
--context ReleaseDbContext --project src/Gpulse.WCT.DataAnalyzer.Core
|
||||
|
||||
# 应用迁移
|
||||
dotnet ef database update --context ReleaseDbContext
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. 配置文件示例
|
||||
|
||||
### SQLite (默认)
|
||||
### SQLite(默认双库)
|
||||
|
||||
```json
|
||||
{
|
||||
"Database": {
|
||||
"Type": "sqlite",
|
||||
"Path": "./data/database/wctminer.db"
|
||||
"LocalPath": "./data/database/local.db",
|
||||
"ReleasePath": "./data/database/release.db"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### PostgreSQL
|
||||
### PostgreSQL(双库独立)
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -63,9 +65,8 @@ dotnet ef database update -- --environment PostgreSQL
|
||||
"Type": "postgresql",
|
||||
"Host": "localhost",
|
||||
"Port": 5432,
|
||||
"Name": "wctminer",
|
||||
"User": "wctminer_user",
|
||||
"Password": "${DB_PASSWORD}"
|
||||
"LocalPath": "Server=localhost;Database=wct_local",
|
||||
"ReleasePath": "Server=db-server;Database=wct_charging_parameters"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -77,5 +78,11 @@ dotnet ef database update -- --environment PostgreSQL
|
||||
推荐使用 [pgloader](https://github.com/dimitri/pgloader) 迁移 SQLite 到 PostgreSQL:
|
||||
|
||||
```bash
|
||||
pgloader ./data/database/wctminer.db postgresql://user:password@localhost:5432/wctminer
|
||||
```
|
||||
# 本地库
|
||||
pgloader ./data/database/local.db postgresql://user:password@localhost:5432/wct_local
|
||||
|
||||
# 发布库
|
||||
pgloader ./data/database/release.db postgresql://user:password@db-server:5432/wct_charging_parameters
|
||||
```
|
||||
|
||||
两个数据库独立迁移,不共享迁移历史。
|
||||
Reference in New Issue
Block a user