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);
}
}
@@ -24,6 +24,10 @@
<PackageReference Include="Hl7.Fhir.R4" Version="5.11.1" /> <PackageReference Include="Hl7.Fhir.R4" Version="5.11.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.27" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.27" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.27" /> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.27" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>