blob: 3a9aa0f43e321dc6872f92816bfea6e7925b75b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
using Microsoft.EntityFrameworkCore;
using System.Text.Json;
namespace HyperBooru;
public class HyperBooruDbContext : DbContext {
public DbSet<DbObject> Objects { get; set; }
public DbSet<DbTagDefinition> TagDefinitions { get; set; }
public DbSet<DbTag> Tags { get; set; }
public DbSet<DbMedia> Media { get; set; }
public DbSet<DbUploadedFile> UploadedFiles { get; set; }
private IConfigService config;
public HyperBooruDbContext(IConfigService config) =>
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}");
}
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.Entity<DbObject>().ToTable("Objects");
modelBuilder.Entity<DbTagDefinition>().ToTable("TagDefinitions");
modelBuilder.Entity<DbTag>().ToTable("Tags");
modelBuilder.Entity<DbMedia>().ToTable("Media");
modelBuilder.Entity<DbUploadedFile>().ToTable("UploadedFiles");
modelBuilder.Entity<DbTagDefinition>().HasData(new DbTagDefinition[] {
new() { ObjectId = -1, Source = TagSource.Internal, Name = "nsfw" },
new() { ObjectId = -2, Source = TagSource.Internal, Name = "ingest" }
});
}
}
|