46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using System;
|
|
using FinlyticBot.Entities;
|
|
using FinlyticCore.Database;
|
|
using FinlyticCore.Entities.Settings;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace FinlyticBot.Database;
|
|
|
|
public class BotDbContext : DbContext, ISettingsDbContext
|
|
{
|
|
public BotDbContext(DbContextOptions<BotDbContext> options) : base(options) { }
|
|
|
|
public DbSet<SettingEntity> DynamicSettings => Set<SettingEntity>();
|
|
public DbSet<ExecutedPaperTradeEntity> ExecutedPaperTrades => Set<ExecutedPaperTradeEntity>();
|
|
public DbSet<BotAuditLogEntity> BotAuditLogs => Set<BotAuditLogEntity>();
|
|
|
|
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<ExecutedPaperTradeEntity>(entity =>
|
|
{
|
|
entity.HasIndex(e => e.TradeId).IsUnique();
|
|
entity.HasIndex(e => e.Symbol);
|
|
entity.HasIndex(e => e.Isin);
|
|
entity.HasIndex(e => e.AlpacaOrderId);
|
|
entity.HasIndex(e => e.Status);
|
|
entity.HasIndex(e => e.PlacedAt);
|
|
});
|
|
|
|
modelBuilder.Entity<BotAuditLogEntity>(entity =>
|
|
{
|
|
entity.HasIndex(e => e.TradeId);
|
|
entity.HasIndex(e => e.Symbol);
|
|
entity.HasIndex(e => e.Action);
|
|
entity.HasIndex(e => e.Timestamp);
|
|
});
|
|
}
|
|
}
|