-
Notifications
You must be signed in to change notification settings - Fork 10
/
DatabaseContext.cs
34 lines (29 loc) · 1.15 KB
/
DatabaseContext.cs
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
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using MinecraftServerDiscoveryApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MinecraftServerDiscoveryApi.Contexts
{
public class DatabaseContext : DbContext
{
public DbSet<GeoInformation> GeoInformation { get; set; }
public DbSet<Player> Players { get; set; }
public DbSet<Server> Servers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var dbString = Environment.GetEnvironmentVariable("MINECRAFT_DISCOVERY_DB");
if (string.IsNullOrWhiteSpace(dbString))
{
throw new MissingFieldException("Database environment variable not found.");
}
optionsBuilder.UseMySql(dbString, ServerVersion.AutoDetect(dbString));
optionsBuilder.LogTo(Console.WriteLine, LogLevel.Information);
optionsBuilder.EnableSensitiveDataLogging();
optionsBuilder.EnableDetailedErrors();
base.OnConfiguring(optionsBuilder);
}
}
}