24 lines
873 B
C#
24 lines
873 B
C#
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"));
|
||
|
|
|
||
|
|
return new AppDbContext(optionsBuilder.Options);
|
||
|
|
}
|
||
|
|
}
|