Added postgres support (#556)

This commit is contained in:
DamianX
2020-01-24 17:25:01 +01:00
committed by Pieter-Jan Briers
parent f95c5b7921
commit 514d05b237
19 changed files with 566 additions and 43 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
@@ -7,12 +8,15 @@ namespace Content.Server.Database
{
private readonly PreferencesDbContext _prefsCtx;
public PrefsDb(string dbPath)
public PrefsDb(IDatabaseConfiguration dbConfig)
{
var optionsBuilder = new DbContextOptionsBuilder<PreferencesDbContext>();
optionsBuilder.UseSqlite($"Data Source={dbPath}");
_prefsCtx = new PreferencesDbContext(optionsBuilder.Options);
_prefsCtx = dbConfig switch
{
SqliteConfiguration sqlite => (PreferencesDbContext) new SqlitePreferencesDbContext(
sqlite.Options),
PostgresConfiguration postgres => new PostgresPreferencesDbContext(postgres.Options),
_ => throw new NotImplementedException()
};
_prefsCtx.Database.Migrate();
}