487924e345
- Move IRagRepository, EfRagRepository, and VectorSerializer from rag-api/Data to rag-data/Repositories - Add rag-api-models ProjectReference to rag-data.csproj for model type availability - Delete rag-api/Data folder (no longer needed; all data access is now in rag-data) - This aligns RAG with email-api and other services: all data code in the data project Pattern: rag-api (API logic) → rag-data (repository, EF entities, migrations) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
70 lines
3.2 KiB
C#
70 lines
3.2 KiB
C#
using CvSearch.Data.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CvSearch.Data;
|
|
|
|
public sealed class CvSearchDbContext : DbContext
|
|
{
|
|
public const string SchemaName = MigrationConstants.SchemaName;
|
|
public const string MigrationTableName = MigrationConstants.MigrationTableName;
|
|
|
|
public CvSearchDbContext(DbContextOptions<CvSearchDbContext> options) : base(options) { }
|
|
|
|
public DbSet<JobSearchTokenEntity> JobSearchTokens => Set<JobSearchTokenEntity>();
|
|
public DbSet<JobSearchSessionEntity> JobSearchSessions => Set<JobSearchSessionEntity>();
|
|
public DbSet<JobSearchResultEntity> JobSearchResults => Set<JobSearchResultEntity>();
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
base.OnConfiguring(optionsBuilder);
|
|
// Configure migration history table to use schema-qualified name: [cvSearch].[_Migrations]
|
|
optionsBuilder.UseSqlServer(x => x.MigrationsHistoryTable(MigrationTableName, SchemaName));
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.HasDefaultSchema(SchemaName);
|
|
|
|
modelBuilder.Entity<JobSearchTokenEntity>(entity =>
|
|
{
|
|
entity.ToTable("JobSearchTokens");
|
|
entity.HasKey(x => x.Id);
|
|
entity.Property(x => x.Id).HasMaxLength(64);
|
|
entity.Property(x => x.CvDocumentId).HasMaxLength(64).IsRequired();
|
|
entity.Property(x => x.Email).HasMaxLength(256).IsRequired();
|
|
entity.Property(x => x.Language).HasMaxLength(8).HasDefaultValue("en").IsRequired();
|
|
entity.Property(x => x.Used).HasDefaultValue(false);
|
|
entity.Property(x => x.CreatedAt).HasDefaultValueSql("SYSUTCDATETIME()");
|
|
});
|
|
|
|
modelBuilder.Entity<JobSearchSessionEntity>(entity =>
|
|
{
|
|
entity.ToTable("JobSearchSessions");
|
|
entity.HasKey(x => x.Id);
|
|
entity.Property(x => x.Id).HasMaxLength(64);
|
|
entity.Property(x => x.TokenId).HasMaxLength(64).IsRequired();
|
|
entity.Property(x => x.CvDocumentId).HasMaxLength(64).IsRequired();
|
|
entity.Property(x => x.Email).HasMaxLength(256).IsRequired();
|
|
entity.Property(x => x.Status).HasMaxLength(32).IsRequired();
|
|
entity.Property(x => x.Keywords).HasMaxLength(1000);
|
|
entity.Property(x => x.ProviderConfigJson).IsRequired(false);
|
|
entity.Property(x => x.Language).HasMaxLength(8).HasDefaultValue("en").IsRequired();
|
|
entity.Property(x => x.CreatedAt).HasDefaultValueSql("SYSUTCDATETIME()");
|
|
entity.HasIndex(x => x.Status);
|
|
});
|
|
|
|
modelBuilder.Entity<JobSearchResultEntity>(entity =>
|
|
{
|
|
entity.ToTable("JobSearchResults");
|
|
entity.HasKey(x => x.Id);
|
|
entity.Property(x => x.Id).HasMaxLength(64);
|
|
entity.Property(x => x.SessionId).HasMaxLength(64).IsRequired();
|
|
entity.Property(x => x.ProviderName).HasMaxLength(128);
|
|
entity.Property(x => x.JobUrl).HasMaxLength(2048);
|
|
entity.Property(x => x.JobTitle).HasMaxLength(512);
|
|
entity.Property(x => x.CreatedAt).HasDefaultValueSql("SYSUTCDATETIME()");
|
|
entity.HasIndex(x => x.SessionId);
|
|
});
|
|
}
|
|
}
|