From 73b7d319cc2278b6cbe03b29c8bf32ed54e27bf6 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 30 Jul 2024 05:21:31 +0200 Subject: [PATCH 1/2] Fixes for DB enum states in unexpected case --- src/database/DatabaseSchemaHelper.cpp | 39 +++++++++++++++++++++++++-- src/model/Recipe.cpp | 9 ++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/database/DatabaseSchemaHelper.cpp b/src/database/DatabaseSchemaHelper.cpp index 2c7175df..42328527 100644 --- a/src/database/DatabaseSchemaHelper.cpp +++ b/src/database/DatabaseSchemaHelper.cpp @@ -36,7 +36,7 @@ #include "database/DbTransaction.h" #include "database/ObjectStoreTyped.h" -int constexpr DatabaseSchemaHelper::latestVersion = 11; +int constexpr DatabaseSchemaHelper::latestVersion = 12; // Default namespace hides functions from everything outside this file. namespace { @@ -732,7 +732,8 @@ namespace { // // Yeast: Extended and additional fields for BeerJSON // - // We only need to update the old Yeast type, form and flocculation mappings. The new ones should "just work". + // We only need to update the old Yeast type, form and flocculation mappings. The new ones ("very low", + // "medium low", "medium high") should "just work". {QString(" UPDATE yeast SET ytype = 'ale' WHERE ytype = 'Ale' ")}, {QString(" UPDATE yeast SET ytype = 'lager' WHERE ytype = 'Lager' ")}, {QString(" UPDATE yeast SET ytype = 'other' WHERE ytype = 'Wheat' ")}, // NB: Wheat becomes Other @@ -1964,6 +1965,37 @@ namespace { return executeSqlQueries(q, migrationQueries); } + /** + * \brief This is not actually a schema change, but rather data fixes that were missed from migrate_to_11 - mostly + * things where we should have been less case-sensitive. + */ + bool migrate_to_12(Database & db, BtSqlQuery q) { + QVector const migrationQueries{ + {QString( "UPDATE hop SET htype = 'aroma/bittering' WHERE lower(htype) = 'both'" )}, + {QString(" UPDATE fermentable SET ftype = 'dry extract' WHERE lower(ftype) = 'dry extract'")}, + {QString(" UPDATE fermentable SET ftype = 'dry extract' WHERE lower(ftype) = 'dryextract'" )}, + {QString(" UPDATE fermentable SET ftype = 'other' WHERE lower(ftype) = 'adjunct'" )}, + {QString(" UPDATE misc SET mtype = 'water agent' WHERE lower(mtype) = 'water agent'")}, + {QString(" UPDATE misc SET mtype = 'water agent' WHERE lower(mtype) = 'wateragent'" )}, + {QString(" UPDATE yeast SET ytype = 'other' WHERE lower(ytype) = 'wheat' ")}, + {QString(" UPDATE yeast SET flocculation = 'very high' WHERE lower(flocculation) = 'very high'")}, + {QString(" UPDATE yeast SET flocculation = 'very high' WHERE lower(flocculation) = 'veryhigh'" )}, + {QString(" UPDATE style SET stype = 'beer' WHERE lower(stype) = 'lager'")}, + {QString(" UPDATE style SET stype = 'beer' WHERE lower(stype) = 'ale' ")}, + {QString(" UPDATE style SET stype = 'beer' WHERE lower(stype) = 'wheat'")}, + {QString(" UPDATE style SET stype = 'other' WHERE lower(stype) = 'mixed'")}, + {QString(" UPDATE mash_step SET mstype = 'sparge' WHERE lower(mstype) = 'flysparge' ")}, + {QString(" UPDATE mash_step SET mstype = 'sparge' WHERE lower(mstype) = 'fly sparge' ")}, + {QString(" UPDATE mash_step SET mstype = 'drain mash tun' WHERE lower(mstype) = 'batchsparge'")}, + {QString(" UPDATE mash_step SET mstype = 'drain mash tun' WHERE lower(mstype) = 'batch sparge'")}, + {QString(" UPDATE recipe SET type = 'partial mash' WHERE lower(type) = 'partial mash'")}, + {QString(" UPDATE recipe SET type = 'partial mash' WHERE lower(type) = 'partialmash'")}, + {QString(" UPDATE recipe SET type = 'all grain' WHERE lower(type) = 'all grain' ")}, + {QString(" UPDATE recipe SET type = 'all grain' WHERE lower(type) = 'allgrain' ")}, + }; + return executeSqlQueries(q, migrationQueries); + } + /*! * \brief Migrate from version \c oldVersion to \c oldVersion+1 */ @@ -2004,6 +2036,9 @@ namespace { case 10: ret &= migrate_to_11(database, sqlQuery); break; + case 11: + ret &= migrate_to_12(database, sqlQuery); + break; default: qCritical() << QString("Unknown version %1").arg(oldVersion); return false; diff --git a/src/model/Recipe.cpp b/src/model/Recipe.cpp index 3ed4bb60..0e687731 100644 --- a/src/model/Recipe.cpp +++ b/src/model/Recipe.cpp @@ -1462,13 +1462,8 @@ class Recipe::impl { // Need to translate OG and FG into plato - double const better_startPlato = Measurement::Units::plato.fromCanonical(this->m_self.m_og); - double const better_finishPlato = Measurement::Units::plato.fromCanonical(this->m_self.m_fg); - double const startPlato = -463.37 + (668.72 * this->m_self.m_og) - (205.35 * this->m_self.m_og * this->m_self.m_og); - double const finishPlato = -463.37 + (668.72 * this->m_self.m_fg) - (205.35 * this->m_self.m_fg * this->m_self.m_fg); - - qCritical() << Q_FUNC_INFO << "better_startPlato:" << better_startPlato << ", startPlato:" << startPlato; - qCritical() << Q_FUNC_INFO << "better_finishPlato:" << better_finishPlato << ", finishPlato:" << finishPlato; + double const startPlato = Measurement::Units::plato.fromCanonical(this->m_self.m_og); + double const finishPlato = Measurement::Units::plato.fromCanonical(this->m_self.m_fg); double const realExtract = (0.1808 * startPlato) + (0.8192 * finishPlato); From f30a1dc64f02c2bf01bdd432aeb375351693ae8d Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 30 Jul 2024 18:50:54 +0200 Subject: [PATCH 2/2] More minor fixes --- src/trees/TreeNode.cpp | 21 ++++++++++++++------- src/trees/TreeNode.h | 10 ++++++++-- translations/bt_ca.ts | 4 ++++ translations/bt_cs.ts | 4 ++++ translations/bt_de.ts | 4 ++++ translations/bt_el.ts | 4 ++++ translations/bt_en.ts | 4 ++++ translations/bt_es.ts | 4 ++++ translations/bt_et.ts | 4 ++++ translations/bt_eu.ts | 4 ++++ translations/bt_fr.ts | 4 ++++ translations/bt_gl.ts | 4 ++++ translations/bt_hu.ts | 4 ++++ translations/bt_it.ts | 4 ++++ translations/bt_lv.ts | 4 ++++ translations/bt_nb.ts | 4 ++++ translations/bt_nl.ts | 4 ++++ translations/bt_pl.ts | 4 ++++ translations/bt_pt.ts | 4 ++++ translations/bt_ru.ts | 4 ++++ translations/bt_sr.ts | 4 ++++ translations/bt_sv.ts | 4 ++++ translations/bt_tr.ts | 4 ++++ translations/bt_zh.ts | 4 ++++ 24 files changed, 110 insertions(+), 9 deletions(-) diff --git a/src/trees/TreeNode.cpp b/src/trees/TreeNode.cpp index 950b6e32..dbbb7fbf 100644 --- a/src/trees/TreeNode.cpp +++ b/src/trees/TreeNode.cpp @@ -77,8 +77,9 @@ template<> EnumStringMapping const TreeItemNode::columnDisplayNames { }; template<> EnumStringMapping const TreeItemNode::columnDisplayNames { - {TreeItemNode::ColumnIndex::Laboratory, Yeast::tr("Laboratory")}, {TreeItemNode::ColumnIndex::Name , Yeast::tr("Name" )}, + {TreeItemNode::ColumnIndex::Laboratory, Yeast::tr("Laboratory")}, + {TreeItemNode::ColumnIndex::ProductId , Yeast::tr("Product ID")}, {TreeItemNode::ColumnIndex::Type , Yeast::tr("Type" )}, {TreeItemNode::ColumnIndex::Form , Yeast::tr("Form" )}, }; @@ -226,8 +227,9 @@ template<> bool TreeItemNode::isLessThan([[maybe_unused]] TreeModel const Yeast const & lhs, Yeast const & rhs) { switch (section) { - case TreeItemNode::ColumnIndex::Laboratory: return lhs.laboratory() < rhs.laboratory(); case TreeItemNode::ColumnIndex::Name : return lhs.name() < rhs.name(); + case TreeItemNode::ColumnIndex::Laboratory: return lhs.laboratory() < rhs.laboratory(); + case TreeItemNode::ColumnIndex::ProductId : return lhs.productId() < rhs.productId(); case TreeItemNode::ColumnIndex::Type : return lhs.type() < rhs.type(); case TreeItemNode::ColumnIndex::Form : return lhs.form() < rhs.form(); } @@ -542,17 +544,22 @@ QVariant TreeNode::dataMisc(int column) { QVariant TreeNode::dataYeast(int column) { Yeast * yeast = qobject_cast(this->m_thing); switch (static_cast::ColumnIndex>(column)) { - case TreeItemNode::ColumnIndex::Laboratory: - if (yeast) { - return QVariant(yeast->laboratory()); - } - break; case TreeItemNode::ColumnIndex::Name: if (! yeast) { return QVariant(QObject::tr("Yeast")); } else { return QVariant(yeast->name()); } + case TreeItemNode::ColumnIndex::Laboratory: + if (yeast) { + return QVariant(yeast->laboratory()); + } + break; + case TreeItemNode::ColumnIndex::ProductId: + if (yeast) { + return QVariant(yeast->productId()); + } + break; case TreeItemNode::ColumnIndex::Type: if (yeast) { return QVariant(Yeast::typeDisplayNames[yeast->type()]); diff --git a/src/trees/TreeNode.h b/src/trees/TreeNode.h index 6f942f66..dc930aa2 100644 --- a/src/trees/TreeNode.h +++ b/src/trees/TreeNode.h @@ -105,6 +105,9 @@ class TreeNodeBase : public CuriouslyRecurringTemplateBase= static_cast(Info::NumberOfColumns)) { + return QVariant(); + } return QVariant(Derived::columnDisplayNames[section]); } @@ -365,12 +368,15 @@ template<> struct TreeItemTraits> { template<> struct TreeItemTraits> { enum class ColumnIndex { - Laboratory, + // It's tempting to put Laboratory first, and have it at the first column, but it messes up the way the folders + // work if the first column isn't Name Name, + Laboratory, + ProductId, Type, Form, }; - enum class Info { NumberOfColumns = 3 }; + enum class Info { NumberOfColumns = 5 }; using ParentType = TreeFolderNode; using ChildPtrTypes = std::variant; }; diff --git a/translations/bt_ca.ts b/translations/bt_ca.ts index 96b7d6a4..0228dc76 100644 --- a/translations/bt_ca.ts +++ b/translations/bt_ca.ts @@ -5947,6 +5947,10 @@ El volum final al primari és de %1. Form Format + + Product ID + ID del producte + YeastDialog diff --git a/translations/bt_cs.ts b/translations/bt_cs.ts index dd86b9c9..9d2a0d3c 100644 --- a/translations/bt_cs.ts +++ b/translations/bt_cs.ts @@ -5793,6 +5793,10 @@ Celkový objem pro hlavní kvašení je %1. Form + + Product ID + ID produktu + YeastDialog diff --git a/translations/bt_de.ts b/translations/bt_de.ts index 89b26ba2..50cba758 100644 --- a/translations/bt_de.ts +++ b/translations/bt_de.ts @@ -5860,6 +5860,10 @@ Das endgültige Volumen in der Hauptgärung beträgt %1. Form + + Product ID + + YeastDialog diff --git a/translations/bt_el.ts b/translations/bt_el.ts index 6610f67d..378da43a 100644 --- a/translations/bt_el.ts +++ b/translations/bt_el.ts @@ -5825,6 +5825,10 @@ The final volume in the primary is %1. Form Μορφή + + Product ID + Κωδικός προιόντος + YeastDialog diff --git a/translations/bt_en.ts b/translations/bt_en.ts index f05ec7c7..1baf6159 100644 --- a/translations/bt_en.ts +++ b/translations/bt_en.ts @@ -4529,6 +4529,10 @@ The final volume in the primary is %1. Form + + Product ID + + YeastTableModel diff --git a/translations/bt_es.ts b/translations/bt_es.ts index cd85985f..c51faa44 100644 --- a/translations/bt_es.ts +++ b/translations/bt_es.ts @@ -5903,6 +5903,10 @@ El volumen final en el primario es %1. Form + + Product ID + + YeastDialog diff --git a/translations/bt_et.ts b/translations/bt_et.ts index d4ac6ecd..5cb10c9d 100644 --- a/translations/bt_et.ts +++ b/translations/bt_et.ts @@ -4614,6 +4614,10 @@ The final volume in the primary is %1. Form + + Product ID + + YeastTableModel diff --git a/translations/bt_eu.ts b/translations/bt_eu.ts index 52fcabc2..0e38e461 100644 --- a/translations/bt_eu.ts +++ b/translations/bt_eu.ts @@ -4626,6 +4626,10 @@ The final volume in the primary is %1. Form + + Product ID + + YeastTableModel diff --git a/translations/bt_fr.ts b/translations/bt_fr.ts index c77c543b..2a7981c5 100644 --- a/translations/bt_fr.ts +++ b/translations/bt_fr.ts @@ -5943,6 +5943,10 @@ Le volume final dans la cuve de fermentation est de %1. Form Format + + Product ID + ID du produit + YeastDialog diff --git a/translations/bt_gl.ts b/translations/bt_gl.ts index 461c7414..0f7e4253 100644 --- a/translations/bt_gl.ts +++ b/translations/bt_gl.ts @@ -4949,6 +4949,10 @@ The final volume in the primary is %1. Form Formulario + + Product ID + + YeastDialog diff --git a/translations/bt_hu.ts b/translations/bt_hu.ts index 9eaced2a..0e8790b8 100644 --- a/translations/bt_hu.ts +++ b/translations/bt_hu.ts @@ -5875,6 +5875,10 @@ Végleges mennyiség az elsődleges erjesztőben: %1 Form Forma + + Product ID + Termékazonosító + YeastDialog diff --git a/translations/bt_it.ts b/translations/bt_it.ts index bbf53071..0f531985 100644 --- a/translations/bt_it.ts +++ b/translations/bt_it.ts @@ -5920,6 +5920,10 @@ Il Volume finale del primo è %1. Form Forma + + Product ID + ID Prodotto + YeastDialog diff --git a/translations/bt_lv.ts b/translations/bt_lv.ts index a2aab866..37deba2c 100644 --- a/translations/bt_lv.ts +++ b/translations/bt_lv.ts @@ -4786,6 +4786,10 @@ The final volume in the primary is %1. Form + + Product ID + + YeastDialog diff --git a/translations/bt_nb.ts b/translations/bt_nb.ts index 8dd4c139..bf119db9 100644 --- a/translations/bt_nb.ts +++ b/translations/bt_nb.ts @@ -5836,6 +5836,10 @@ Sluttvolumet i primærgjæringskaret er %1. Form + + Product ID + Produkt-ID + YeastDialog diff --git a/translations/bt_nl.ts b/translations/bt_nl.ts index cd56f106..dc82ae7e 100644 --- a/translations/bt_nl.ts +++ b/translations/bt_nl.ts @@ -5917,6 +5917,10 @@ Het uiteindelijke volume in de hoofdvergisting is %1. Form + + Product ID + Product ID + YeastDialog diff --git a/translations/bt_pl.ts b/translations/bt_pl.ts index 5d0ef5a7..35f72a0d 100644 --- a/translations/bt_pl.ts +++ b/translations/bt_pl.ts @@ -5753,6 +5753,10 @@ Końcowa pojemność w fermentorze wyniesie %1. Form + + Product ID + ID produktu + YeastDialog diff --git a/translations/bt_pt.ts b/translations/bt_pt.ts index e275b225..9155223f 100644 --- a/translations/bt_pt.ts +++ b/translations/bt_pt.ts @@ -5863,6 +5863,10 @@ O volume final do fermentador primário é %1. Form + + Product ID + + YeastDialog diff --git a/translations/bt_ru.ts b/translations/bt_ru.ts index b7f64472..1976fe66 100644 --- a/translations/bt_ru.ts +++ b/translations/bt_ru.ts @@ -5899,6 +5899,10 @@ The final volume in the primary is %1. Form Форма + + Product ID + ID продукта + YeastDialog diff --git a/translations/bt_sr.ts b/translations/bt_sr.ts index 03c42e5f..cfc8a9c0 100644 --- a/translations/bt_sr.ts +++ b/translations/bt_sr.ts @@ -5578,6 +5578,10 @@ The final volume in the primary is %1. Form Облик + + Product ID + + YeastDialog diff --git a/translations/bt_sv.ts b/translations/bt_sv.ts index ea35a878..d83a5051 100644 --- a/translations/bt_sv.ts +++ b/translations/bt_sv.ts @@ -5904,6 +5904,10 @@ Primärens slutgiltiga volym är %1. Form Formulär + + Product ID + Produkt-ID + YeastDialog diff --git a/translations/bt_tr.ts b/translations/bt_tr.ts index e43ea6bc..de04edae 100644 --- a/translations/bt_tr.ts +++ b/translations/bt_tr.ts @@ -5941,6 +5941,10 @@ The final volume in the primary is %1. Form Biçim + + Product ID + Ürün Kimliği + YeastDialog diff --git a/translations/bt_zh.ts b/translations/bt_zh.ts index 492702ff..8f8db601 100644 --- a/translations/bt_zh.ts +++ b/translations/bt_zh.ts @@ -5673,6 +5673,10 @@ The final volume in the primary is %1. Form 形式Form + + Product ID + 产品IDProduct ID + YeastDialog