Update to allow for seeding of database
This commit is contained in:
@@ -48,8 +48,17 @@ public static class DataSeeder
|
||||
};
|
||||
db.Encounters.AddRange(encounter1, encounter2);
|
||||
|
||||
var thresholds = BuildDefaultThresholds();
|
||||
db.AlertThresholds.AddRange(thresholds);
|
||||
// Thresholds may already exist from BootstrapSeeder — unique on observation_code.
|
||||
List<AlertThreshold> thresholds;
|
||||
if (!await db.AlertThresholds.AnyAsync())
|
||||
{
|
||||
thresholds = BuildDefaultThresholds();
|
||||
db.AlertThresholds.AddRange(thresholds);
|
||||
}
|
||||
else
|
||||
{
|
||||
thresholds = await db.AlertThresholds.ToListAsync();
|
||||
}
|
||||
|
||||
// Observations spanning normal, warning, and critical ranges for encounter1
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
@@ -108,6 +117,21 @@ public static class DataSeeder
|
||||
await CacheThresholdsAsync(redis, thresholds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Idempotent: inserts the default threshold catalogue only when the table is empty,
|
||||
/// then warms Redis. Safe for production bootstrap.
|
||||
/// </summary>
|
||||
public static async Task EnsureDefaultThresholdsAsync(AppDbContext db, IConnectionMultiplexer redis)
|
||||
{
|
||||
if (await db.AlertThresholds.AnyAsync())
|
||||
return;
|
||||
|
||||
var thresholds = BuildDefaultThresholds();
|
||||
db.AlertThresholds.AddRange(thresholds);
|
||||
await db.SaveChangesAsync();
|
||||
await CacheThresholdsAsync(redis, thresholds);
|
||||
}
|
||||
|
||||
public static List<AlertThreshold> BuildDefaultThresholds() => new()
|
||||
{
|
||||
new() {
|
||||
|
||||
Reference in New Issue
Block a user