From ba7cf7029f51335d27cfee61689fad708a8ccf40 Mon Sep 17 00:00:00 2001 From: Robbie Lodico Date: Sat, 14 Oct 2023 22:32:10 -0400 Subject: [PATCH] fix: db upgrade issue on User_Variables column --- .../Database/SqliteNetCoreGuidPatch.cs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Intersect.Server/Database/SqliteNetCoreGuidPatch.cs b/Intersect.Server/Database/SqliteNetCoreGuidPatch.cs index 173fcbd767..f2ff536fbd 100644 --- a/Intersect.Server/Database/SqliteNetCoreGuidPatch.cs +++ b/Intersect.Server/Database/SqliteNetCoreGuidPatch.cs @@ -5,6 +5,7 @@ using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; +using Remotion.Linq.Clauses; using SqlKata.Execution; namespace Intersect.Server.Database; @@ -103,6 +104,12 @@ public static void ApplyTo(TContext context) column => column.NotNull ); + var searchIdColumns = new[] { "Id" }; + if (!guidColumnNames.Contains("Id")) + { + searchIdColumns = guidColumnNames; + } + var numberOfRows = queryFactory.Query(entityTable).Select("*").AsCount().First(); var convertedRowCount = 0; const int take = 100; @@ -151,7 +158,10 @@ public static void ApplyTo(TContext context) } } ); - return (convertedRow, row["Id"]); + var searchValues = searchIdColumns + .Select(searchIdColumn => (searchIdColumn, row[searchIdColumn])) + .ToArray(); + return (convertedRow, searchValues); } ) .ToList(); @@ -159,20 +169,19 @@ public static void ApplyTo(TContext context) dbConnection.Open(); var transaction = dbConnection.BeginTransaction(); var segmentConvertedRowCount = 0; - foreach (var (convertedRow, searchId) in convertedRows) + foreach (var (convertedRow, searchIds) in convertedRows) { - var result = queryFactory - .Query(entityTable) - .Where("Id", searchId) - .Update(convertedRow, transaction: transaction); + var query = queryFactory.Query(entityTable); + foreach (var (columnName, searchId) in searchIds) + { + query = query.Where(columnName, searchId); + } - var searchIdString = searchId is byte[] searchIdBytes - ? new Guid(searchIdBytes).ToString() - : searchId.ToString(); + var result = query.Update(convertedRow, transaction: transaction); if (Log.Default.Configuration.LogLevel >= LogLevel.Debug) { - Log.Debug($"Processed row {convertedRowCount++}/{numberOfRows} in '{entityTable}' (segment {segmentConvertedRowCount++}/{convertedRows.Count}) ({searchIdString} was {searchId.GetFullishName()}), {result} rows changed."); + Log.Debug($"Processed row {convertedRowCount++}/{numberOfRows} in '{entityTable}' (segment {segmentConvertedRowCount++}/{convertedRows.Count}), {result} rows changed."); } } transaction.Commit();