23 lines
849 B
C#
23 lines
849 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Design;
|
|
|
|
namespace InboxIntel.Infrastructure.Persistence;
|
|
|
|
/// <summary>
|
|
/// Design-time factory so `dotnet ef migrations add ...` works without booting
|
|
/// the full API host. Reads the connection string from the EF_CONNECTION env
|
|
/// var, falling back to a local default.
|
|
/// </summary>
|
|
public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
|
|
{
|
|
public AppDbContext CreateDbContext(string[] args)
|
|
{
|
|
var conn = Environment.GetEnvironmentVariable("EF_CONNECTION")
|
|
?? "Host=localhost;Port=5432;Database=inboxintel;Username=inboxintel;Password=inboxintel";
|
|
var options = new DbContextOptionsBuilder<AppDbContext>()
|
|
.UseNpgsql(conn)
|
|
.Options;
|
|
return new AppDbContext(options);
|
|
}
|
|
}
|