mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-01-24 21:58:45 -05:00
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Infrastructure.Configuration;
|
|
|
|
namespace Infrastructure.Events;
|
|
|
|
/// <summary>
|
|
/// Database context for events
|
|
/// </summary>
|
|
public class EventDbContext : DbContext
|
|
{
|
|
public DbSet<Event> Events { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
var dbPath = Path.Combine(ConfigurationPathProvider.GetSettingsPath(), "events.db");
|
|
optionsBuilder.UseSqlite($"Data Source={dbPath}");
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
// Additional configuration if needed
|
|
modelBuilder.Entity<Event>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.Property(e => e.Timestamp).IsRequired();
|
|
entity.Property(e => e.EventType).IsRequired().HasMaxLength(100);
|
|
entity.Property(e => e.Source).IsRequired().HasMaxLength(100);
|
|
entity.Property(e => e.Message).IsRequired().HasMaxLength(1000);
|
|
entity.Property(e => e.Severity).IsRequired().HasMaxLength(20);
|
|
entity.Property(e => e.CorrelationId).HasMaxLength(50);
|
|
});
|
|
}
|
|
} |