using FinlyticCore.Database;
using FinlyticCore.Entities.Settings;
using FinlyticSentiment.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace FinlyticSentiment.Database;
///
/// EF Core DbContext for managing FinlyticSentiment settings in PostgreSQL.
///
public class SentimentDbContext : DbContext, ISettingsDbContext
{
public SentimentDbContext(DbContextOptions options) : base(options)
{
}
public DbSet DynamicSettings => Set();
public DbSet Settings => 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.ToTable("sentiment_settings");
entity.HasKey(e => e.Id);
entity.Property(e => e.GermanWebhookUrl).HasMaxLength(500);
entity.Property(e => e.EnglishWebhookUrl).HasMaxLength(500);
});
}
}
public class SentimentDbContextFactory : IDesignTimeDbContextFactory
{
public SentimentDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseNpgsql("Host=localhost;Database=sentiment;Username=postgres;Password=postgres");
return new SentimentDbContext(optionsBuilder.Options);
}
}