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 deployedbe334a69as-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.
This commit is contained in:
parent
be334a69dc
commit
bbfaa039de
1 changed files with 18 additions and 0 deletions
|
|
@ -583,6 +583,16 @@ public static class HostingExtensions
|
||||||
{
|
{
|
||||||
Name = scopeSpec.ScopeName,
|
Name = scopeSpec.ScopeName,
|
||||||
DisplayName = scopeSpec.Description,
|
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,
|
Name = spec.ResourceName,
|
||||||
DisplayName = spec.ResourceDisplayName,
|
DisplayName = spec.ResourceDisplayName,
|
||||||
Enabled = true,
|
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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue