| 12345678910111213141516171819202122232425262728 |
- using Microsoft.EntityFrameworkCore;
- using Microsoft.EntityFrameworkCore.Design;
- using Microsoft.EntityFrameworkCore.Diagnostics;
- namespace Infrastructure.Persistence;
- /// <summary>
- /// 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.
- /// </summary>
- public sealed class AppDbContextDesignTimeFactory : IDesignTimeDbContextFactory<AppDbContext>
- {
- 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<AppDbContext>()
- .UseSqlServer(conn)
- .ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning))
- .Options;
- return new AppDbContext(options);
- }
- }
|