From 6de90a807912396b2acee3d5c625e1186c8b32d0 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Mon, 14 Oct 2024 18:43:47 +0200 Subject: [PATCH] Fix upgrade to take account of salt additions with "When to add" of "Never" --- src/database/DatabaseSchemaHelper.cpp | 30 ++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/database/DatabaseSchemaHelper.cpp b/src/database/DatabaseSchemaHelper.cpp index cc38260b4..05f93c4ea 100644 --- a/src/database/DatabaseSchemaHelper.cpp +++ b/src/database/DatabaseSchemaHelper.cpp @@ -1439,7 +1439,7 @@ namespace { // 3 == Ratio == Add at mash and sparge, pro rata to the amounts of water (I think!) // 4 == Equal == Add at mash and sparge, equal amounts (I think!) // - // We ditch the "Never" value and store in when_to_add as a string. + // We skip the "Never" value (see below) and store in when_to_add as a string. // {QString("UPDATE salt_in_recipe " "SET quantity = s.amount, " @@ -1466,6 +1466,34 @@ namespace { "WHERE salt_in_recipe.salt_id = s.id " "AND s.addTo != 0")}, // + // Now we have to do something with the salts marked as "do not add". Since salt is not mentioned in either + // BeerXML or BeerJSON, we don't have a lot of guidance here. AFAICT the "Never" value was just a convenience + // in the UI for when you created a salt addition but hadn't yet set all its properties. I _think_ we could + // safely just delete Salts with addTo == 0. However, rather than risk losing data, we will instead mark them + // as deleted. We have to set some valid value for when_to_add, so we arbitrarily choose "Equal", but make + // clear in the Name that original value was "Never". + // + {QString("UPDATE salt_in_recipe " + "SET quantity = s.amount, " + "unit = s.unit, " + "name = 'Deleted addition of \"Never add\" ' || s.name, " + "display = ?, " + "deleted = ?, " + "when_to_add = 'Equal' " + "FROM (" + "SELECT id, " + "name, " + "amount, " + "addTo, " + "CASE " + "WHEN amount_is_weight THEN 'kilograms' " + "ELSE 'liters' " + "END AS unit " + "FROM salt" + ") AS s " + "WHERE salt_in_recipe.salt_id = s.id " + "AND s.addTo == 0"), {QVariant{false}, QVariant{true}}}, + // // For water both the source and target are volume in liters // {QString("UPDATE water_in_recipe "