feat(news): dynamic settings, IFinlyticLogger, live log streaming, and EF migration
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user