From 9b2aef2ca2025e1a7d21c1850829694d3df2f42b Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 10 Sep 2023 13:23:21 +0300 Subject: [PATCH] Fix executing migration 072 on Postgres Fixes #4109 --- .../072_add_alac_24_quality_in_profiles.cs | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Core/Datastore/Migration/072_add_alac_24_quality_in_profiles.cs b/src/NzbDrone.Core/Datastore/Migration/072_add_alac_24_quality_in_profiles.cs index 9d7b619e5..13f422c82 100644 --- a/src/NzbDrone.Core/Datastore/Migration/072_add_alac_24_quality_in_profiles.cs +++ b/src/NzbDrone.Core/Datastore/Migration/072_add_alac_24_quality_in_profiles.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; +using Dapper; using FluentMigrator; using Newtonsoft.Json; using NzbDrone.Common.Serializer; @@ -62,20 +63,16 @@ namespace NzbDrone.Core.Datastore.Migration public void Commit() { - foreach (var profile in _changedProfiles) + var profilesToUpdate = _changedProfiles.Select(p => new { - using (var updateProfileCmd = _connection.CreateCommand()) - { - updateProfileCmd.Transaction = _transaction; - updateProfileCmd.CommandText = "UPDATE \"QualityProfiles\" SET \"Name\" = ?, \"Cutoff\" = ?, \"Items\" = ? WHERE \"Id\" = ?"; - updateProfileCmd.AddParameter(profile.Name); - updateProfileCmd.AddParameter(profile.Cutoff); - updateProfileCmd.AddParameter(profile.Items.ToJson()); - updateProfileCmd.AddParameter(profile.Id); - - updateProfileCmd.ExecuteNonQuery(); - } - } + p.Id, + p.Name, + p.Cutoff, + Items = p.Items.ToJson() + }); + + var updateSql = "UPDATE \"QualityProfiles\" SET \"Name\" = @Name, \"Cutoff\" = @Cutoff, \"Items\" = @Items WHERE \"Id\" = @Id"; + _connection.Execute(updateSql, profilesToUpdate, transaction: _transaction); _changedProfiles.Clear(); }