42 lines
2.0 KiB
C#
42 lines
2.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||
using RAG.Domain.Entities;
|
||
|
||
namespace RAG.Infrastructure.Persistence.Configurations;
|
||
|
||
public class DocumentConfiguration : IEntityTypeConfiguration<Document>
|
||
{
|
||
public void Configure(EntityTypeBuilder<Document> builder)
|
||
{
|
||
builder.ToTable("documents");
|
||
builder.HasKey(d => d.Id);
|
||
builder.Property(d => d.Id).ValueGeneratedNever().HasComment("文档ID");
|
||
|
||
builder.Property(d => d.KnowledgeBaseId).HasComment("所属知识库ID");
|
||
builder.Property(d => d.Title).HasMaxLength(500).IsRequired().HasComment("文档标题");
|
||
builder.Property(d => d.FileName).HasMaxLength(500).IsRequired().HasComment("原始文件名");
|
||
builder.Property(d => d.FilePath).HasMaxLength(1000).IsRequired().HasComment("文件存储路径");
|
||
builder.Property(d => d.FileSize).HasComment("文件大小(字节)");
|
||
builder.Property(d => d.ContentType).HasMaxLength(100).IsRequired().HasComment("文件MIME类型");
|
||
builder.Property(d => d.ChunkCount).HasComment("分块数量");
|
||
builder.Property(d => d.Status).HasComment("文档状态:Pending=0, Processing=1, Completed=2, Failed=3");
|
||
|
||
// IAuditable
|
||
builder.Property(d => d.CreatedBy).HasMaxLength(100).HasComment("创建人");
|
||
builder.Property(d => d.CreatedAt).HasComment("创建时间");
|
||
builder.Property(d => d.UpdatedBy).HasMaxLength(100).HasComment("更新人");
|
||
builder.Property(d => d.UpdatedAt).HasComment("更新时间");
|
||
|
||
// ISoftDelete
|
||
builder.Property(d => d.IsDeleted).HasDefaultValue(false).HasComment("是否已软删除");
|
||
|
||
// IHasOperatorIP
|
||
builder.Property(d => d.OperatorIP).HasMaxLength(50).HasComment("操作者IP地址");
|
||
|
||
builder.HasMany(d => d.Chunks)
|
||
.WithOne(c => c.Document)
|
||
.HasForeignKey(c => c.DocumentId)
|
||
.OnDelete(DeleteBehavior.Cascade);
|
||
}
|
||
}
|