continuity/Server/DB/WonderkingContext.cs

38 lines
1.4 KiB
C#
Raw Normal View History

namespace Server.DB;
2023-08-10 08:47:35 +00:00
2023-08-14 11:49:27 +00:00
using System.Data.Common;
using Documents;
2023-08-14 11:49:27 +00:00
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Npgsql;
2023-08-10 08:47:35 +00:00
2023-08-14 11:49:27 +00:00
public class WonderkingContext : DbContext
2023-08-10 08:47:35 +00:00
{
2023-08-14 11:49:27 +00:00
private readonly ILoggerFactory loggerFactory;
private readonly IConfiguration configuration;
public WonderkingContext(ILoggerFactory loggerFactory, IConfiguration configuration)
2023-08-10 08:47:35 +00:00
{
2023-08-14 11:49:27 +00:00
this.loggerFactory = loggerFactory;
this.configuration = configuration;
2023-08-10 08:47:35 +00:00
}
2023-08-14 11:49:27 +00:00
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) =>
optionsBuilder
.UseNpgsql(
$"Host={this.configuration["DB:Host"]};Username={this.configuration["DB:Username"]};Password={this.configuration["DB:Password"]};Database={this.configuration["DB:Database"]};Port={this.configuration["DB:Port"]}")
.EnableSensitiveDataLogging().UseLoggerFactory(this.loggerFactory);
protected override void OnModelCreating(ModelBuilder modelBuilder) =>
modelBuilder.Entity<Account>(builder =>
{
builder.Property(b => b.Username).HasColumnType("varchar(20)");
builder.Property(b => b.Password).HasColumnType("bytea");
builder.Property(b => b.Salt).HasColumnType("bytea");
builder.HasKey(b => b.Id);
});
public DbSet<Account> Accounts { get; set; }
2023-08-11 09:31:30 +00:00
}