50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using FinlyticCore.Database;
|
|
using FinlyticCore.Entities.Settings;
|
|
using FinlyticSentiment.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Design;
|
|
|
|
namespace FinlyticSentiment.Database;
|
|
|
|
/// <summary>
|
|
/// EF Core DbContext for managing FinlyticSentiment settings in PostgreSQL.
|
|
/// </summary>
|
|
public class SentimentDbContext : DbContext, ISettingsDbContext
|
|
{
|
|
public SentimentDbContext(DbContextOptions<SentimentDbContext> options) : base(options)
|
|
{
|
|
}
|
|
|
|
public DbSet<SettingEntity> DynamicSettings => Set<SettingEntity>();
|
|
public DbSet<SentimentSettingsEntity> Settings => Set<SentimentSettingsEntity>();
|
|
|
|
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<SentimentSettingsEntity>(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<SentimentDbContext>
|
|
{
|
|
public SentimentDbContext CreateDbContext(string[] args)
|
|
{
|
|
var optionsBuilder = new DbContextOptionsBuilder<SentimentDbContext>();
|
|
optionsBuilder.UseNpgsql("Host=localhost;Database=sentiment;Username=postgres;Password=postgres");
|
|
return new SentimentDbContext(optionsBuilder.Options);
|
|
}
|
|
}
|