Add EF Core migrations; make schema strategy explicit
- 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.
This commit is contained in:
@@ -108,6 +108,21 @@ runtime through `PUT /admin-api/policy`, which persists to `policy_settings`.
|
||||
Database: `Database:Provider` = `sqlite` (default) or `postgres`,
|
||||
`ConnectionStrings__OpenWaf`. GeoIP: `GEOIP_MAXMIND_DB_PATH`.
|
||||
|
||||
## Schema
|
||||
|
||||
Migrations are the schema of record for PostgreSQL, which is the provider a
|
||||
real deployment runs:
|
||||
|
||||
```bash
|
||||
cd dotnet
|
||||
dotnet ef migrations add <Name> --project OpenWaf.Infrastructure --startup-project OpenWaf.Infrastructure
|
||||
```
|
||||
|
||||
A migration set is provider-shaped SQL, so it is not applied to the SQLite
|
||||
default — there the schema is created from the model at startup. `OPENWAF_SCHEMA`
|
||||
overrides the choice: `migrate`, `ensurecreated`, or `none` when an operator
|
||||
manages the schema themselves.
|
||||
|
||||
## Admin API
|
||||
|
||||
Requires `X-Admin-Token` (or `?token=`). **No token configured means the admin
|
||||
|
||||
@@ -22,10 +22,28 @@ internal sealed class EdgeStateWarmer(
|
||||
using var scope = scopeFactory.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<OpenWafDbContext>();
|
||||
|
||||
var provider = Environment.GetEnvironmentVariable("OPENWAF_DB_PROVIDER");
|
||||
if (!string.Equals(provider, "external", StringComparison.OrdinalIgnoreCase))
|
||||
// Migrations are the schema of record for the provider that actually
|
||||
// runs in production — PostgreSQL. A migration set is provider-shaped
|
||||
// SQL, so it is not applied to the SQLite default; there the schema is
|
||||
// created from the model instead. OPENWAF_SCHEMA=none leaves both alone
|
||||
// when an operator manages the schema themselves.
|
||||
var isSqlite = string.Equals(
|
||||
Environment.GetEnvironmentVariable("Database__Provider") ?? "sqlite",
|
||||
"sqlite", StringComparison.OrdinalIgnoreCase);
|
||||
var strategy = Environment.GetEnvironmentVariable("OPENWAF_SCHEMA")
|
||||
?? (isSqlite ? "ensurecreated" : "migrate");
|
||||
|
||||
switch (strategy.ToLowerInvariant())
|
||||
{
|
||||
await db.Database.EnsureCreatedAsync(cancellationToken);
|
||||
case "ensurecreated":
|
||||
await db.Database.EnsureCreatedAsync(cancellationToken);
|
||||
break;
|
||||
case "migrate":
|
||||
await db.Database.MigrateAsync(cancellationToken);
|
||||
break;
|
||||
default:
|
||||
log.LogInformation("edge: schema management left to the operator (OPENWAF_SCHEMA={Strategy})", strategy);
|
||||
break;
|
||||
}
|
||||
|
||||
await state.WarmUpAsync(cancellationToken);
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0" />
|
||||
<!-- NU1903: EF's transitive SQLitePCLRaw 2.1.11 carries a known high
|
||||
severity advisory (GHSA-2m69-gcr7-jv3q). Pinned forward rather than
|
||||
|
||||
Generated
+260
@@ -0,0 +1,260 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using OpenWaf.Infrastructure.Persistence;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace OpenWaf.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
[DbContext(typeof(OpenWafDbContext))]
|
||||
[Migration("20261001002803_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Domain.Policy.CountryRule", b =>
|
||||
{
|
||||
b.Property<string>("Code")
|
||||
.HasMaxLength(2)
|
||||
.HasColumnType("character varying(2)");
|
||||
|
||||
b.Property<bool>("IsAllowed")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Code");
|
||||
|
||||
b.ToTable("country_rules", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Domain.Security.AllowEntry", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset?>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Match")
|
||||
.IsRequired()
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("character varying(512)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Match")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("allow_entries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Domain.Security.BlockEntry", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<int?>("ConsecutiveRefusals")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset?>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("LastCity")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<string>("LastCountryCode")
|
||||
.HasMaxLength(2)
|
||||
.HasColumnType("character varying(2)");
|
||||
|
||||
b.Property<string>("LastPath")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("character varying(512)");
|
||||
|
||||
b.Property<string>("LastRegion")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<int?>("LastStatusCode")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("LastUserAgent")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasMaxLength(1024)
|
||||
.HasColumnType("character varying(1024)");
|
||||
|
||||
b.Property<string>("RedirectTo")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("character varying(512)");
|
||||
|
||||
b.Property<int>("Source")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("SourceKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ExpiresAt");
|
||||
|
||||
b.HasIndex("SourceKey", "Source")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("block_entries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Domain.Security.EdgeAlert", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Detail")
|
||||
.IsRequired()
|
||||
.HasMaxLength(1024)
|
||||
.HasColumnType("character varying(1024)");
|
||||
|
||||
b.Property<string>("Kind")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<string>("LastPath")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("LastStatusCode")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("SourceKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CreatedAt");
|
||||
|
||||
b.ToTable("edge_alerts", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Domain.Security.SourceObservation", b =>
|
||||
{
|
||||
b.Property<string>("SourceKey")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<DateTimeOffset>("FirstSeenAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("LastCity")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<string>("LastCountryCode")
|
||||
.HasMaxLength(2)
|
||||
.HasColumnType("character varying(2)");
|
||||
|
||||
b.Property<string>("LastPath")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("character varying(512)");
|
||||
|
||||
b.Property<string>("LastRegion")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<DateTimeOffset>("LastSeenAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int?>("LastStatusCode")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("LastUserAgent")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<int>("MaxConsecutiveRefusals")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TotalRefusals")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TotalServerErrorStreak")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("SourceKey");
|
||||
|
||||
b.HasIndex("LastSeenAt");
|
||||
|
||||
b.ToTable("source_observations", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Infrastructure.Persistence.PolicySetting", b =>
|
||||
{
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.HasKey("Key");
|
||||
|
||||
b.ToTable("policy_settings", (string)null);
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace OpenWaf.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "allow_entries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Match = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
||||
Note = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
||||
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
ExpiresAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_allow_entries", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "block_entries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
SourceKey = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
||||
Source = table.Column<int>(type: "integer", nullable: false),
|
||||
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
ExpiresAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
Reason = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: true),
|
||||
RedirectTo = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
||||
LastStatusCode = table.Column<int>(type: "integer", nullable: true),
|
||||
LastPath = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
||||
LastUserAgent = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
||||
LastCountryCode = table.Column<string>(type: "character varying(2)", maxLength: 2, nullable: true),
|
||||
LastCity = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
||||
LastRegion = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
||||
ConsecutiveRefusals = table.Column<int>(type: "integer", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_block_entries", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "country_rules",
|
||||
columns: table => new
|
||||
{
|
||||
Code = table.Column<string>(type: "character varying(2)", maxLength: 2, nullable: false),
|
||||
Name = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
||||
IsAllowed = table.Column<bool>(type: "boolean", nullable: false),
|
||||
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_country_rules", x => x.Code);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "edge_alerts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
SourceKey = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
||||
Kind = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
LastStatusCode = table.Column<int>(type: "integer", nullable: true),
|
||||
LastPath = table.Column<string>(type: "text", nullable: true),
|
||||
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
Detail = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_edge_alerts", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "policy_settings",
|
||||
columns: table => new
|
||||
{
|
||||
Key = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||
Value = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_policy_settings", x => x.Key);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "source_observations",
|
||||
columns: table => new
|
||||
{
|
||||
SourceKey = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
||||
FirstSeenAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
LastSeenAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
MaxConsecutiveRefusals = table.Column<int>(type: "integer", nullable: false),
|
||||
TotalRefusals = table.Column<int>(type: "integer", nullable: false),
|
||||
TotalServerErrorStreak = table.Column<int>(type: "integer", nullable: false),
|
||||
LastStatusCode = table.Column<int>(type: "integer", nullable: true),
|
||||
LastPath = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
||||
LastUserAgent = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
||||
LastCountryCode = table.Column<string>(type: "character varying(2)", maxLength: 2, nullable: true),
|
||||
LastCity = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
||||
LastRegion = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_source_observations", x => x.SourceKey);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_allow_entries_Match",
|
||||
table: "allow_entries",
|
||||
column: "Match",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_block_entries_ExpiresAt",
|
||||
table: "block_entries",
|
||||
column: "ExpiresAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_block_entries_SourceKey_Source",
|
||||
table: "block_entries",
|
||||
columns: new[] { "SourceKey", "Source" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_edge_alerts_CreatedAt",
|
||||
table: "edge_alerts",
|
||||
column: "CreatedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_source_observations_LastSeenAt",
|
||||
table: "source_observations",
|
||||
column: "LastSeenAt");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "allow_entries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "block_entries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "country_rules");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "edge_alerts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "policy_settings");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "source_observations");
|
||||
}
|
||||
}
|
||||
}
|
||||
+257
@@ -0,0 +1,257 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using OpenWaf.Infrastructure.Persistence;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace OpenWaf.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
[DbContext(typeof(OpenWafDbContext))]
|
||||
partial class OpenWafDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Domain.Policy.CountryRule", b =>
|
||||
{
|
||||
b.Property<string>("Code")
|
||||
.HasMaxLength(2)
|
||||
.HasColumnType("character varying(2)");
|
||||
|
||||
b.Property<bool>("IsAllowed")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Code");
|
||||
|
||||
b.ToTable("country_rules", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Domain.Security.AllowEntry", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset?>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Match")
|
||||
.IsRequired()
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("character varying(512)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Match")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("allow_entries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Domain.Security.BlockEntry", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<int?>("ConsecutiveRefusals")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset?>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("LastCity")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<string>("LastCountryCode")
|
||||
.HasMaxLength(2)
|
||||
.HasColumnType("character varying(2)");
|
||||
|
||||
b.Property<string>("LastPath")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("character varying(512)");
|
||||
|
||||
b.Property<string>("LastRegion")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<int?>("LastStatusCode")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("LastUserAgent")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasMaxLength(1024)
|
||||
.HasColumnType("character varying(1024)");
|
||||
|
||||
b.Property<string>("RedirectTo")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("character varying(512)");
|
||||
|
||||
b.Property<int>("Source")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("SourceKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ExpiresAt");
|
||||
|
||||
b.HasIndex("SourceKey", "Source")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("block_entries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Domain.Security.EdgeAlert", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Detail")
|
||||
.IsRequired()
|
||||
.HasMaxLength(1024)
|
||||
.HasColumnType("character varying(1024)");
|
||||
|
||||
b.Property<string>("Kind")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<string>("LastPath")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("LastStatusCode")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("SourceKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CreatedAt");
|
||||
|
||||
b.ToTable("edge_alerts", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Domain.Security.SourceObservation", b =>
|
||||
{
|
||||
b.Property<string>("SourceKey")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<DateTimeOffset>("FirstSeenAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("LastCity")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<string>("LastCountryCode")
|
||||
.HasMaxLength(2)
|
||||
.HasColumnType("character varying(2)");
|
||||
|
||||
b.Property<string>("LastPath")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("character varying(512)");
|
||||
|
||||
b.Property<string>("LastRegion")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<DateTimeOffset>("LastSeenAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int?>("LastStatusCode")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("LastUserAgent")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<int>("MaxConsecutiveRefusals")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TotalRefusals")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TotalServerErrorStreak")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("SourceKey");
|
||||
|
||||
b.HasIndex("LastSeenAt");
|
||||
|
||||
b.ToTable("source_observations", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("OpenWaf.Infrastructure.Persistence.PolicySetting", b =>
|
||||
{
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.HasKey("Key");
|
||||
|
||||
b.ToTable("policy_settings", (string)null);
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "10.0.0",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
],
|
||||
"rollForward": false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user