using Microsoft.EntityFrameworkCore; using HyperBooru.Services; using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; namespace HyperBooru; public class HBContext : 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 HBContext(DbContextOptions options, IConfigService config) : base(options) => 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}"); #if DEBUG options.EnableSensitiveDataLogging(); #endif } 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 TagDefinition[] { new() { ObjectId = -1, Source = TagSource.Internal, Name = "nsfw" }, new() { ObjectId = -2, Source = TagSource.Internal, Name = "ingest" } }); modelBuilder.Entity() .HasMany(e => e.ImplicitTags) .WithMany(); } }