Added postgres support (#556)
This commit is contained in:
committed by
Pieter-Jan Briers
parent
f95c5b7921
commit
514d05b237
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user