using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.Extensions.Configuration; namespace DataServer.Data; public sealed class DesignTimeDbContextFactory : IDesignTimeDbContextFactory { public GameDbContext CreateDbContext(string[] args) { string cs; try { cs = ConnectionStringFactory.BuildMySqlFromEnv(); } catch { var cfg = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true) .AddUserSecrets(optional: true) .AddEnvironmentVariables() .Build(); cs = cfg.GetConnectionString("PrimaryMySql") ?? cfg["Database:ConnectionString"] ?? "Server=localhost;Port=3306;Database=systemrevival;User Id=root;Password=pass;"; } var opts = new DbContextOptionsBuilder() // Keep design-time independent of live DB connectivity. .UseMySql(cs, new MySqlServerVersion(new Version(8, 0, 36))) .Options; return new GameDbContext(opts); } }