This commit is contained in:
Ccjcarkbla
2026-02-23 21:09:46 -05:00
parent b1d8173a1f
commit 9b9bdacb3a
22 changed files with 833 additions and 110 deletions
+15
View File
@@ -16,6 +16,7 @@ public sealed class AppDbContext : DbContext
public DbSet<AuthorizationGroupEntity> AuthorizationGroups => Set<AuthorizationGroupEntity>();
public DbSet<PermissionRuleEntity> PermissionRules => Set<PermissionRuleEntity>();
public DbSet<AuditRecordEntity> AuditRecords => Set<AuditRecordEntity>();
public DbSet<ManagedPageEntity> ManagedPages => Set<ManagedPageEntity>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -87,5 +88,19 @@ public sealed class AppDbContext : DbContext
e.Property(x => x.Target).HasMaxLength(200).IsRequired();
e.HasIndex(x => x.TimestampUtc);
});
modelBuilder.Entity<ManagedPageEntity>(e =>
{
e.ToTable("ManagedPage");
e.HasKey(x => x.Id);
e.Property(x => x.Key).HasMaxLength(100).IsRequired();
e.Property(x => x.DisplayName).HasMaxLength(200).IsRequired();
e.Property(x => x.PageKind).HasMaxLength(50).IsRequired();
e.Property(x => x.RecurrenceRule).HasMaxLength(200);
e.Property(x => x.LastUpdatedBy).HasMaxLength(200).IsRequired();
e.Property(x => x.ContentJson).IsRequired();
e.HasIndex(x => x.Key).IsUnique();
e.HasIndex(x => new { x.PageKind, x.IsEnabled, x.Priority });
});
}
}
+23
View File
@@ -0,0 +1,23 @@
namespace maintenance.Data.Entities;
public sealed class ManagedPageEntity
{
public Guid Id { get; set; }
public string Key { get; set; } = string.Empty;
public string DisplayName { get; set; } = string.Empty;
public string PageKind { get; set; } = "maintenance"; // maintenance | error
public bool IsDefaultFallback { get; set; }
public bool IsEnabled { get; set; } = true;
public bool OverrideWindow { get; set; }
public int Priority { get; set; }
public DateTime? StartUtc { get; set; }
public DateTime? EndUtc { get; set; }
public string? RecurrenceRule { get; set; } // cron-like expression (future evaluator)
// Structured content payload rendered into a locked template.
public string ContentJson { get; set; } = "{}";
public string LastUpdatedBy { get; set; } = string.Empty;
public DateTime LastUpdatedAtUtc { get; set; }
}
+73
View File
@@ -0,0 +1,73 @@
using System.Text.Json;
using maintenance.Data.Entities;
using maintenance.Services.Pages;
using Microsoft.EntityFrameworkCore;
namespace maintenance.Data.Seed;
public static class ManagedPageSeeder
{
public static async Task SeedAsync(AppDbContext dbContext, CancellationToken cancellationToken = default)
{
var defaults = new[]
{
new ManagedPageEntity
{
Id = Guid.NewGuid(),
Key = "generic-maintenance",
DisplayName = "Generic Maintenance",
PageKind = "maintenance",
IsDefaultFallback = true,
IsEnabled = true,
OverrideWindow = false,
Priority = 0,
ContentJson = JsonSerializer.Serialize(new PageContentModel
{
ErrorName = "Application Unavailable",
Description = "MAX applications may be down for scheduled maintenance 2AM-8AM Sunday morning. If this appears at another time, contact support.",
ErrorCode = "eau",
ShowInstructions = false
}),
LastUpdatedBy = "system-seed",
LastUpdatedAtUtc = DateTime.UtcNow
},
new ManagedPageEntity
{
Id = Guid.NewGuid(),
Key = "generic-error",
DisplayName = "Generic Error",
PageKind = "error",
IsDefaultFallback = true,
IsEnabled = true,
OverrideWindow = false,
Priority = 0,
ContentJson = JsonSerializer.Serialize(new PageContentModel
{
ErrorName = "System Error",
Description = "A system error has occurred. Please contact MAX Support.",
ErrorCode = "eag",
ShowInstructions = false
}),
LastUpdatedBy = "system-seed",
LastUpdatedAtUtc = DateTime.UtcNow
}
};
var existingKeys = await dbContext.ManagedPages
.AsNoTracking()
.Select(x => x.Key)
.ToListAsync(cancellationToken);
var missing = defaults
.Where(x => !existingKeys.Contains(x.Key, StringComparer.OrdinalIgnoreCase))
.ToList();
if (missing.Count == 0)
{
return;
}
await dbContext.ManagedPages.AddRangeAsync(missing, cancellationToken);
await dbContext.SaveChangesAsync(cancellationToken);
}
}