From bbfaa039deb58f383e1f3d2d0dcdb9ceddddeb27 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 25 Jun 2026 21:30:56 +0100 Subject: [PATCH] Set explicit defaults on seeded ApiScopes and ApiResources The previous commit (be334a69) relied on C# defaults to populate the Postgres NOT NULL columns Enabled, Required, Emphasize, ShowInDiscoveryDocument (on ApiScopes) and Created (on ApiResources). Both tables declare these columns NOT NULL without a database default, so EF Core ends up shipping C# defaults (false / DateTime.MinValue) that violate the constraints or silently disable the seeded rows. Concretely, if we deployed be334a69 as-is: - ApiScopes.Enabled = false -> the scope is invisible to DefaultResourceValidator, exactly the bug we're fixing. - ApiResources.Created = DateTime.MinValue (0001-01-01) -> Postgres rejects the INSERT with 'null value in column Created violates not-null constraint'. Set the values explicitly so the seeder produces the same state whether it runs once or a hundred times, fresh database or not. --- src/Yavsc.Org/Extensions/HostingExtensions.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Yavsc.Org/Extensions/HostingExtensions.cs b/src/Yavsc.Org/Extensions/HostingExtensions.cs index 38e00d24..fb7d41d6 100644 --- a/src/Yavsc.Org/Extensions/HostingExtensions.cs +++ b/src/Yavsc.Org/Extensions/HostingExtensions.cs @@ -583,6 +583,16 @@ public static class HostingExtensions { Name = scopeSpec.ScopeName, DisplayName = scopeSpec.Description, + // The corresponding Postgres columns are NOT NULL + // with no DB default — EF Core ships the C# default + // (false) unless we set them explicitly. A scope + // inserted with Enabled=false is invisible to + // DefaultResourceValidator, which would silently + // reproduce the bug we're fixing here. + Enabled = true, + Required = false, + Emphasize = false, + ShowInDiscoveryDocument = true, }); } } @@ -614,6 +624,14 @@ public static class HostingExtensions Name = spec.ResourceName, DisplayName = spec.ResourceDisplayName, Enabled = true, + // Created is NOT NULL with no DB default. Without + // this EF will send DateTime.MinValue (0001-01-01) + // which Postgres rejects with + // "null value in column 'Created' violates + // not-null constraint" once the seeder runs. + Created = DateTime.UtcNow, + ShowInDiscoveryDocument = true, + NonEditable = false, }); } }