## 主要变更 ### Infrastructure 层重构 - `PlatformDbContext`: 构造函数改为接受泛型 `DbContextOptions`,支持派生上下文 - `TenantStore<TContext>`: 泛型化实现,支持不同的数据库上下文 - `Extensions`: 新增 `AddPlatformCore<TContext>` 扩展方法,简化服务注册 ### 依赖调整 - 移除 Npgsql.EntityFrameworkCore.PostgreSQL 直接依赖,由使用方自行决定数据库提供程序 ### CI/CD 集成 - 新增 `.gitea/workflows/publish-nuget.yml` Gitea Actions 工作流 - 新增 `push-platform-nuget.sh` 脚本,支持: - 从 git tag 自动获取版本号 - HTTP/HTTPS 双模式支持 - 独立 NuGet 配置文件 - CI/CD 友好的环境变量配置 ### 其他 - `NuGet.Config`: 新增 NuGet 配置文件 - `Fengling.Platform.Domain`: 添加 Items 文件夹占位
85 lines
3.4 KiB
C#
85 lines
3.4 KiB
C#
using Fengling.Platform.Domain.AggregatesModel.RoleAggregate;
|
|
using Fengling.Platform.Domain.AggregatesModel.TenantAggregate;
|
|
using Fengling.Platform.Domain.AggregatesModel.UserAggregate;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
namespace Fengling.Platform.Infrastructure;
|
|
|
|
|
|
public class PlatformDbContext(DbContextOptions options)
|
|
: IdentityDbContext<ApplicationUser, ApplicationRole, long>(options)
|
|
{
|
|
public DbSet<Tenant> Tenants => Set<Tenant>();
|
|
public DbSet<AccessLog> AccessLogs => Set<AccessLog>();
|
|
public DbSet<AuditLog> AuditLogs => Set<AuditLog>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
if (modelBuilder is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(modelBuilder));
|
|
}
|
|
|
|
modelBuilder.Entity<ApplicationUser>(entity =>
|
|
{
|
|
entity.Property(e => e.PhoneNumber).HasMaxLength(20);
|
|
entity.HasIndex(e => e.PhoneNumber).IsUnique();
|
|
|
|
entity.OwnsOne(e => e.TenantInfo, navigationBuilder =>
|
|
{
|
|
navigationBuilder.Property(t => t.TenantCode).HasColumnName("TenantCode");
|
|
navigationBuilder.Property(t => t.TenantId).HasColumnName("TenantId");
|
|
navigationBuilder.Property(t => t.TenantName).HasColumnName("TenantName");
|
|
navigationBuilder.WithOwner();
|
|
});
|
|
});
|
|
|
|
modelBuilder.Entity<ApplicationRole>(entity =>
|
|
{
|
|
entity.Property(e => e.Description).HasMaxLength(200);
|
|
});
|
|
|
|
modelBuilder.Entity<AccessLog>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.HasIndex(e => e.CreatedAt);
|
|
entity.HasIndex(e => e.UserName);
|
|
entity.HasIndex(e => e.TenantId);
|
|
entity.HasIndex(e => e.Action);
|
|
entity.HasIndex(e => e.Status);
|
|
entity.Property(e => e.UserName).HasMaxLength(50);
|
|
entity.Property(e => e.TenantId).HasMaxLength(50);
|
|
entity.Property(e => e.Action).HasMaxLength(20);
|
|
entity.Property(e => e.Resource).HasMaxLength(200);
|
|
entity.Property(e => e.Method).HasMaxLength(10);
|
|
entity.Property(e => e.IpAddress).HasMaxLength(50);
|
|
entity.Property(e => e.UserAgent).HasMaxLength(500);
|
|
entity.Property(e => e.Status).HasMaxLength(20);
|
|
});
|
|
|
|
modelBuilder.Entity<AuditLog>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.HasIndex(e => e.CreatedAt);
|
|
entity.HasIndex(e => e.Operator);
|
|
entity.HasIndex(e => e.TenantId);
|
|
entity.HasIndex(e => e.Operation);
|
|
entity.HasIndex(e => e.Action);
|
|
entity.Property(e => e.Operator).HasMaxLength(50);
|
|
entity.Property(e => e.TenantId).HasMaxLength(50);
|
|
entity.Property(e => e.Operation).HasMaxLength(20);
|
|
entity.Property(e => e.Action).HasMaxLength(20);
|
|
entity.Property(e => e.TargetType).HasMaxLength(50);
|
|
entity.Property(e => e.TargetName).HasMaxLength(100);
|
|
entity.Property(e => e.IpAddress).HasMaxLength(50);
|
|
entity.Property(e => e.Description).HasMaxLength(500);
|
|
entity.Property(e => e.Status).HasMaxLength(20);
|
|
});
|
|
|
|
modelBuilder.ApplyConfigurationsFromAssembly(typeof(PlatformDbContext).Assembly);
|
|
base.OnModelCreating(modelBuilder);
|
|
}
|
|
}
|