Rename EmailApiDbContext to EmailDbContext and EmailTemplates table to Templates
Refactoring: - Rename EmailApiDbContext class to EmailDbContext for consistency with other DbContext naming - Rename DbSet property from EmailTemplates to Templates - Rename table from EmailTemplates to Templates - Update all references in Program.cs files (email-api, api, cv-search-job) - Update all migration files and model snapshot - Fix cv-search-job migrations assembly name: email-api-data → email-data This improves naming consistency across the solution. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -51,12 +51,12 @@ try
|
|||||||
});
|
});
|
||||||
builder.Services.AddSingleton<ITemplateService, DbTemplateService>();
|
builder.Services.AddSingleton<ITemplateService, DbTemplateService>();
|
||||||
|
|
||||||
builder.Services.AddDbContext<EmailApiDbContext>(options =>
|
builder.Services.AddDbContext<EmailDbContext>(options =>
|
||||||
{
|
{
|
||||||
var connectionString = builder.Services.GetConfiguredDbConnectionString(builder.Configuration);
|
var connectionString = builder.Services.GetConfiguredDbConnectionString(builder.Configuration);
|
||||||
options.UseSqlServer(connectionString, sql =>
|
options.UseSqlServer(connectionString, sql =>
|
||||||
{
|
{
|
||||||
sql.MigrationsHistoryTable(EmailApiDbContext.MigrationTableName, EmailApiDbContext.SchemaName);
|
sql.MigrationsHistoryTable(EmailDbContext.MigrationTableName, EmailDbContext.SchemaName);
|
||||||
sql.MigrationsAssembly("email-data");
|
sql.MigrationsAssembly("email-data");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ try
|
|||||||
builder.Services.Configure<SmtpSettings>(builder.Configuration.GetSection("Smtp"));
|
builder.Services.Configure<SmtpSettings>(builder.Configuration.GetSection("Smtp"));
|
||||||
builder.Services.Configure<FileStorageSettings>(builder.Configuration.GetSection("FileStorage"));
|
builder.Services.Configure<FileStorageSettings>(builder.Configuration.GetSection("FileStorage"));
|
||||||
|
|
||||||
builder.Services.AddDbContext<EmailApiDbContext>(options =>
|
builder.Services.AddDbContext<EmailDbContext>(options =>
|
||||||
{
|
{
|
||||||
var connectionString = builder.Services.GetConfiguredDbConnectionString(builder.Configuration);
|
var connectionString = builder.Services.GetConfiguredDbConnectionString(builder.Configuration);
|
||||||
options.UseSqlServer(connectionString, sql =>
|
options.UseSqlServer(connectionString, sql =>
|
||||||
{
|
{
|
||||||
sql.MigrationsHistoryTable(EmailApiDbContext.MigrationTableName, EmailApiDbContext.SchemaName);
|
sql.MigrationsHistoryTable(EmailDbContext.MigrationTableName, EmailDbContext.SchemaName);
|
||||||
sql.MigrationsAssembly("email-data");
|
sql.MigrationsAssembly("email-data");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -61,7 +61,7 @@ try
|
|||||||
Log.Information("Running EF Core migrations if any");
|
Log.Information("Running EF Core migrations if any");
|
||||||
using (var scope = app.Services.CreateScope())
|
using (var scope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
var db = scope.ServiceProvider.GetRequiredService<EmailApiDbContext>();
|
var db = scope.ServiceProvider.GetRequiredService<EmailDbContext>();
|
||||||
db.Database.Migrate();
|
db.Database.Migrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace Email.Data;
|
namespace Email.Data;
|
||||||
|
|
||||||
public sealed class EmailApiDbContext : DbContext
|
public sealed class EmailDbContext : DbContext
|
||||||
{
|
{
|
||||||
public const string SchemaName = MigrationConstants.SchemaName;
|
public const string SchemaName = MigrationConstants.SchemaName;
|
||||||
public const string MigrationTableName = MigrationConstants.MigrationTableName;
|
public const string MigrationTableName = MigrationConstants.MigrationTableName;
|
||||||
|
|
||||||
public EmailApiDbContext(DbContextOptions<EmailApiDbContext> options) : base(options) { }
|
public EmailDbContext(DbContextOptions<EmailDbContext> options) : base(options) { }
|
||||||
|
|
||||||
public DbSet<EmailTemplateEntity> EmailTemplates => Set<EmailTemplateEntity>();
|
public DbSet<EmailTemplateEntity> Templates => Set<EmailTemplateEntity>();
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,7 @@ public sealed class EmailApiDbContext : DbContext
|
|||||||
|
|
||||||
modelBuilder.Entity<EmailTemplateEntity>(entity =>
|
modelBuilder.Entity<EmailTemplateEntity>(entity =>
|
||||||
{
|
{
|
||||||
entity.ToTable("EmailTemplates");
|
entity.ToTable("Templates");
|
||||||
entity.HasKey(x => new { x.Key, x.Language });
|
entity.HasKey(x => new { x.Key, x.Language });
|
||||||
entity.Property(x => x.Key).HasMaxLength(128);
|
entity.Property(x => x.Key).HasMaxLength(128);
|
||||||
entity.Property(x => x.Language).HasMaxLength(8);
|
entity.Property(x => x.Language).HasMaxLength(8);
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
namespace Email.Data;
|
namespace Email.Data;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Schema constants used by EmailApiDbContext and migrations.
|
/// Schema constants used by EmailDbContext and migrations.
|
||||||
/// Centralized to avoid hardcoded strings and ensure consistency.
|
/// Centralized to avoid hardcoded strings and ensure consistency.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class MigrationConstants
|
public static class MigrationConstants
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace Email.Data.Migrations
|
namespace Email.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(EmailApiDbContext))]
|
[DbContext(typeof(EmailDbContext))]
|
||||||
[Migration("20260528100000_CreateEmailTemplates")]
|
[Migration("20260528100000_CreateEmailTemplates")]
|
||||||
partial class CreateEmailTemplates
|
partial class CreateEmailTemplates
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace Email.Data.Migrations
|
namespace Email.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(EmailApiDbContext))]
|
[DbContext(typeof(EmailDbContext))]
|
||||||
[Migration("20260528130652_SeedEmailTemplates")]
|
[Migration("20260528130652_SeedEmailTemplates")]
|
||||||
partial class SeedEmailTemplates
|
partial class SeedEmailTemplates
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-3
@@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace Email.Data.Migrations
|
namespace Email.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(EmailApiDbContext))]
|
[DbContext(typeof(EmailDbContext))]
|
||||||
partial class EmailApiDbContextModelSnapshot : ModelSnapshot
|
partial class EmailDbContextModelSnapshot : ModelSnapshot
|
||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
@@ -58,7 +58,7 @@ namespace Email.Data.Migrations
|
|||||||
|
|
||||||
b.HasKey("Key", "Language");
|
b.HasKey("Key", "Language");
|
||||||
|
|
||||||
b.ToTable("EmailTemplates", MigrationConstants.SchemaName);
|
b.ToTable("Templates", MigrationConstants.SchemaName);
|
||||||
});
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
@@ -6,13 +6,13 @@ namespace Email.Data.Repositories;
|
|||||||
|
|
||||||
public sealed class EfEmailTemplateRepository : IEmailTemplateRepository
|
public sealed class EfEmailTemplateRepository : IEmailTemplateRepository
|
||||||
{
|
{
|
||||||
private readonly EmailApiDbContext _db;
|
private readonly EmailDbContext _db;
|
||||||
|
|
||||||
public EfEmailTemplateRepository(EmailApiDbContext db)
|
public EfEmailTemplateRepository(EmailDbContext db)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IReadOnlyList<EmailTemplateEntity>> GetAllAsync(CancellationToken ct)
|
public async Task<IReadOnlyList<EmailTemplateEntity>> GetAllAsync(CancellationToken ct)
|
||||||
=> await _db.EmailTemplates.AsNoTracking().ToListAsync(ct);
|
=> await _db.Templates.AsNoTracking().ToListAsync(ct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,13 +56,13 @@ try
|
|||||||
client.DefaultRequestHeaders.Add("X-Internal-Api-Key", key);
|
client.DefaultRequestHeaders.Add("X-Internal-Api-Key", key);
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddDbContext<EmailApiDbContext>(options =>
|
builder.Services.AddDbContext<EmailDbContext>(options =>
|
||||||
{
|
{
|
||||||
var connectionString = builder.Services.GetConfiguredDbConnectionString(builder.Configuration);
|
var connectionString = builder.Services.GetConfiguredDbConnectionString(builder.Configuration);
|
||||||
options.UseSqlServer(connectionString, sql =>
|
options.UseSqlServer(connectionString, sql =>
|
||||||
{
|
{
|
||||||
sql.MigrationsHistoryTable(EmailApiDbContext.MigrationTableName, EmailApiDbContext.SchemaName);
|
sql.MigrationsHistoryTable(EmailDbContext.MigrationTableName, EmailDbContext.SchemaName);
|
||||||
sql.MigrationsAssembly("email-api-data");
|
sql.MigrationsAssembly("email-data");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user