Updated Db models

This commit is contained in:
Toastie 2024-07-07 14:27:42 +12:00
parent 62319ebb1a
commit 56d82a5a26
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
2 changed files with 30 additions and 30 deletions
src/EllieBot/Db

View file

@ -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;