diff options
Diffstat (limited to 'HBContext.cs')
| -rw-r--r-- | HBContext.cs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/HBContext.cs b/HBContext.cs new file mode 100644 index 0000000..17b8b3d --- /dev/null +++ b/HBContext.cs @@ -0,0 +1,41 @@ +using Microsoft.EntityFrameworkCore; +using HyperBooru.Services; + +namespace HyperBooru; + +public class HBContext : DbContext { + public DbSet<HBObject> Objects { get; set; } + public DbSet<TagDefinition> TagDefinitions { get; set; } + public DbSet<Tag> Tags { get; set; } + public DbSet<Media> Media { get; set; } + public DbSet<UploadedFile> UploadedFiles { get; set; } + + private IConfigService config; + + public HBContext(DbContextOptions<HBContext> 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<HBObject>().ToTable("Objects"); + modelBuilder.Entity<TagDefinition>().ToTable("TagDefinitions"); + modelBuilder.Entity<Tag>().ToTable("Tags"); + modelBuilder.Entity<Media>().ToTable("Media"); + modelBuilder.Entity<UploadedFile>().ToTable("UploadedFiles"); + + modelBuilder.Entity<TagDefinition>().HasData(new TagDefinition[] { + new() { ObjectId = -1, Source = TagSource.Internal, Name = "nsfw" }, + new() { ObjectId = -2, Source = TagSource.Internal, Name = "ingest" } + }); + } +}
\ No newline at end of file |
