using FinlyticAnalyzer.Entities; using FinlyticCore.Database; using FinlyticCore.Entities.Settings; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; namespace FinlyticAnalyzer.Database; public class AnalyzerDbContext : DbContext, ISettingsDbContext { public AnalyzerDbContext(DbContextOptions options) : base(options) { } public DbSet DynamicSettings => Set(); public DbSet Analyses => Set(); public DbSet Settings => Set(); public DbSet TradeProposals => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity(entity => { entity.HasKey(e => e.Id); entity.HasIndex(e => e.Key).IsUnique(); }); modelBuilder.Entity(entity => { entity.HasIndex(e => e.AnalysisId).IsUnique(); entity.HasIndex(e => e.EventId); entity.HasIndex(e => e.Isin); entity.HasIndex(e => e.Sector); entity.HasIndex(e => e.CreatedAt); }); modelBuilder.Entity(entity => { entity.HasIndex(e => e.Isin); entity.HasIndex(e => e.ExpiresAt); }); } } public class AnalyzerDbContextFactory : IDesignTimeDbContextFactory { public AnalyzerDbContext CreateDbContext(string[] args) { var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseNpgsql("Host=localhost;Database=analyzer;Username=postgres;Password=postgres"); return new AnalyzerDbContext(optionsBuilder.Options); } }