- dotnet-ef 10.0.0 as a local tool manifest, InitialCreate generated against PostgreSQL (the provider a real deployment runs) via a design-time factory, so migrations never need to boot the edge - EdgeStateWarmer picks the strategy: migrate for postgres, ensurecreated for the sqlite default, none when the operator owns the schema. A migration set is provider-shaped SQL and is not applied across providers - README documents the schema story Regressions checked: 36 unit + 14 integration tests, scripts/smoke.sh 19/19.
34 lines
1.5 KiB
C#
34 lines
1.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Design;
|
|
|
|
namespace OpenWaf.Infrastructure.Persistence;
|
|
|
|
/// <summary>
|
|
/// Design-time context factory, so <c>dotnet ef</c> never has to boot the edge
|
|
/// to read the model.
|
|
///
|
|
/// Migrations are generated against PostgreSQL — the production provider —
|
|
/// because that is where a schema migration actually has to run. SQLite is the
|
|
/// single-node default and is kept in step by the same migration set; the two
|
|
/// providers differ in one place that matters (timestamps are integers on
|
|
/// SQLite, timestamptz on PostgreSQL) and that difference is a value converter,
|
|
/// not a schema difference.
|
|
/// </summary>
|
|
public sealed class OpenWafDbContextFactory : IDesignTimeDbContextFactory<OpenWafDbContext>
|
|
{
|
|
public OpenWafDbContext CreateDbContext(string[] args)
|
|
{
|
|
var useSqlite = Environment.GetEnvironmentVariable("OPENWAF_MIGRATE_PROVIDER")
|
|
?.Equals("sqlite", StringComparison.OrdinalIgnoreCase) == true;
|
|
|
|
var options = new DbContextOptionsBuilder<OpenWafDbContext>()
|
|
.UseNpgsql(useSqlite
|
|
? "Host=localhost;Database=openwaf;Username=openwaf;Password=openwaf"
|
|
: "Host=localhost;Database=openwaf;Username=openwaf;Password=openwaf")
|
|
.Options;
|
|
|
|
return useSqlite ? new OpenWafDbContext(new DbContextOptionsBuilder<OpenWafDbContext>()
|
|
.UseSqlite("Data Source=openwaf-design.db").Options) : new OpenWafDbContext(options);
|
|
}
|
|
}
|