fix: Configure EF Core migration history tables with schema-qualified names
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>
This commit is contained in:
@@ -16,6 +16,13 @@ public sealed class CvMatcherDbContext : DbContext
|
|||||||
public DbSet<CvMatcherChatCacheEntity> CvMatcherChatCache => Set<CvMatcherChatCacheEntity>();
|
public DbSet<CvMatcherChatCacheEntity> CvMatcherChatCache => Set<CvMatcherChatCacheEntity>();
|
||||||
public DbSet<AiPromptEntity> AiPrompts => Set<AiPromptEntity>();
|
public DbSet<AiPromptEntity> AiPrompts => Set<AiPromptEntity>();
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
// Configure migration history table to use schema-qualified name: [cvMatcher].[_Migrations]
|
||||||
|
optionsBuilder.UseSqlServer(x => x.MigrationsHistoryTable(MigrationTableName, SchemaName));
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.HasDefaultSchema(SchemaName);
|
modelBuilder.HasDefaultSchema(SchemaName);
|
||||||
|
|||||||
@@ -14,6 +14,13 @@ public sealed class CvSearchDbContext : DbContext
|
|||||||
public DbSet<JobSearchSessionEntity> JobSearchSessions => Set<JobSearchSessionEntity>();
|
public DbSet<JobSearchSessionEntity> JobSearchSessions => Set<JobSearchSessionEntity>();
|
||||||
public DbSet<JobSearchResultEntity> JobSearchResults => Set<JobSearchResultEntity>();
|
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)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.HasDefaultSchema(SchemaName);
|
modelBuilder.HasDefaultSchema(SchemaName);
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ public sealed class EmailApiDbContext : DbContext
|
|||||||
|
|
||||||
public DbSet<EmailTemplateEntity> EmailTemplates => Set<EmailTemplateEntity>();
|
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)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.HasDefaultSchema(SchemaName);
|
modelBuilder.HasDefaultSchema(SchemaName);
|
||||||
|
|||||||
-69
@@ -1,69 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using EmailApi.Data;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace EmailApi.Data.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(EmailApiDbContext))]
|
|
||||||
[Migration("20260528151849_RenameEFMigrationsTable")]
|
|
||||||
partial class RenameEFMigrationsTable
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasDefaultSchema("emailApi")
|
|
||||||
.HasAnnotation("ProductVersion", "10.0.7")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
|
||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("EmailApi.Data.Entities.EmailTemplateEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Key")
|
|
||||||
.HasMaxLength(128)
|
|
||||||
.HasColumnType("nvarchar(128)");
|
|
||||||
|
|
||||||
b.Property<string>("Language")
|
|
||||||
.HasMaxLength(8)
|
|
||||||
.HasColumnType("nvarchar(8)");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.IsRequired()
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasMaxLength(500)
|
|
||||||
.HasColumnType("nvarchar(500)")
|
|
||||||
.HasDefaultValue("");
|
|
||||||
|
|
||||||
b.Property<string>("OperatorCopy")
|
|
||||||
.IsRequired()
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("nvarchar(256)")
|
|
||||||
.HasDefaultValue("");
|
|
||||||
|
|
||||||
b.Property<DateTime>("UpdatedAt")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("datetime2")
|
|
||||||
.HasDefaultValueSql("SYSUTCDATETIME()");
|
|
||||||
|
|
||||||
b.Property<string>("Value")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.HasKey("Key", "Language");
|
|
||||||
|
|
||||||
b.ToTable("EmailTemplates", "emailApi");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace EmailApi.Data.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class RenameEFMigrationsTable : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
// Rename the EF Core migrations history table to match naming convention
|
|
||||||
migrationBuilder.Sql("EXEC sp_rename '[emailApi].[_EmailApiMigrations]', '_Migrations'");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
// Revert the rename
|
|
||||||
migrationBuilder.Sql("EXEC sp_rename '[emailApi].[_Migrations]', '_EmailApiMigrations'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,6 +12,13 @@ public sealed class MyAiDbContext : DbContext
|
|||||||
|
|
||||||
public DbSet<TemplateEntity> Templates => Set<TemplateEntity>();
|
public DbSet<TemplateEntity> Templates => Set<TemplateEntity>();
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
// Configure migration history table to use schema-qualified name: [myAi].[_Migrations]
|
||||||
|
optionsBuilder.UseSqlServer(x => x.MigrationsHistoryTable(MigrationTableName, SchemaName));
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.HasDefaultSchema(SchemaName);
|
modelBuilder.HasDefaultSchema(SchemaName);
|
||||||
|
|||||||
-56
@@ -1,56 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
using MyAi.Data;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace MyAi.Data.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(MyAiDbContext))]
|
|
||||||
[Migration("20260528151850_RenameEFMigrationsTable")]
|
|
||||||
partial class RenameEFMigrationsTable
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "8.0.5")
|
|
||||||
.HasDefaultSchema("myAi");
|
|
||||||
|
|
||||||
modelBuilder.Entity("MyAi.Data.Entities.TemplateEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Key")
|
|
||||||
.HasMaxLength(128)
|
|
||||||
.HasColumnType("nvarchar(128)");
|
|
||||||
|
|
||||||
b.Property<string>("Language")
|
|
||||||
.HasMaxLength(8)
|
|
||||||
.HasColumnType("nvarchar(8)");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.IsRequired()
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasMaxLength(500)
|
|
||||||
.HasColumnType("nvarchar(500)")
|
|
||||||
.HasDefaultValue("");
|
|
||||||
|
|
||||||
b.Property<DateTime>("UpdatedAt")
|
|
||||||
.HasColumnType("datetime2");
|
|
||||||
|
|
||||||
b.Property<string>("Value")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.HasKey("Key", "Language");
|
|
||||||
|
|
||||||
b.ToTable("Templates");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace MyAi.Data.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class RenameEFMigrationsTable : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
// Rename the EF Core migrations history table to match naming convention
|
|
||||||
migrationBuilder.Sql("EXEC sp_rename '[myAi].[_MyAiMigrations]', '_Migrations'");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
// Revert the rename
|
|
||||||
migrationBuilder.Sql("EXEC sp_rename '[myAi].[_Migrations]', '_MyAiMigrations'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,13 @@ public sealed class RagDbContext : DbContext
|
|||||||
public DbSet<RagEmbeddingCacheEntity> RagEmbeddingCache => Set<RagEmbeddingCacheEntity>();
|
public DbSet<RagEmbeddingCacheEntity> RagEmbeddingCache => Set<RagEmbeddingCacheEntity>();
|
||||||
public DbSet<RagChatCompletionCacheEntity> RagChatCompletionCache => Set<RagChatCompletionCacheEntity>();
|
public DbSet<RagChatCompletionCacheEntity> RagChatCompletionCache => Set<RagChatCompletionCacheEntity>();
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
// Configure migration history table to use schema-qualified name: [rag].[_Migrations]
|
||||||
|
optionsBuilder.UseSqlServer(x => x.MigrationsHistoryTable(MigrationTableName, SchemaName));
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.HasDefaultSchema(SchemaName);
|
modelBuilder.HasDefaultSchema(SchemaName);
|
||||||
|
|||||||
Reference in New Issue
Block a user