From f8677deeeed80a63c019e3bea15f21f9947a688d Mon Sep 17 00:00:00 2001 From: xiangning Date: Fri, 3 Jul 2026 11:14:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor(workflow):=20=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E6=97=B6=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87=E5=B7=A5=E5=8E=82=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除对 Microsoft.Extensions.Configuration 的依赖 - 删除复杂的 appsettings.json 配置文件查找逻辑 - 将连接字符串改为硬编码方式 - 更新数据库端口为 15432 并修改密码为 dev - 精简注释说明 feat(im): 添加 MongoDB Entities 包支持 - 引入 MongoDB.Entities 25.1.0 版本依赖 - 升级 MongoDB.Driver 从 3.4. --- .../Infrastructure/IM.Infrastructure.csproj | 3 ++- .../WorkflowDbContextDesignTimeFactory.cs | 26 ++----------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/modules/im/Infrastructure/IM.Infrastructure.csproj b/src/modules/im/Infrastructure/IM.Infrastructure.csproj index 5a7dbf6..cef3259 100644 --- a/src/modules/im/Infrastructure/IM.Infrastructure.csproj +++ b/src/modules/im/Infrastructure/IM.Infrastructure.csproj @@ -7,6 +7,7 @@ + @@ -14,7 +15,7 @@ all - + diff --git a/src/modules/workflow/Infrastructure/Persistence/WorkflowDbContextDesignTimeFactory.cs b/src/modules/workflow/Infrastructure/Persistence/WorkflowDbContextDesignTimeFactory.cs index 246e6ca..29072e6 100644 --- a/src/modules/workflow/Infrastructure/Persistence/WorkflowDbContextDesignTimeFactory.cs +++ b/src/modules/workflow/Infrastructure/Persistence/WorkflowDbContextDesignTimeFactory.cs @@ -1,39 +1,17 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; -using Microsoft.Extensions.Configuration; namespace Workflow.Infrastructure.Persistence; -/// -/// EF Core 设计时工厂,供 dotnet ef migrations 命令使用。 -/// 关键:必须启用 UseSnakeCaseNamingConvention(与运行时一致),否则迁移会用 PascalCase 列名。 -/// +/// EF Core 设计时工厂。硬编码连接串,不依赖 appsettings 路径。 public class WorkflowDbContextDesignTimeFactory : IDesignTimeDbContextFactory { public WorkflowDbContext CreateDbContext(string[] args) { - // 向上查找 Api 项目的 appsettings.json(兼容不同工作目录) - var basePath = Path.Combine(Directory.GetCurrentDirectory(), "..", "Workflow.Api"); - if (!Directory.Exists(basePath)) - { - // 如果从 Infrastructure 目录运行,尝试另一种路径 - basePath = Path.Combine(Directory.GetCurrentDirectory(), "..", "Api"); - } - - var config = new ConfigurationBuilder() - .SetBasePath(basePath) - .AddJsonFile("appsettings.json", optional: true) - .Build(); - - var connectionString = config.GetConnectionString("Default") - ?? config.GetConnectionString("Workflow") - ?? "Host=localhost;Port=5432;Database=workflow;Username=rag;Password=REDACTED_DEV_PASSWORD"; - var options = new DbContextOptionsBuilder() - .UseNpgsql(connectionString) + .UseNpgsql("Host=localhost;Port=15432;Database=workflow;Username=rag;Password=dev") .UseSnakeCaseNamingConvention() .Options; - return new WorkflowDbContext(options); } }