Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions PatchNotes.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@

var app = builder.Build();

// Seed email templates at startup to avoid race condition on first-access lazy seeding
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<PatchNotesDbContext>();
await db.Database.EnsureCreatedAsync();
await EmailTemplateRoutes.SeedDefaultTemplatesAsync(db);
}

if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
Expand Down
6 changes: 0 additions & 6 deletions PatchNotes.Api/Routes/EmailTemplateRoutes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ public static WebApplication MapEmailTemplateRoutes(this WebApplication app)
// GET /api/admin/email-templates - List all templates
group.MapGet("/", async (PatchNotesDbContext db) =>
{
// Seed defaults on first access
if (!await db.EmailTemplates.AnyAsync())
{
await SeedDefaultTemplatesAsync(db);
}

var templates = await db.EmailTemplates
.OrderBy(t => t.Name)
.Select(t => new EmailTemplateDto
Expand Down
Loading