2026-07-20 09:50:43 +00:00
|
|
|
|
2026-07-19 19:58:45 +00:00
|
|
|
using Heimdall.Infrastructure.Data.Interceptors;
|
2026-07-16 20:53:56 +00:00
|
|
|
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;Password=heimdall";
|
|
|
|
|
|
|
|
|
|
optionsBuilder.UseNpgsql(connectionString, npgsql =>
|
|
|
|
|
npgsql.MigrationsHistoryTable("__EFMigrationsHistory", "public"));
|
|
|
|
|
|
2026-07-19 19:58:45 +00:00
|
|
|
return new AppDbContext(
|
|
|
|
|
optionsBuilder.Options,
|
2026-07-20 09:50:43 +00:00
|
|
|
new AuditInterceptor());
|
2026-07-16 20:53:56 +00:00
|
|
|
}
|
|
|
|
|
}
|