using Microsoft.EntityFrameworkCore; using YarpGateway.Models; namespace YarpGateway.Data; public class GatewayDbContext : DbContext { public GatewayDbContext(DbContextOptions options) : base(options) { } public DbSet Tenants => Set(); public DbSet TenantRoutes => Set(); public DbSet ServiceInstances => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { entity.HasKey(e => e.Id); entity.Property(e => e.TenantCode).HasMaxLength(50).IsRequired(); entity.Property(e => e.TenantName).HasMaxLength(100).IsRequired(); entity.HasIndex(e => e.TenantCode).IsUnique(); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.Id); entity.Property(e => e.TenantCode).HasMaxLength(50); entity.Property(e => e.ServiceName).HasMaxLength(100).IsRequired(); entity.Property(e => e.ClusterId).HasMaxLength(100).IsRequired(); entity.Property(e => e.PathPattern).HasMaxLength(200).IsRequired(); entity.HasIndex(e => e.TenantCode); entity.HasIndex(e => e.ServiceName); entity.HasIndex(e => e.ClusterId); entity.HasIndex(e => new { e.ServiceName, e.IsGlobal, e.Status }); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.Id); entity.Property(e => e.ClusterId).HasMaxLength(100).IsRequired(); entity.Property(e => e.DestinationId).HasMaxLength(100).IsRequired(); entity.Property(e => e.Address).HasMaxLength(200).IsRequired(); entity.HasIndex(e => new { e.ClusterId, e.DestinationId }).IsUnique(); entity.HasIndex(e => e.Health); }); base.OnModelCreating(modelBuilder); } }