移除历史状态归一化及相关遗留逻辑
- 移除 LegacyStatusNormalizationMigrator,仅保留 AreaLayoutModeDefaultMigrator - 删除 WmsDispatchStatus 枚举、常量和全局 using - 统一所有 DbContext 注入为 MiGuDbContext,移除 PlatformDbContext - 服务实体操作统一用 IEditableRepository<T>,移除本地实现 - 移除 WmsService 的 MigrateLegacyAsync 方法 - 精简接口模型,移除部分字段和请求体 - 前端保存容器时 status 字段取自已有数据,移除写死默认值 - 更新文档,去除旧说明,统一数据库初始化流程
This commit is contained in:
@@ -29,35 +29,16 @@ public sealed class SimpleFieldsCarTypeBackfillMigrator : IDataMigrator
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把库内旧状态字符串刷成规范枚举名(Available/Idle→Empty,Occupied→FullContainer)。
|
||||
/// 仅 Sqlite 表名/列名;绕过枚举 HasConversion(ExecuteUpdate + 字符串比较会 InvalidCast)。
|
||||
/// </summary>
|
||||
public sealed class LegacyStatusNormalizationMigrator : IDataMigrator
|
||||
/// <summary>库区 LayoutMode 空值补 Flat(raw UPDATE,避开枚举 converter)。</summary>
|
||||
public sealed class AreaLayoutModeDefaultMigrator : IDataMigrator
|
||||
{
|
||||
public int Order => 15;
|
||||
public string Name => "Wms.LegacyStatusNormalization";
|
||||
public string Name => "Wms.AreaLayoutModeDefault";
|
||||
|
||||
public async Task MigrateAsync(DbContext db, CancellationToken ct = default)
|
||||
{
|
||||
if (db is not MiGuDbContext) return;
|
||||
|
||||
await db.Database.ExecuteSqlRawAsync(
|
||||
"""
|
||||
UPDATE wms_storages
|
||||
SET Status = 'Empty'
|
||||
WHERE Status IN ('Available', 'Idle')
|
||||
""",
|
||||
ct);
|
||||
|
||||
await db.Database.ExecuteSqlRawAsync(
|
||||
"""
|
||||
UPDATE wms_storages
|
||||
SET Status = 'FullContainer'
|
||||
WHERE Status = 'Occupied'
|
||||
""",
|
||||
ct);
|
||||
|
||||
await db.Database.ExecuteSqlRawAsync(
|
||||
"""
|
||||
UPDATE wms_areas
|
||||
@@ -98,7 +79,7 @@ public static class DataMigratorRegistration
|
||||
public static IServiceCollection AddMiGuDataMigrators(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IDataMigrator, SimpleFieldsCarTypeBackfillMigrator>();
|
||||
services.AddSingleton<IDataMigrator, LegacyStatusNormalizationMigrator>();
|
||||
services.AddSingleton<IDataMigrator, AreaLayoutModeDefaultMigrator>();
|
||||
services.AddSingleton<IDataMigrator, ContainerLocationStorageIdBackfillMigrator>();
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -96,9 +96,3 @@ public static class WmsReservationStatuses
|
||||
public const WmsReservationStatus Released = WmsReservationStatus.Released;
|
||||
public const WmsReservationStatus Expired = WmsReservationStatus.Expired;
|
||||
}
|
||||
|
||||
public static class WmsDispatchStatuses
|
||||
{
|
||||
public const WmsDispatchStatus Dispatched = WmsDispatchStatus.Dispatched;
|
||||
public const WmsDispatchStatus Failed = WmsDispatchStatus.Failed;
|
||||
}
|
||||
|
||||
@@ -27,9 +27,3 @@ public enum WmsReservationStatus
|
||||
Released,
|
||||
Expired
|
||||
}
|
||||
|
||||
public enum WmsDispatchStatus
|
||||
{
|
||||
Dispatched,
|
||||
Failed
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ namespace MiGu.DB.Domains.Wms;
|
||||
|
||||
/// <summary>
|
||||
/// WMS 状态/类型枚举。列以字符串存储(见约定 HasConversion<string>),成员名即库内合法值。
|
||||
/// 旧别名(Available/Idle/Occupied 等)不进入枚举,由 LegacyStatusNormalizationMigrator 刷库。
|
||||
/// </summary>
|
||||
public enum AreaLayoutMode
|
||||
{
|
||||
|
||||
@@ -33,17 +33,8 @@ public static class StorageStatuses
|
||||
public static readonly HashSet<StorageStatus> All = new()
|
||||
{ Empty, EmptyContainer, FullContainer, Disabled };
|
||||
|
||||
/// <summary>
|
||||
/// 写路径归一:兼容历史字符串 Available/Idle/Occupied。
|
||||
/// 库内残留旧值须靠 DataMigrator 刷掉,不能依赖 converter 读侧归一(WHERE 会漏行)。
|
||||
/// </summary>
|
||||
public static StorageStatus Normalize(string? status) => status switch
|
||||
{
|
||||
"Available" or "Idle" => Empty,
|
||||
"Occupied" => FullContainer,
|
||||
_ when Enum.TryParse<StorageStatus>(status, true, out var e) && All.Contains(e) => e,
|
||||
_ => Empty
|
||||
};
|
||||
public static StorageStatus ParseOr(string? value, StorageStatus fallback = StorageStatus.Empty) =>
|
||||
Enum.TryParse<StorageStatus>(value, true, out var e) && All.Contains(e) ? e : fallback;
|
||||
}
|
||||
|
||||
public static class ContainerStatuses
|
||||
|
||||
@@ -94,7 +94,7 @@ dotnet ef migrations add <迁移名称> `
|
||||
|
||||
### 3.4 应用到本地库
|
||||
|
||||
启动 `MiGu.Server` 即可(`EnsurePlatformDatabaseAsync` → `MigrateMiGuDbAsync`),或:
|
||||
启动 `MiGu.Server` 即可(`Program.cs` 直接调用 `MigrateMiGuDbAsync`),或:
|
||||
|
||||
```powershell
|
||||
dotnet ef database update `
|
||||
@@ -151,7 +151,7 @@ dotnet ef database update <目标迁移名> `
|
||||
|
||||
→ **[MiGu.Server/README.md · 数据库启动流程](../MiGu.Server/README.md#数据库启动流程)**
|
||||
|
||||
摘要:`EnsurePlatformDatabaseAsync` → `MigrateMiGuDbAsync`;`Database:SchemaMode` 为 `EnsureCreated` 或 `Migrate`;之后按需跑 `IDataMigrator`。
|
||||
摘要:`MigrateMiGuDbAsync`;`Database:SchemaMode` 为 `EnsureCreated` 或 `Migrate`;之后按需跑 `IDataMigrator`。
|
||||
|
||||
**Migrate 基线:** 已有表、无 History 时,会把**全部** pending Migration 写入 `__EFMigrationsHistory`(假定 EnsureCreated 库已对齐模型 tip)。发版前若开发期改过模型,须先 `migrations add` 再切 `Migrate`。
|
||||
|
||||
@@ -165,7 +165,7 @@ dotnet ef database update <目标迁移名> `
|
||||
| 刷旧枚举字符串、回填列 | 新增 `IDataMigrator`,注册到 `AddMiGuDataMigrators` |
|
||||
| 开发机整库清空重来 | 删 `data/platform.db*` 后启动(等同空库 Migrate);**不要**在生产用 EnsureDeleted |
|
||||
|
||||
注意:带 `HasConversion` 的枚举列,用 `ExecuteUpdate` + 原始字符串比较可能触发转换异常;旧值刷库需绕过 converter(参见 `LegacyStatusNormalizationMigrator`)。
|
||||
注意:带 `HasConversion` 的枚举列,用 `ExecuteUpdate` + 原始字符串比较可能触发转换异常;空 LayoutMode 等特例用 raw UPDATE(参见 `AreaLayoutModeDefaultMigrator`)。
|
||||
|
||||
---
|
||||
|
||||
|
||||
+1
-2
@@ -17,7 +17,7 @@
|
||||
|
||||
```csharp
|
||||
builder.Services.AddPlatformPersistence(builder.Configuration); // 内部 AddMiGuDb
|
||||
await app.Services.EnsurePlatformDatabaseAsync(); // 内部 MigrateMiGuDbAsync
|
||||
await app.Services.MigrateMiGuDbAsync();
|
||||
```
|
||||
|
||||
**启动流程、SchemaMode、开发/发版配置说明见 [MiGu.Server/README.md · 数据库启动流程](../MiGu.Server/README.md#数据库启动流程)。**
|
||||
@@ -27,7 +27,6 @@ await app.Services.EnsurePlatformDatabaseAsync(); // 内部 Migrat
|
||||
## 实体与枚举
|
||||
|
||||
- 业务状态字段为 **enum**,约定自动 `HasConversion<string>()`(严格 1:1,不做读侧归一)。
|
||||
- 旧库值(如 `Available`/`Idle`)由 `LegacyStatusNormalizationMigrator` 一次性刷成规范名。
|
||||
- `Version` 为乐观并发令牌;软删走全局 `HasQueryFilter`。
|
||||
- 复数辅助类(`StorageStatuses`、`LocationKinds`…)负责 API 字符串解析与集合校验。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user