Files
Heimdall/src/Heimdall.Infrastructure/Data/AppDbContextFactory.cs
T
Arnaud Dartois ec50f6635e fix: remove hardcoded DB password from AppDbContextFactory
The fallback connection string included 'Password=heimdall' as a literal.
Remove the password — the fallback is only for local dev where PostgreSQL
trust authentication is typically used. Production deployments must set
the DATABASE_URL environment variable.
2026-07-27 18:37:54 +00:00

28 lines
953 B
C#

using Heimdall.Infrastructure.Data.Interceptors;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace Heimdall.Infrastructure.Data;
/// <summary>
/// Design-time factory for EF Core migrations.
/// Used by `dotnet ef migrations add` and `dotnet ef database update`.
/// </summary>
public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
public AppDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
var connectionString = Environment.GetEnvironmentVariable("DATABASE_URL")
?? "Host=localhost;Port=5432;Database=heimdall;Username=heimdall";
optionsBuilder.UseNpgsql(connectionString, npgsql =>
npgsql.MigrationsHistoryTable("__EFMigrationsHistory", "public"));
return new AppDbContext(
optionsBuilder.Options,
new AuditInterceptor());
}
}