Use in-memory SQLite prefs DB when UserData is virtual.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
|
||||
namespace Content.Server.Database
|
||||
@@ -50,9 +51,10 @@ namespace Content.Server.Database
|
||||
|
||||
public class SqliteConfiguration : IDatabaseConfiguration
|
||||
{
|
||||
private readonly string _databaseFilePath;
|
||||
private readonly string? _databaseFilePath;
|
||||
|
||||
public SqliteConfiguration(string databaseFilePath)
|
||||
/// <param name="databaseFilePath">If null, an in-memory database is used.</param>
|
||||
public SqliteConfiguration(string? databaseFilePath)
|
||||
{
|
||||
_databaseFilePath = databaseFilePath;
|
||||
}
|
||||
@@ -62,7 +64,20 @@ namespace Content.Server.Database
|
||||
get
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<PreferencesDbContext>();
|
||||
optionsBuilder.UseSqlite($"Data Source={_databaseFilePath}");
|
||||
SqliteConnection connection;
|
||||
if (_databaseFilePath != null)
|
||||
{
|
||||
connection = new SqliteConnection($"Data Source={_databaseFilePath}");
|
||||
}
|
||||
else
|
||||
{
|
||||
connection = new SqliteConnection("Data Source=:memory:");
|
||||
// When using an in-memory DB we have to open it manually
|
||||
// so EFCore doesn't open, close and wipe it.
|
||||
connection.Open();
|
||||
}
|
||||
|
||||
optionsBuilder.UseSqlite(connection);
|
||||
return optionsBuilder.Options;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user