forked from Erisa/Cliptok
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.cs
More file actions
40 lines (34 loc) · 1.32 KB
/
Database.cs
File metadata and controls
40 lines (34 loc) · 1.32 KB
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
38
39
40
using Microsoft.EntityFrameworkCore;
namespace Cliptok
{
public class CliptokDbContext : DbContext
{
private readonly string _connectionString;
private readonly bool _usePostgres;
public DbSet<Models.CachedDiscordMessage> Messages { get; set; }
public DbSet<Models.CachedDiscordUser> Users { get; set; }
public DbSet<Models.BulkMessageLogStore> BulkMessageLogStore { get; set; }
public DbSet<Models.CachedDiscordSticker> Stickers { get; set; }
public CliptokDbContext()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
#if DEBUG
optionsBuilder.EnableSensitiveDataLogging(true);
optionsBuilder.EnableDetailedErrors(true);
#endif
bool usePostgres = Environment.GetEnvironmentVariable("CLIPTOK_POSTGRES") is not null;
if (usePostgres)
optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CLIPTOK_POSTGRES"));
else
{
throw new ArgumentException("Persistent database enabled but no database connection string provided. Set CLIPTOK_POSTGRES environment variable.");
}
}
}
}
}