Skip to content

Commit

Permalink
Merge pull request #856 from matty0ung/usability
Browse files Browse the repository at this point in the history
Fix upgrade to take account of salt additions with "When to add" of "Never"
  • Loading branch information
matty0ung authored Oct 14, 2024
2 parents b9c96af + ce35311 commit 0ae3f50
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGES.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ happens, so I'm now setting it to a slightly arbitrary time early in the morning
Bug fixes and minor enhancements.

### New Features
* None
* Add vertical splitter on Recipe tab, make kettle diameter editable
* Minor improvements to editor layouts

### Bug Fixes
* Some input fields not wide enough on various editors [849](https://github.com/Brewtarget/brewtarget/issues/849)
* Upgrade to Qt 6 [841](https://github.com/Brewtarget/brewtarget/issues/841)
* Equipment should be optional in Recipes in BeerXML [853](https://github.com/Brewtarget/brewtarget/issues/853)
* Salt additions with when-to-add time of Never not handled in DB upgrade [840](https://github.com/Brewtarget/brewtarget/issues/840)

### Release Timestamp
Fri, 11 Oct 2024 04:00:07 +0100
Mon, 14 Oct 2024 04:00:07 +0100

## v4.0.6
Bug fixes for the 4.0.5 release (ie bugs in 4.0.5 are fixed in this 4.0.6 release).
Expand Down
30 changes: 29 additions & 1 deletion src/database/DatabaseSchemaHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand All @@ -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 "
Expand Down

0 comments on commit 0ae3f50

Please sign in to comment.