From 7dcc15cb52c29cc1c0112e3af2cf985b26cd7653 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Thu, 17 Aug 2023 13:54:01 +1000 Subject: Fixed implicit tagging completely and switched DB to PostgreSQL --- HBContext.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'HBContext.cs') diff --git a/HBContext.cs b/HBContext.cs index 162a2c7..04f2d1a 100644 --- a/HBContext.cs +++ b/HBContext.cs @@ -1,6 +1,5 @@ using Microsoft.EntityFrameworkCore; using HyperBooru.Services; -using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; namespace HyperBooru; @@ -18,9 +17,7 @@ public class HBContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder options) { options.UseLazyLoadingProxies(); - - var path = Path.Join(config.DataPath, "HyperBooru.db"); - options.UseSqlite($"Data Source = {config.DbPath}"); + options.UseNpgsql(config.DbConnectionString); #if DEBUG options.EnableSensitiveDataLogging(); @@ -28,17 +25,22 @@ public class HBContext : DbContext { } protected override void OnModelCreating(ModelBuilder modelBuilder) { + // Don't use shared tables for inherited types modelBuilder.Entity().ToTable("Objects"); modelBuilder.Entity().ToTable("TagDefinitions"); modelBuilder.Entity().ToTable("Tags"); modelBuilder.Entity().ToTable("Media"); modelBuilder.Entity().ToTable("UploadedFiles"); + // Seed internal tag definitions + // These should NEVER change modelBuilder.Entity().HasData(new TagDefinition[] { new() { ObjectId = -1, Source = TagSource.Internal, Name = "nsfw" }, new() { ObjectId = -2, Source = TagSource.Internal, Name = "ingest" } }); + // Implicit tags need some special attention to make many<->many + // navigations work for the same object type. modelBuilder.Entity() .HasMany(e => e.ImplicitTags) .WithMany(); -- cgit v1.3