From a8b0291ebf751b28f0794014deb119f98493cf38 Mon Sep 17 00:00:00 2001 From: max Date: Tue, 2 Sep 2025 16:17:47 +0200 Subject: [PATCH] [DB] Update migrations for datetime update --- Manager.App/Manager.App.csproj | 1 + Manager.App/Services/System/ClientManager.cs | 9 +++++++-- Manager.App/Services/System/SystemService.cs | 12 ++++++++++++ Manager.Data/Contexts/LibraryDbContext.cs | 1 + ... 20250902141251_InitialLibrary.Designer.cs} | 18 +++++++++++++++--- ...ary.cs => 20250902141251_InitialLibrary.cs} | 12 ++++++++---- .../LibraryDbContextModelSnapshot.cs | 16 ++++++++++++++-- 7 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 Manager.App/Services/System/SystemService.cs rename Manager.Data/Migrations/{20250902133345_InitialLibrary.Designer.cs => 20250902141251_InitialLibrary.Designer.cs} (96%) rename Manager.Data/Migrations/{20250902133345_InitialLibrary.cs => 20250902141251_InitialLibrary.cs} (95%) diff --git a/Manager.App/Manager.App.csproj b/Manager.App/Manager.App.csproj index 36dbce5..9147f6a 100644 --- a/Manager.App/Manager.App.csproj +++ b/Manager.App/Manager.App.csproj @@ -31,6 +31,7 @@ + diff --git a/Manager.App/Services/System/ClientManager.cs b/Manager.App/Services/System/ClientManager.cs index 19c6a37..8cb55fa 100644 --- a/Manager.App/Services/System/ClientManager.cs +++ b/Manager.App/Services/System/ClientManager.cs @@ -8,21 +8,26 @@ namespace Manager.App.Services.System; public class ClientManager : BackgroundService { private readonly List _clients = []; - private bool _cancelled; + private CancellationToken _cancellationToken; protected override async Task ExecuteAsync(CancellationToken stoppingToken) { + _cancellationToken = stoppingToken; stoppingToken.Register(CancellationRequested); } private void CancellationRequested() { - _cancelled = true; // Clear up } public async Task> LoadClient(ClientAccountEntity accountEntity) { + if (_cancellationToken.IsCancellationRequested) + { + return ResultError.Fail("Service is shutting down."); + } + var container = new CookieContainer(); if (accountEntity.HttpCookies.Count != 0) diff --git a/Manager.App/Services/System/SystemService.cs b/Manager.App/Services/System/SystemService.cs new file mode 100644 index 0000000..77f3a9a --- /dev/null +++ b/Manager.App/Services/System/SystemService.cs @@ -0,0 +1,12 @@ +namespace Manager.App.Services.System; + +public class SystemService : BackgroundService +{ + private CancellationToken _cancellationToken { get; set; } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + _cancellationToken = stoppingToken; + } + +} \ No newline at end of file diff --git a/Manager.Data/Contexts/LibraryDbContext.cs b/Manager.Data/Contexts/LibraryDbContext.cs index 2584cbd..51c1b3b 100644 --- a/Manager.Data/Contexts/LibraryDbContext.cs +++ b/Manager.Data/Contexts/LibraryDbContext.cs @@ -11,6 +11,7 @@ public sealed class LibraryDbContext : DbContext { ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; ChangeTracker.LazyLoadingEnabled = false; + Database.EnsureCreated(); } public DbSet Captions { get; set; } diff --git a/Manager.Data/Migrations/20250902133345_InitialLibrary.Designer.cs b/Manager.Data/Migrations/20250902141251_InitialLibrary.Designer.cs similarity index 96% rename from Manager.Data/Migrations/20250902133345_InitialLibrary.Designer.cs rename to Manager.Data/Migrations/20250902141251_InitialLibrary.Designer.cs index e24e45d..b850f99 100644 --- a/Manager.Data/Migrations/20250902133345_InitialLibrary.Designer.cs +++ b/Manager.Data/Migrations/20250902141251_InitialLibrary.Designer.cs @@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Manager.Data.Migrations { [DbContext(typeof(LibraryDbContext))] - [Migration("20250902133345_InitialLibrary")] + [Migration("20250902141251_InitialLibrary")] partial class InitialLibrary { /// @@ -30,6 +30,12 @@ namespace Manager.Data.Migrations .HasMaxLength(100) .HasColumnType("TEXT"); + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("LastModifiedUtc") + .HasColumnType("TEXT"); + b.Property("Name") .IsRequired() .HasMaxLength(100) @@ -157,10 +163,10 @@ namespace Manager.Data.Migrations .HasMaxLength(100) .HasColumnType("TEXT"); - b.Property("DateAddedUtc") + b.Property("CreatedAtUtc") .HasColumnType("TEXT"); - b.Property("DateModifiedUtc") + b.Property("LastModifiedUtc") .HasColumnType("TEXT"); b.HasKey("PlaylistId", "MediaId"); @@ -242,6 +248,9 @@ namespace Manager.Data.Migrations b.Property("ContentLengthBytes") .HasColumnType("INTEGER"); + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + b.Property("Framerate") .HasColumnType("REAL"); @@ -254,6 +263,9 @@ namespace Manager.Data.Migrations b.Property("LastModifiedUnixEpoch") .HasColumnType("INTEGER"); + b.Property("LastModifiedUtc") + .HasColumnType("TEXT"); + b.Property("LoudnessDb") .HasColumnType("REAL"); diff --git a/Manager.Data/Migrations/20250902133345_InitialLibrary.cs b/Manager.Data/Migrations/20250902141251_InitialLibrary.cs similarity index 95% rename from Manager.Data/Migrations/20250902133345_InitialLibrary.cs rename to Manager.Data/Migrations/20250902141251_InitialLibrary.cs index ca8be1b..be499c7 100644 --- a/Manager.Data/Migrations/20250902133345_InitialLibrary.cs +++ b/Manager.Data/Migrations/20250902141251_InitialLibrary.cs @@ -131,7 +131,9 @@ namespace Manager.Data.Migrations { MediaId = table.Column(type: "TEXT", maxLength: 100, nullable: false), LanguageCode = table.Column(type: "TEXT", maxLength: 100, nullable: false), - Name = table.Column(type: "TEXT", maxLength: 100, nullable: false) + Name = table.Column(type: "TEXT", maxLength: 100, nullable: false), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false), + LastModifiedUtc = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -164,7 +166,9 @@ namespace Manager.Data.Migrations QualityLabel = table.Column(type: "TEXT", maxLength: 100, nullable: true), AudioChannels = table.Column(type: "INTEGER", nullable: true), AudioSampleRate = table.Column(type: "TEXT", maxLength: 100, nullable: true), - LoudnessDb = table.Column(type: "REAL", nullable: true) + LoudnessDb = table.Column(type: "REAL", nullable: true), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false), + LastModifiedUtc = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -183,8 +187,8 @@ namespace Manager.Data.Migrations { PlaylistId = table.Column(type: "TEXT", maxLength: 100, nullable: false), MediaId = table.Column(type: "TEXT", maxLength: 100, nullable: false), - DateAddedUtc = table.Column(type: "TEXT", nullable: false), - DateModifiedUtc = table.Column(type: "TEXT", nullable: false) + CreatedAtUtc = table.Column(type: "TEXT", nullable: false), + LastModifiedUtc = table.Column(type: "TEXT", nullable: false) }, constraints: table => { diff --git a/Manager.Data/Migrations/LibraryDbContextModelSnapshot.cs b/Manager.Data/Migrations/LibraryDbContextModelSnapshot.cs index 586c94a..773b010 100644 --- a/Manager.Data/Migrations/LibraryDbContextModelSnapshot.cs +++ b/Manager.Data/Migrations/LibraryDbContextModelSnapshot.cs @@ -27,6 +27,12 @@ namespace Manager.Data.Migrations .HasMaxLength(100) .HasColumnType("TEXT"); + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("LastModifiedUtc") + .HasColumnType("TEXT"); + b.Property("Name") .IsRequired() .HasMaxLength(100) @@ -154,10 +160,10 @@ namespace Manager.Data.Migrations .HasMaxLength(100) .HasColumnType("TEXT"); - b.Property("DateAddedUtc") + b.Property("CreatedAtUtc") .HasColumnType("TEXT"); - b.Property("DateModifiedUtc") + b.Property("LastModifiedUtc") .HasColumnType("TEXT"); b.HasKey("PlaylistId", "MediaId"); @@ -239,6 +245,9 @@ namespace Manager.Data.Migrations b.Property("ContentLengthBytes") .HasColumnType("INTEGER"); + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + b.Property("Framerate") .HasColumnType("REAL"); @@ -251,6 +260,9 @@ namespace Manager.Data.Migrations b.Property("LastModifiedUnixEpoch") .HasColumnType("INTEGER"); + b.Property("LastModifiedUtc") + .HasColumnType("TEXT"); + b.Property("LoudnessDb") .HasColumnType("REAL");