Skip to content

Commit

Permalink
Merge pull request #802 from matty0ung/dbFixes
Browse files Browse the repository at this point in the history
Fixes for DB enum states in unexpected case and a couple of other things.
  • Loading branch information
matty0ung committed Jul 30, 2024
2 parents fb4e76e + f30a1dc commit 0db2266
Show file tree
Hide file tree
Showing 26 changed files with 149 additions and 18 deletions.
39 changes: 37 additions & 2 deletions src/database/DatabaseSchemaHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<QueryAndParameters> 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
*/
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions src/model/Recipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
21 changes: 14 additions & 7 deletions src/trees/TreeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ template<> EnumStringMapping const TreeItemNode<Misc>::columnDisplayNames {
};

template<> EnumStringMapping const TreeItemNode<Yeast>::columnDisplayNames {
{TreeItemNode<Yeast>::ColumnIndex::Laboratory, Yeast::tr("Laboratory")},
{TreeItemNode<Yeast>::ColumnIndex::Name , Yeast::tr("Name" )},
{TreeItemNode<Yeast>::ColumnIndex::Laboratory, Yeast::tr("Laboratory")},
{TreeItemNode<Yeast>::ColumnIndex::ProductId , Yeast::tr("Product ID")},
{TreeItemNode<Yeast>::ColumnIndex::Type , Yeast::tr("Type" )},
{TreeItemNode<Yeast>::ColumnIndex::Form , Yeast::tr("Form" )},
};
Expand Down Expand Up @@ -226,8 +227,9 @@ template<> bool TreeItemNode<Yeast>::isLessThan([[maybe_unused]] TreeModel const
Yeast const & lhs,
Yeast const & rhs) {
switch (section) {
case TreeItemNode<Yeast>::ColumnIndex::Laboratory: return lhs.laboratory() < rhs.laboratory();
case TreeItemNode<Yeast>::ColumnIndex::Name : return lhs.name() < rhs.name();
case TreeItemNode<Yeast>::ColumnIndex::Laboratory: return lhs.laboratory() < rhs.laboratory();
case TreeItemNode<Yeast>::ColumnIndex::ProductId : return lhs.productId() < rhs.productId();
case TreeItemNode<Yeast>::ColumnIndex::Type : return lhs.type() < rhs.type();
case TreeItemNode<Yeast>::ColumnIndex::Form : return lhs.form() < rhs.form();
}
Expand Down Expand Up @@ -542,17 +544,22 @@ QVariant TreeNode::dataMisc(int column) {
QVariant TreeNode::dataYeast(int column) {
Yeast * yeast = qobject_cast<Yeast *>(this->m_thing);
switch (static_cast<TreeItemNode<Yeast>::ColumnIndex>(column)) {
case TreeItemNode<Yeast>::ColumnIndex::Laboratory:
if (yeast) {
return QVariant(yeast->laboratory());
}
break;
case TreeItemNode<Yeast>::ColumnIndex::Name:
if (! yeast) {
return QVariant(QObject::tr("Yeast"));
} else {
return QVariant(yeast->name());
}
case TreeItemNode<Yeast>::ColumnIndex::Laboratory:
if (yeast) {
return QVariant(yeast->laboratory());
}
break;
case TreeItemNode<Yeast>::ColumnIndex::ProductId:
if (yeast) {
return QVariant(yeast->productId());
}
break;
case TreeItemNode<Yeast>::ColumnIndex::Type:
if (yeast) {
return QVariant(Yeast::typeDisplayNames[yeast->type()]);
Expand Down
10 changes: 8 additions & 2 deletions src/trees/TreeNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class TreeNodeBase : public CuriouslyRecurringTemplateBase<TreeItemTraits, Deriv
~TreeNodeBase() = default;

static QVariant header(int section) {
if (section < 0 || section >= static_cast<int>(Info::NumberOfColumns)) {
return QVariant();
}
return QVariant(Derived::columnDisplayNames[section]);
}

Expand Down Expand Up @@ -365,12 +368,15 @@ template<> struct TreeItemTraits<TreeItemNode<Misc>> {

template<> struct TreeItemTraits<TreeItemNode<Yeast>> {
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<Yeast>;
using ChildPtrTypes = std::variant<std::monostate>;
};
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_ca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5947,6 +5947,10 @@ El volum final al primari és de %1.</translation>
<source>Form</source>
<translation type="unfinished">Format</translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">ID del producte</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5793,6 +5793,10 @@ Celkový objem pro hlavní kvašení je %1.</translation>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">ID produktu</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5860,6 +5860,10 @@ Das endgültige Volumen in der Hauptgärung beträgt %1.</translation>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5825,6 +5825,10 @@ The final volume in the primary is %1.</source>
<source>Form</source>
<translation type="unfinished">Μορφή</translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">Κωδικός προιόντος</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4529,6 +4529,10 @@ The final volume in the primary is %1.</source>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YeastTableModel</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5903,6 +5903,10 @@ El volumen final en el primario es %1.</translation>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_et.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4614,6 +4614,10 @@ The final volume in the primary is %1.</source>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YeastTableModel</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_eu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4626,6 +4626,10 @@ The final volume in the primary is %1.</source>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YeastTableModel</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5943,6 +5943,10 @@ Le volume final dans la cuve de fermentation est de %1.</translation>
<source>Form</source>
<translation type="unfinished">Format</translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">ID du produit</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_gl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4949,6 +4949,10 @@ The final volume in the primary is %1.</source>
<source>Form</source>
<translation type="unfinished">Formulario</translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_hu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5875,6 +5875,10 @@ Végleges mennyiség az elsődleges erjesztőben: %1</translation>
<source>Form</source>
<translation type="unfinished">Forma</translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">Termékazonosító</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5920,6 +5920,10 @@ Il Volume finale del primo è %1.</translation>
<source>Form</source>
<translation type="unfinished">Forma</translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">ID Prodotto</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_lv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4786,6 +4786,10 @@ The final volume in the primary is %1.</source>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_nb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5836,6 +5836,10 @@ Sluttvolumet i primærgjæringskaret er %1.</translation>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">Produkt-ID</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5917,6 +5917,10 @@ Het uiteindelijke volume in de hoofdvergisting is %1.</translation>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">Product ID</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5753,6 +5753,10 @@ Końcowa pojemność w fermentorze wyniesie %1.</translation>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">ID produktu</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5863,6 +5863,10 @@ O volume final do fermentador primário é %1.</translation>
<source>Form</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5899,6 +5899,10 @@ The final volume in the primary is %1.</source>
<source>Form</source>
<translation type="unfinished">Форма</translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">ID продукта</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_sr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5578,6 +5578,10 @@ The final volume in the primary is %1.</source>
<source>Form</source>
<translation type="unfinished">Облик</translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_sv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5904,6 +5904,10 @@ Primärens slutgiltiga volym är %1.</translation>
<source>Form</source>
<translation type="unfinished">Formulär</translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">Produkt-ID</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bt_tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5941,6 +5941,10 @@ The final volume in the primary is %1.</source>
<source>Form</source>
<translation type="unfinished">Biçim</translation>
</message>
<message>
<source>Product ID</source>
<translation type="unfinished">Ürün Kimliği</translation>
</message>
</context>
<context>
<name>YeastDialog</name>
Expand Down
Loading

0 comments on commit 0db2266

Please sign in to comment.