24 lines
907 B
C#
24 lines
907 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Design;
|
|
|
|
/// <summary>
|
|
/// Creates <see cref="AppDbContext"/> for EF tools and migration bundles without
|
|
/// running <c>Program.cs</c> (JWT and other runtime config are not available there).
|
|
/// <c>./migrate-api --connection</c> still overrides the connection at apply time.
|
|
/// </summary>
|
|
public sealed class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
|
|
{
|
|
public AppDbContext CreateDbContext(string[] args)
|
|
{
|
|
var connectionString =
|
|
Environment.GetEnvironmentVariable("ConnectionStrings__DefaultConnection")
|
|
?? "Host=localhost;Port=5436;Database=vigilcare;Username=postgres;Password=password";
|
|
|
|
var options = new DbContextOptionsBuilder<AppDbContext>()
|
|
.UseNpgsql(connectionString)
|
|
.Options;
|
|
|
|
return new AppDbContext(options);
|
|
}
|
|
}
|