- 重命名 log_file 为 test_scenario(测试场景) - 拆分维度表:tx_panel、tx_hardware、tx_software、rx_type - 采用星型模型设计,消除数据冗余 - 为所有表添加软删除字段 is_deleted - 更新关系说明,包含全局查询过滤器配置 - 更新 ER 图和查询示例 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1.5 KiB
1.5 KiB
数据库迁移策略
所属模块:数据库切换支持
1. 迁移命令
SQLite
# 添加迁移
dotnet ef migrations add InitialCreate --output-dir Migrations/SQLite
# 应用迁移
dotnet ef database update
PostgreSQL
# 切换配置后添加迁移
dotnet ef migrations add InitialCreate --output-dir Migrations/PostgreSQL -- --environment PostgreSQL
# 应用迁移
dotnet ef database update -- --environment PostgreSQL
2. 切换步骤
从 SQLite 切换到 PostgreSQL
| 步骤 | 操作 | 说明 |
|---|---|---|
| 1 | 修改配置 | appsettings.json 中 Database:Type 改为 postgresql |
| 2 | 设置连接 | 配置 Host, Port, Name, User, Password |
| 3 | 创建数据库 | CREATE DATABASE wctminer; |
| 4 | 应用迁移 | dotnet ef database update |
| 5 | 数据迁移 | 使用工具迁移 SQLite 数据到 PostgreSQL |
3. 配置文件示例
SQLite (默认)
{
"Database": {
"Type": "sqlite",
"Path": "./data/database/wctminer.db"
}
}
PostgreSQL
{
"Database": {
"Type": "postgresql",
"Host": "localhost",
"Port": 5432,
"Name": "wctminer",
"User": "wctminer_user",
"Password": "${DB_PASSWORD}"
}
}
4. 数据迁移工具
推荐使用 pgloader 迁移 SQLite 到 PostgreSQL:
pgloader ./data/database/wctminer.db postgresql://user:password@localhost:5432/wctminer