Browse Source

add some database startup logging (#2409)

* add some database startup logging

* fix unscheduled playout gap offset

* fix database logging
pull/2410/head
Jason Dove 4 months ago committed by GitHub
parent
commit
3722bc8c9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      ErsatzTV.Application/Playouts/Queries/GetFuturePlayoutItemsByIdHandler.cs
  2. 21
      ErsatzTV/Services/RunOnce/DatabaseMigratorService.cs

4
ErsatzTV.Application/Playouts/Queries/GetFuturePlayoutItemsByIdHandler.cs

@ -108,8 +108,8 @@ public class GetFuturePlayoutItemsByIdHandler(IDbContextFactory<TvContext> dbCon @@ -108,8 +108,8 @@ public class GetFuturePlayoutItemsByIdHandler(IDbContextFactory<TvContext> dbCon
TimeSpan gapDuration = gap.Finish - gap.Start;
return new PlayoutItemViewModel(
"UNSCHEDULED",
gap.Start,
gap.Finish,
gap.StartOffset,
gap.FinishOffset,
TimeSpan.FromSeconds(Math.Round(gapDuration.TotalSeconds)).ToString(
gapDuration.TotalHours >= 1 ? @"h\:mm\:ss" : @"mm\:ss",
CultureInfo.CurrentUICulture.DateTimeFormat),

21
ErsatzTV/Services/RunOnce/DatabaseMigratorService.cs

@ -33,8 +33,20 @@ public class DatabaseMigratorService : BackgroundService @@ -33,8 +33,20 @@ public class DatabaseMigratorService : BackgroundService
if (TvContext.IsSqlite)
{
// sqlite migrations lock is always stale since mutex ensures single instance of etv
await dbContext.Database.ExecuteSqlRawAsync("DROP TABLE IF EXISTS `__EFMigrationsLock`", stoppingToken);
int count = await dbContext.Connection.ExecuteScalarAsync<int>(
"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='__EFMigrationsLock'");
if (count > 0)
{
count = await dbContext.Connection.ExecuteScalarAsync<int>("SELECT count(*) FROM `__EFMigrationsLock`");
if (count > 0)
{
_logger.LogWarning(
"Cleaning database migrations lock; this is needed when ETV is terminated during a database migration.");
// sqlite migrations lock is always stale since mutex ensures single instance of etv
await dbContext.Database.ExecuteSqlRawAsync("DELETE FROM `__EFMigrationsLock`", stoppingToken);
}
}
}
List<string> pendingMigrations = await dbContext.Database
@ -59,6 +71,7 @@ public class DatabaseMigratorService : BackgroundService @@ -59,6 +71,7 @@ public class DatabaseMigratorService : BackgroundService
// then continue migrating
await dbContext.Database.MigrateAsync(stoppingToken);
_logger.LogInformation("Initializing database");
await DbInitializer.Initialize(dbContext, stoppingToken);
_systemStartup.DatabaseIsReady();
@ -66,7 +79,7 @@ public class DatabaseMigratorService : BackgroundService @@ -66,7 +79,7 @@ public class DatabaseMigratorService : BackgroundService
_logger.LogInformation("Done applying database migrations");
}
private static async Task PopulatePathHashes(TvContext dbContext)
private async Task PopulatePathHashes(TvContext dbContext)
{
if (await dbContext.Connection.ExecuteScalarAsync<int>(
"SELECT COUNT(*) FROM `MediaFile` WHERE `PathHash` IS NULL OR `PathHash` = ''") == 0)
@ -74,6 +87,8 @@ public class DatabaseMigratorService : BackgroundService @@ -74,6 +87,8 @@ public class DatabaseMigratorService : BackgroundService
return;
}
_logger.LogInformation("Populating database path hashes");
if (dbContext.Connection is SqliteConnection sqliteConnection)
{
sqliteConnection.CreateFunction("HASH_SHA256", (string text) => PathUtils.GetPathHash(text));

Loading…
Cancel
Save