This commit is contained in:
Ccjcarkbla
2026-02-23 08:00:41 -05:00
parent a89f1810b5
commit 829a71ab5e
124 changed files with 76395 additions and 2 deletions
+91
View File
@@ -0,0 +1,91 @@
using maintenance.Data.Entities;
using Microsoft.EntityFrameworkCore;
namespace maintenance.Data;
public sealed class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
public DbSet<TemplateEntity> Templates => Set<TemplateEntity>();
public DbSet<AppMappingEntity> AppMappings => Set<AppMappingEntity>();
public DbSet<FeatureFlagEntity> FeatureFlags => Set<FeatureFlagEntity>();
public DbSet<MaintenanceWindowEntity> MaintenanceWindows => Set<MaintenanceWindowEntity>();
public DbSet<AuthorizationGroupEntity> AuthorizationGroups => Set<AuthorizationGroupEntity>();
public DbSet<PermissionRuleEntity> PermissionRules => Set<PermissionRuleEntity>();
public DbSet<AuditRecordEntity> AuditRecords => Set<AuditRecordEntity>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TemplateEntity>(e =>
{
e.ToTable("Template");
e.HasKey(x => x.Id);
e.Property(x => x.Name).HasMaxLength(50).IsRequired();
e.Property(x => x.Title).HasMaxLength(200).IsRequired();
e.Property(x => x.LastUpdatedBy).HasMaxLength(200).IsRequired();
e.HasIndex(x => x.Name).IsUnique();
});
modelBuilder.Entity<AppMappingEntity>(e =>
{
e.ToTable("AppMapping");
e.HasKey(x => x.Id);
e.Property(x => x.AppId).HasMaxLength(100).IsRequired();
e.Property(x => x.DisplayName).HasMaxLength(200).IsRequired();
e.Property(x => x.DefaultTemplate).HasMaxLength(50).IsRequired();
e.HasIndex(x => x.AppId).IsUnique();
});
modelBuilder.Entity<FeatureFlagEntity>(e =>
{
e.ToTable("FeatureFlag");
e.HasKey(x => x.Id);
e.Property(x => x.Key).HasMaxLength(100).IsRequired();
e.Property(x => x.Scope).HasMaxLength(50).IsRequired();
e.HasIndex(x => new { x.Key, x.Scope }).IsUnique();
});
modelBuilder.Entity<MaintenanceWindowEntity>(e =>
{
e.ToTable("MaintenanceWindow");
e.HasKey(x => x.Id);
e.Property(x => x.AppId).HasMaxLength(100);
e.HasIndex(x => new { x.AppId, x.StartTimeEastern, x.EndTimeEastern });
});
modelBuilder.Entity<AuthorizationGroupEntity>(e =>
{
e.ToTable("AuthorizationGroup");
e.HasKey(x => x.Id);
e.Property(x => x.GroupClaimValue).HasMaxLength(256).IsRequired();
e.Property(x => x.Role).HasMaxLength(50).IsRequired();
e.HasIndex(x => x.GroupClaimValue).IsUnique();
});
modelBuilder.Entity<PermissionRuleEntity>(e =>
{
e.ToTable("PermissionRule");
e.HasKey(x => x.Id);
e.Property(x => x.PermissionKey).HasMaxLength(200).IsRequired();
e.Property(x => x.Effect).HasMaxLength(10).IsRequired();
e.HasOne(x => x.Group)
.WithMany()
.HasForeignKey(x => x.GroupId)
.OnDelete(DeleteBehavior.Cascade);
e.HasIndex(x => new { x.PermissionKey, x.GroupId }).IsUnique();
});
modelBuilder.Entity<AuditRecordEntity>(e =>
{
e.ToTable("AuditRecord");
e.HasKey(x => x.Id);
e.Property(x => x.Actor).HasMaxLength(200).IsRequired();
e.Property(x => x.Action).HasMaxLength(100).IsRequired();
e.Property(x => x.Target).HasMaxLength(200).IsRequired();
e.HasIndex(x => x.TimestampUtc);
});
}
}
+11
View File
@@ -0,0 +1,11 @@
namespace maintenance.Data.Entities;
public sealed class AppMappingEntity
{
public Guid Id { get; set; }
public string AppId { get; set; } = string.Empty;
public string DisplayName { get; set; } = string.Empty;
public string DefaultTemplate { get; set; } = "down";
public string AllowedFieldsJson { get; set; } = "[]";
public bool Active { get; set; } = true;
}
+11
View File
@@ -0,0 +1,11 @@
namespace maintenance.Data.Entities;
public sealed class AuditRecordEntity
{
public Guid Id { get; set; }
public string Actor { get; set; } = string.Empty;
public string Action { get; set; } = string.Empty;
public string Target { get; set; } = string.Empty;
public DateTime TimestampUtc { get; set; }
public string? Diff { get; set; }
}
@@ -0,0 +1,9 @@
namespace maintenance.Data.Entities;
public sealed class AuthorizationGroupEntity
{
public Guid Id { get; set; }
public string GroupClaimValue { get; set; } = string.Empty;
public string Role { get; set; } = "admin";
public bool Active { get; set; } = true;
}
+9
View File
@@ -0,0 +1,9 @@
namespace maintenance.Data.Entities;
public sealed class FeatureFlagEntity
{
public Guid Id { get; set; }
public string Key { get; set; } = string.Empty;
public bool Enabled { get; set; }
public string Scope { get; set; } = "global";
}
+7
View File
@@ -0,0 +1,7 @@
namespace maintenance.Data.Entities;
public sealed class GroupLookupEntity
{
public string GroupClaimValue { get; set; } = string.Empty;
public string DisplayName { get; set; } = string.Empty;
}
+10
View File
@@ -0,0 +1,10 @@
namespace maintenance.Data.Entities;
public sealed class MaintenanceWindowEntity
{
public Guid Id { get; set; }
public string? AppId { get; set; }
public DateTime StartTimeEastern { get; set; }
public DateTime EndTimeEastern { get; set; }
public bool HideSupportContactDuringWindow { get; set; }
}
+11
View File
@@ -0,0 +1,11 @@
namespace maintenance.Data.Entities;
public sealed class PermissionRuleEntity
{
public Guid Id { get; set; }
public string PermissionKey { get; set; } = string.Empty;
public Guid GroupId { get; set; }
public string Effect { get; set; } = "allow";
public AuthorizationGroupEntity? Group { get; set; }
}
+12
View File
@@ -0,0 +1,12 @@
namespace maintenance.Data.Entities;
public sealed class TemplateEntity
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public string? SupportContactBlock { get; set; }
public string LastUpdatedBy { get; set; } = string.Empty;
public DateTime LastUpdatedAtUtc { get; set; }
}
+46
View File
@@ -0,0 +1,46 @@
using maintenance.Data.Entities;
using Microsoft.EntityFrameworkCore;
namespace maintenance.Data;
public sealed class GroupLookupDbContext : DbContext
{
public GroupLookupDbContext(DbContextOptions<GroupLookupDbContext> options) : base(options)
{
}
public DbSet<GroupLookupEntity> Groups => Set<GroupLookupEntity>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<GroupLookupEntity>(e =>
{
e.ToTable("GroupLookup");
e.HasKey(x => x.GroupClaimValue);
e.Property(x => x.GroupClaimValue).HasMaxLength(256).IsRequired();
e.Property(x => x.DisplayName).HasMaxLength(256).IsRequired();
});
}
public override int SaveChanges()
{
throw new NotSupportedException("GroupLookupDbContext is read-only.");
}
public override int SaveChanges(bool acceptAllChangesOnSuccess)
{
throw new NotSupportedException("GroupLookupDbContext is read-only.");
}
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
throw new NotSupportedException("GroupLookupDbContext is read-only.");
}
public override Task<int> SaveChangesAsync(
bool acceptAllChangesOnSuccess,
CancellationToken cancellationToken = default)
{
throw new NotSupportedException("GroupLookupDbContext is read-only.");
}
}