From 8b17395c6c23a67517fe8566bc1f4297f1c2bbdd Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Fri, 18 Apr 2025 15:43:40 +0700 Subject: [PATCH 1/3] update to ef 9.0.4 --- backend/Directory.Packages.props | 53 ++++++++++--------- ...elSnapshotTests.VerifyDbModel.verified.txt | 2 +- backend/FwLite/LcmCrdt/LcmCrdt.csproj | 1 + backend/FwLite/LcmDebugger/Program.cs | 1 + backend/harmony | 2 +- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/backend/Directory.Packages.props b/backend/Directory.Packages.props index fd938ffbd..2acd4e983 100644 --- a/backend/Directory.Packages.props +++ b/backend/Directory.Packages.props @@ -16,8 +16,8 @@ - - + + @@ -28,7 +28,7 @@ - + @@ -37,25 +37,26 @@ - - + + + - - - - - - - - - + + + + + + + + + - - - - - - + + + + + + @@ -71,9 +72,9 @@ - - - + + + @@ -110,9 +111,9 @@ - - - + + + diff --git a/backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.VerifyDbModel.verified.txt b/backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.VerifyDbModel.verified.txt index eeff4ac2a..8db9b0fe1 100644 --- a/backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.VerifyDbModel.verified.txt +++ b/backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.VerifyDbModel.verified.txt @@ -370,4 +370,4 @@ Relational:ViewName: Relational:ViewSchema: Annotations: - ProductVersion: 8.0.15 \ No newline at end of file + ProductVersion: 9.0.4 \ No newline at end of file diff --git a/backend/FwLite/LcmCrdt/LcmCrdt.csproj b/backend/FwLite/LcmCrdt/LcmCrdt.csproj index ade1aaebf..2335b4b18 100644 --- a/backend/FwLite/LcmCrdt/LcmCrdt.csproj +++ b/backend/FwLite/LcmCrdt/LcmCrdt.csproj @@ -14,6 +14,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/backend/FwLite/LcmDebugger/Program.cs b/backend/FwLite/LcmDebugger/Program.cs index 7ca0ac736..b684acdde 100644 --- a/backend/FwLite/LcmDebugger/Program.cs +++ b/backend/FwLite/LcmDebugger/Program.cs @@ -7,6 +7,7 @@ using LexCore.Exceptions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Refit; using SIL.Harmony; diff --git a/backend/harmony b/backend/harmony index e758fbebd..cd4b271d6 160000 --- a/backend/harmony +++ b/backend/harmony @@ -1 +1 @@ -Subproject commit e758fbebda4e0f1aba4656ea64b7cda991fde2d2 +Subproject commit cd4b271d68a325fce340d26bd47cda012c52bcbd From 9c79545d9dd4aac0d592d9af90fa6603ddd4db56 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Fri, 18 Apr 2025 16:24:46 +0700 Subject: [PATCH 2/3] update ef tool to version 9.0.4 and update EF Projectables too --- .config/dotnet-tools.json | 2 +- backend/Directory.Packages.props | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 8b0291a0f..b75b95152 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-ef": { - "version": "9.0.0", + "version": "9.0.4", "commands": [ "dotnet-ef" ], diff --git a/backend/Directory.Packages.props b/backend/Directory.Packages.props index 2acd4e983..404cdd454 100644 --- a/backend/Directory.Packages.props +++ b/backend/Directory.Packages.props @@ -11,8 +11,8 @@ - - + + From 916e0787fa9e93b5c376b85be80d1974a9932fff Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Fri, 18 Apr 2025 17:11:49 +0700 Subject: [PATCH 3/3] move AddQuartz into LexBoxDbContext.cs to ensure it's always run and avoid Pending model change warnings --- backend/LexBoxApi/LexBoxApi.csproj | 1 - backend/LexBoxApi/ScheduledTasksKernel.cs | 4 ---- backend/LexData/DbStartupService.cs | 26 +++++++++++++++++++++++ backend/LexData/LexBoxDbContext.cs | 4 +++- backend/LexData/LexData.csproj | 3 ++- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/backend/LexBoxApi/LexBoxApi.csproj b/backend/LexBoxApi/LexBoxApi.csproj index 6f06e2987..24a6411c6 100644 --- a/backend/LexBoxApi/LexBoxApi.csproj +++ b/backend/LexBoxApi/LexBoxApi.csproj @@ -6,7 +6,6 @@ 1 - diff --git a/backend/LexBoxApi/ScheduledTasksKernel.cs b/backend/LexBoxApi/ScheduledTasksKernel.cs index 45372a712..60bfcef4d 100644 --- a/backend/LexBoxApi/ScheduledTasksKernel.cs +++ b/backend/LexBoxApi/ScheduledTasksKernel.cs @@ -16,10 +16,6 @@ public static class ScheduledTasksKernel { public static void AddScheduledTasks(this IServiceCollection services, IConfiguration configuration) { - services.ConfigureDbModel(builder => - { - builder.AddQuartz(b => b.UsePostgreSql()); - }); services.AddQuartz(q => { q.UsePersistentStore(options => diff --git a/backend/LexData/DbStartupService.cs b/backend/LexData/DbStartupService.cs index 6e5db1b6a..bb61c57ab 100644 --- a/backend/LexData/DbStartupService.cs +++ b/backend/LexData/DbStartupService.cs @@ -1,6 +1,9 @@ using System.Diagnostics; using System.Net.Sockets; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -59,6 +62,7 @@ private async Task TryMigrate(DbContext dbContext, CancellationToken cance { try { + // there's a method to check if we can connect, but that won't work when the database is not created yet. await dbContext.Database.MigrateAsync(cancellationToken); return true; @@ -84,6 +88,28 @@ private async Task TryMigrate(DbContext dbContext, CancellationToken cance } } + //this is mostly just for debugging diffs + private void DetermineModelDiffs(DbContext dbContext) + { + var migrationsAssembly = dbContext.Database.GetService(); + var designTimeModel = dbContext.Database.GetService(); + var modelRuntimeInitializer = dbContext.Database.GetService(); + var migrationsModelDiffer = dbContext.Database.GetService(); + var diffs = migrationsModelDiffer.GetDifferences( + modelRuntimeInitializer.Initialize(migrationsAssembly.ModelSnapshot!.Model).GetRelationalModel(), + designTimeModel.Model.GetRelationalModel()); + if (diffs.Count > 0) + { + foreach (var migrationOperation in diffs) + { + _logger.LogInformation("Model Diffs:{Diff}", migrationOperation); + } + } + else + { + _logger.LogInformation("No model diffs"); + } + } public Task StopAsync(CancellationToken cancellationToken) { return Task.CompletedTask; diff --git a/backend/LexData/LexBoxDbContext.cs b/backend/LexData/LexBoxDbContext.cs index cdca48abc..72a9b954a 100644 --- a/backend/LexData/LexBoxDbContext.cs +++ b/backend/LexData/LexBoxDbContext.cs @@ -1,3 +1,5 @@ +using AppAny.Quartz.EntityFrameworkCore.Migrations; +using AppAny.Quartz.EntityFrameworkCore.Migrations.PostgreSQL; using LexCore.Entities; using LexData.Configuration; using Microsoft.EntityFrameworkCore; @@ -12,9 +14,9 @@ public class LexBoxDbContext(DbContextOptions options, IEnumera protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.HasCollation(CaseInsensitiveCollation, locale: "und-u-ks-level2", provider: "icu", deterministic: false); modelBuilder.ApplyConfigurationsFromAssembly(typeof(EntityBaseConfiguration<>).Assembly); + modelBuilder.AddQuartz(b => b.UsePostgreSql()); foreach (var configureDbModel in _configureDbModels) { configureDbModel.Configure(modelBuilder); diff --git a/backend/LexData/LexData.csproj b/backend/LexData/LexData.csproj index f7b2d2ac4..82c286cc2 100644 --- a/backend/LexData/LexData.csproj +++ b/backend/LexData/LexData.csproj @@ -1,5 +1,6 @@ + @@ -20,4 +21,4 @@ - \ No newline at end of file +