diff options
Diffstat (limited to 'HBContext.cs')
| -rw-r--r-- | HBContext.cs | 10 |
1 files changed, 6 insertions, 4 deletions
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<HBObject>().ToTable("Objects"); modelBuilder.Entity<TagDefinition>().ToTable("TagDefinitions"); modelBuilder.Entity<Tag>().ToTable("Tags"); modelBuilder.Entity<Media>().ToTable("Media"); modelBuilder.Entity<UploadedFile>().ToTable("UploadedFiles"); + // Seed internal tag definitions + // These should NEVER change modelBuilder.Entity<TagDefinition>().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<TagDefinition>() .HasMany(e => e.ImplicitTags) .WithMany(); |
