using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; namespace ZB.MOM.WW.OtOpcUa.Configuration; /// /// Used by dotnet ef at design time (migrations, scaffolding). Reads the connection string /// from the OTOPCUA_CONFIG_CONNECTION environment variable, falling back to the local dev /// container on localhost:1433. /// public sealed class DesignTimeDbContextFactory : IDesignTimeDbContextFactory { // Host-port 14330 avoids collision with the native MSSQL14 instance on 1433 (Galaxy "ZB" DB). private const string DefaultConnectionString = "Server=localhost,14330;Database=OtOpcUaConfig;User Id=sa;Password=OtOpcUaDev_2026!;TrustServerCertificate=True;Encrypt=False;"; public OtOpcUaConfigDbContext CreateDbContext(string[] args) { var connection = Environment.GetEnvironmentVariable("OTOPCUA_CONFIG_CONNECTION") ?? DefaultConnectionString; var options = new DbContextOptionsBuilder() .UseSqlServer(connection, sql => sql.MigrationsAssembly(typeof(OtOpcUaConfigDbContext).Assembly.FullName)) .Options; return new OtOpcUaConfigDbContext(options); } }