57e8cb3f4b
Each DbContext now explicitly configures its migration history table to use the schema-qualified name pattern [schemaName].[_Migrations]: - [cvMatcher].[_Migrations] for CvMatcherDbContext - [emailApi].[_Migrations] for EmailApiDbContext - [cvSearch].[_Migrations] for CvSearchDbContext - [rag].[_Migrations] for RagDbContext - [myAi].[_Migrations] for MyAiDbContext This is done via OnConfiguring() with UseSqlServer().MigrationsHistoryTable(name, schema). Removed incorrect rename migrations that were created due to misunderstanding of the proper EF Core configuration approach. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
using EmailApi.Data.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EmailApi.Data;
|
|
|
|
public sealed class EmailApiDbContext : DbContext
|
|
{
|
|
public const string SchemaName = "emailApi";
|
|
public const string MigrationTableName = "_Migrations";
|
|
|
|
public EmailApiDbContext(DbContextOptions<EmailApiDbContext> options) : base(options) { }
|
|
|
|
public DbSet<EmailTemplateEntity> EmailTemplates => Set<EmailTemplateEntity>();
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
base.OnConfiguring(optionsBuilder);
|
|
// Configure migration history table to use schema-qualified name: [emailApi].[_Migrations]
|
|
optionsBuilder.UseSqlServer(x => x.MigrationsHistoryTable(MigrationTableName, SchemaName));
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.HasDefaultSchema(SchemaName);
|
|
|
|
modelBuilder.Entity<EmailTemplateEntity>(entity =>
|
|
{
|
|
entity.ToTable("EmailTemplates");
|
|
entity.HasKey(x => new { x.Key, x.Language });
|
|
entity.Property(x => x.Key).HasMaxLength(128);
|
|
entity.Property(x => x.Language).HasMaxLength(8);
|
|
entity.Property(x => x.Value).IsRequired();
|
|
entity.Property(x => x.Description).HasMaxLength(500).HasDefaultValue(string.Empty);
|
|
entity.Property(x => x.UpdatedAt).HasDefaultValueSql("SYSUTCDATETIME()");
|
|
entity.Property(x => x.OperatorCopy).HasMaxLength(256).HasDefaultValue(string.Empty);
|
|
});
|
|
}
|
|
}
|