forked from EllieBotDevs/elliebot
Updated Db models
This commit is contained in:
parent
5e7c75a498
commit
c5cd772126
7 changed files with 39 additions and 36 deletions
src/EllieBot/Db
|
@ -4,14 +4,14 @@ using Microsoft.EntityFrameworkCore;
|
|||
|
||||
namespace EllieBot.Db;
|
||||
|
||||
public sealed class EllieDbService : DbService
|
||||
public sealed class EllieDbService : DbService
|
||||
{
|
||||
private readonly IBotCredsProvider _creds;
|
||||
|
||||
// these are props because creds can change at runtime
|
||||
private string DbType => _creds.GetCreds().Db.Type.ToLowerInvariant().Trim();
|
||||
private string ConnString => _creds.GetCreds().Db.ConnectionString;
|
||||
|
||||
|
||||
public EllieDbService(IBotCredsProvider creds)
|
||||
{
|
||||
LinqToDBForEFTools.Initialize();
|
||||
|
@ -26,13 +26,13 @@ public sealed class EllieDbService : DbService
|
|||
var connString = ConnString;
|
||||
|
||||
await using var context = CreateRawDbContext(dbType, connString);
|
||||
|
||||
|
||||
// make sure sqlite db is in wal journal mode
|
||||
if (context is SqliteContext)
|
||||
{
|
||||
await context.Database.ExecuteSqlRawAsync("PRAGMA journal_mode=WAL");
|
||||
}
|
||||
|
||||
|
||||
await context.Database.MigrateAsync();
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public sealed class EllieDbService : DbService
|
|||
throw new NotSupportedException($"The database provide type of '{dbType}' is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private EllieContext GetDbContextInternal()
|
||||
{
|
||||
var dbType = DbType;
|
||||
|
|
Reference in a new issue