using Microsoft.EntityFrameworkCore; using System.Text.Json; namespace HyperBooru; public class HyperBooruDbContext : DbContext { public DbSet Objects { get; set; } public DbSet TagDefinitions { get; set; } public DbSet Tags { get; set; } public DbSet Media { get; set; } public DbSet UploadedFiles { get; set; } private IConfigService config; public HyperBooruDbContext(IConfigService config) => this.config = config; protected override void OnConfiguring(DbContextOptionsBuilder options) { options.UseLazyLoadingProxies(); var path = Path.Join(config.DataPath, "HyperBooru.db"); options.UseSqlite($"Data Source = {config.DbPath}"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().ToTable("Objects"); modelBuilder.Entity().ToTable("TagDefinitions"); modelBuilder.Entity().ToTable("Tags"); modelBuilder.Entity().ToTable("Media"); modelBuilder.Entity().ToTable("UploadedFiles"); modelBuilder.Entity().HasData(new DbTagDefinition[] { new() { ObjectId = -1, Source = TagSource.Internal, Name = "nsfw" }, new() { ObjectId = -2, Source = TagSource.Internal, Name = "ingest" } }); } }