54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
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<AnalyzerDbContext> options) : base(options) { }
|
|
|
|
public DbSet<SettingEntity> DynamicSettings => Set<SettingEntity>();
|
|
public DbSet<AnalysisEntity> Analyses => Set<AnalysisEntity>();
|
|
public DbSet<AnalyzerSettingsEntity> Settings => Set<AnalyzerSettingsEntity>();
|
|
public DbSet<TradeProposalEntity> TradeProposals => Set<TradeProposalEntity>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<SettingEntity>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.HasIndex(e => e.Key).IsUnique();
|
|
});
|
|
|
|
modelBuilder.Entity<AnalysisEntity>(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<TradeProposalEntity>(entity =>
|
|
{
|
|
entity.HasIndex(e => e.Isin);
|
|
entity.HasIndex(e => e.ExpiresAt);
|
|
});
|
|
}
|
|
}
|
|
|
|
public class AnalyzerDbContextFactory : IDesignTimeDbContextFactory<AnalyzerDbContext>
|
|
{
|
|
public AnalyzerDbContext CreateDbContext(string[] args)
|
|
{
|
|
var optionsBuilder = new DbContextOptionsBuilder<AnalyzerDbContext>();
|
|
optionsBuilder.UseNpgsql("Host=localhost;Database=analyzer;Username=postgres;Password=postgres");
|
|
return new AnalyzerDbContext(optionsBuilder.Options);
|
|
}
|
|
}
|