summaryrefslogtreecommitdiff
path: root/HBContext.cs
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2023-08-17 13:54:01 +1000
committerJake Mannens <jake@asger.xyz>2023-08-17 13:54:01 +1000
commita57b6ea2e174cedb04a422a05a180f377ed4c448 (patch)
treecd454fa16c7d37a484268c722b9b57527dad2b4b /HBContext.cs
parent727dcaacc6df8813a9296ac858dd51d11f3737b8 (diff)
Fixed implicit tagging completely and switched DB to PostgreSQL
Diffstat (limited to 'HBContext.cs')
-rw-r--r--HBContext.cs10
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();