using Microsoft.EntityFrameworkCore; using Moonlight.App.Database.Entities; using Moonlight.App.Database.Entities.LogsEntries; using Moonlight.App.Database.Entities.Notification; using Moonlight.App.Models.Misc; using Moonlight.App.Services; namespace Moonlight.App.Database; public class DataContext : DbContext { private readonly ConfigService ConfigService; public DataContext(ConfigService configService) { ConfigService = configService; } public DbSet DockerImages { get; set; } public DbSet Images { get; set; } public DbSet ImageTags { get; set; } public DbSet ImageVariables { get; set; } public DbSet Nodes { get; set; } public DbSet NodeAllocations { get; set; } public DbSet Servers { get; set; } public DbSet ServerBackups { get; set; } public DbSet ServerVariables { get; set; } public DbSet Users { get; set; } public DbSet LoadingMessages { get; set; } public DbSet AuditLog { get; set; } public DbSet ErrorLog { get; set; } public DbSet SecurityLog { get; set; } public DbSet SupportMessages { get; set; } public DbSet SharedDomains { get; set; } public DbSet Domains { get; set; } public DbSet Revokes { get; set; } public DbSet NotificationClients { get; set; } public DbSet NotificationActions { get; set; } public DbSet DdosAttacks { get; set; } public DbSet Subscriptions { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { var config = ConfigService .GetSection("Moonlight") .GetSection("Database"); var connectionString = $"host={config.GetValue("Host")};" + $"port={config.GetValue("Port")};" + $"database={config.GetValue("Database")};" + $"uid={config.GetValue("Username")};" + $"pwd={config.GetValue("Password")}"; optionsBuilder.UseMySql( connectionString, ServerVersion.Parse("5.7.37-mysql"), builder => { builder.EnableRetryOnFailure(5); } ); } } }