using Microsoft.EntityFrameworkCore; using EonaCat.LogStack.Status.Models; using Monitor = EonaCat.LogStack.Status.Models.Monitor; namespace EonaCat.LogStack.Status.Data; // This file is part of the EonaCat project(s) which is released under the Apache License. // See the LICENSE file or go to https://EonaCat.com/License for full license details. public class DatabaseContext : DbContext { public DatabaseContext(DbContextOptions options) : base(options) { } public DbSet Monitors => Set(); public DbSet MonitorChecks => Set(); public DbSet Certificates => Set(); public DbSet Logs => Set(); public DbSet Settings => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().HasIndex(c => new { c.MonitorId, c.CheckedAt }); modelBuilder.Entity().HasIndex(l => l.Timestamp); modelBuilder.Entity().HasIndex(l => new { l.Level, l.Source }); modelBuilder.Entity().HasIndex(s => s.Key).IsUnique(); // Seed default settings modelBuilder.Entity().HasData( new AppSettings { Id = 1, Key = "AdminPasswordHash", Value = BCrypt.Net.BCrypt.EnhancedHashPassword("adminEonaCat") }, new AppSettings { Id = 2, Key = "SiteName", Value = "Status" }, new AppSettings { Id = 3, Key = "ShowLogsPublicly", Value = "false" }, new AppSettings { Id = 4, Key = "ShowUptimePublicly", Value = "true" }, new AppSettings { Id = 5, Key = "MaxLogRetentionDays", Value = "30" }, new AppSettings { Id = 6, Key = "AlertEmail", Value = "" } ); } }