Fix issue with Unable to create a 'DbContext' of type 'AppDbContext'
CI / frontend (push) Canceled after 0s
CI / backend (push) Canceled after 11s

This commit is contained in:
2026-08-10 17:40:09 +08:00
parent 22094a6b16
commit 2e66d40248
2 changed files with 27 additions and 0 deletions
@@ -0,0 +1,23 @@
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=127.0.0.1;Database=vigilcare;Username=postgres;Password=postgres";
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseNpgsql(connectionString)
.Options;
return new AppDbContext(options);
}
}