tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
PostgresSqlDatabaseContext.cs
Go to the documentation of this file.
1using System;
2
3using Microsoft.EntityFrameworkCore;
4
6
8{
13 {
15 protected override DeleteBehavior RevInfoCompileJobDeleteBehavior => DeleteBehavior.Cascade;
16
22 DbContextOptions<PostgresSqlDatabaseContext> dbContextOptions)
23 : base(dbContextOptions)
24 {
25 }
26
32 public static void ConfigureWith(DbContextOptionsBuilder options, DatabaseConfiguration databaseConfiguration)
33 {
34 ArgumentNullException.ThrowIfNull(options);
35 ArgumentNullException.ThrowIfNull(databaseConfiguration);
36
37 if (databaseConfiguration.DatabaseType != DatabaseType.PostgresSql)
38 throw new InvalidOperationException($"Invalid DatabaseType for {nameof(PostgresSqlDatabaseContext)}!");
39
40 // Why the fuck is this an AppContext switch
41 AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
42 options.UseNpgsql(databaseConfiguration.ConnectionString, options =>
43 {
44 options.EnableRetryOnFailure();
45 options.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery);
46
47 if (!String.IsNullOrEmpty(databaseConfiguration.ServerVersion))
48 options.SetPostgresVersion(
49 Version.Parse(databaseConfiguration.ServerVersion));
50 });
51 }
52 }
53}
Configuration options for the Database.DatabaseContext.
string? ConnectionString
The connection string for the database.
DatabaseType DatabaseType
The Configuration.DatabaseType to create.
Backend abstract implementation of IDatabaseContext.
PostgresSqlDatabaseContext(DbContextOptions< PostgresSqlDatabaseContext > dbContextOptions)
Initializes a new instance of the PostgresSqlDatabaseContext class.
static void ConfigureWith(DbContextOptionsBuilder options, DatabaseConfiguration databaseConfiguration)
Configure the PostgresSqlDatabaseContext.
DatabaseType
Type of database to user.