using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Diagnostics; namespace Infrastructure.Persistence; /// /// Design-time DbContext factory used by 'dotnet ef migrations / database update'. /// Bypasses the full Host startup (Program.cs) so EF tools don't need to construct /// Redis / JWT / Mail / etc. services. The connection string is taken from the /// 'ConnectionStrings__DefaultConnection' environment variable (set by Jenkins or /// the developer's shell) and falls back to a local SQL Express instance. /// public sealed class AppDbContextDesignTimeFactory : IDesignTimeDbContextFactory { public AppDbContext CreateDbContext(string[] args) { var conn = Environment.GetEnvironmentVariable("ConnectionStrings__DefaultConnection") ?? "Server=.\\SQLEXPRESS;Database=dpot;Trusted_Connection=True;TrustServerCertificate=True;MultipleActiveResultSets=true"; var options = new DbContextOptionsBuilder() .UseSqlServer(conn) .ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning)) .Options; return new AppDbContext(options); } }