35 lines
1.4 KiB
C#
35 lines
1.4 KiB
C#
namespace Server.DB;
|
|
|
|
using Documents;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
public class WonderkingContext : DbContext
|
|
{
|
|
private readonly ILoggerFactory loggerFactory;
|
|
private readonly IConfiguration configuration;
|
|
|
|
public WonderkingContext(ILoggerFactory loggerFactory, IConfiguration configuration)
|
|
{
|
|
this.loggerFactory = loggerFactory;
|
|
this.configuration = configuration;
|
|
}
|
|
|
|
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; }
|
|
}
|