feat(news): dynamic settings, IFinlyticLogger, live log streaming, and EF migration

This commit is contained in:
2026-08-15 21:30:01 +02:00
parent a1f2b888f6
commit a94c36a878
12 changed files with 800 additions and 555 deletions
+25 -1
View File
@@ -1,5 +1,8 @@
using FinlyticCore.Database;
using FinlyticCore.Entities.Settings;
using FinlyticNews.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace FinlyticNews.Database;
@@ -7,7 +10,7 @@ namespace FinlyticNews.Database;
/// Entity Framework Core database context for the news microservice,
/// managing article sources, processed news, and matched assets.
/// </summary>
public class NewsDbContext : DbContext
public class NewsDbContext : DbContext, ISettingsDbContext
{
/// <summary>
/// Initializes a new instance of the <see cref="NewsDbContext"/> class.
@@ -17,6 +20,11 @@ public class NewsDbContext : DbContext
{
}
/// <summary>
/// Gets or sets the database set for dynamic settings.
/// </summary>
public DbSet<SettingEntity> DynamicSettings => Set<SettingEntity>();
/// <summary>
/// Gets or sets the database set for configured article sources.
/// </summary>
@@ -45,6 +53,12 @@ public class NewsDbContext : DbContext
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<SettingEntity>(entity =>
{
entity.HasKey(e => e.Id);
entity.HasIndex(e => e.Key).IsUnique();
});
// Configure unique index on SourceUrl for deduplication check (idempotency)
modelBuilder.Entity<NewsArticleEntity>()
.HasIndex(a => a.SourceUrl)
@@ -68,3 +82,13 @@ public class NewsDbContext : DbContext
.OnDelete(DeleteBehavior.Cascade);
}
}
public class NewsDbContextFactory : IDesignTimeDbContextFactory<NewsDbContext>
{
public NewsDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<NewsDbContext>();
optionsBuilder.UseNpgsql("Host=localhost;Database=news;Username=postgres;Password=postgres");
return new NewsDbContext(optionsBuilder.Options);
}
}