40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
|
|
public static class DbResetHelper
|
|
{
|
|
// Truncate all data between tests — faster than dropping and re-creating
|
|
// the database, and preserves the schema (migrations do not re-run).
|
|
public static async Task ResetAsync(AppDbContext db)
|
|
{
|
|
for (var attempt = 0; ; attempt++)
|
|
{
|
|
try
|
|
{
|
|
await db.Database.ExecuteSqlRawAsync(@"
|
|
DELETE FROM medication_administrations;
|
|
DELETE FROM sepsis_bundle_elements;
|
|
DELETE FROM sepsis_bundles;
|
|
DELETE FROM reconciliation_alerts;
|
|
DELETE FROM outbox_events;
|
|
DELETE FROM orders;
|
|
DELETE FROM clinical_alerts;
|
|
DELETE FROM gcs_scores;
|
|
DELETE FROM sofa_scores;
|
|
DELETE FROM news2_scores;
|
|
DELETE FROM observations;
|
|
DELETE FROM external_resource_identifiers;
|
|
DELETE FROM encounters;
|
|
DELETE FROM alert_thresholds;
|
|
DELETE FROM clinical_audit_logs;
|
|
DELETE FROM clinical_users;
|
|
DELETE FROM patients;
|
|
");
|
|
return;
|
|
}
|
|
catch when (attempt < 5)
|
|
{
|
|
await Task.Delay(1000);
|
|
}
|
|
}
|
|
}
|
|
} |