# HG changeset patch # User Michiel Broek # Date 1674999643 -3600 # Node ID 28f0e43e9f0843a7a243e358aab56e93ff2251fe # Parent a3653722b0d67a113898051ee5bdf1b7f57f0216 Version 0.4.0. Added database upgrade procedure on startup. Make sure inventory_yeastpack database is created and has default entries. This will become a table with data for different yeast packs. diff -r a3653722b0d6 -r 28f0e43e9f08 CMakeLists.txt --- a/CMakeLists.txt Sat Jan 28 10:36:59 2023 +0100 +++ b/CMakeLists.txt Sun Jan 29 14:40:43 2023 +0100 @@ -8,8 +8,8 @@ # ===== Set application version ===== SET( bmsapp_VERSION_MAJOR 0 ) -SET( bmsapp_VERSION_MINOR 3 ) -SET( bmsapp_VERSION_PATCH 6 ) +SET( bmsapp_VERSION_MINOR 4 ) +SET( bmsapp_VERSION_PATCH 0 ) # Compile flags diff -r a3653722b0d6 -r 28f0e43e9f08 src/MainWindow.cpp --- a/src/MainWindow.cpp Sat Jan 28 10:36:59 2023 +0100 +++ b/src/MainWindow.cpp Sun Jan 29 14:40:43 2023 +0100 @@ -67,6 +67,7 @@ db = new DataBase(); db->openDataBase(useDevelopOption); + updateDataBase(); loadSetup(); maintDataBase(); openWS(useDevelopOption); @@ -158,6 +159,74 @@ /* + * Upgrade database. Check and do upgrades. + */ +void MainWindow::updateDataBase() +{ + QSqlQuery query1, query2, query3, query4; + int count = 0; + + qDebug() << "updateDatabase() start"; + + /* + * Make sure we have the inventory_yeastpack with initial records. + */ + query1.exec("CREATE TABLE IF NOT EXISTS `inventory_yeastpack` (" + "`record` int(11) NOT NULL AUTO_INCREMENT," + "`uuid` varchar(36) NOT NULL," + "`laboratory` varchar(128) NOT NULL," + "`form` tinyint(4) NOT NULL DEFAULT 0," + "`package` varchar(128) NOT NULL," + "`notes` text DEFAULT NULL," + "`cells` double NOT NULL DEFAULT 0," + "`viability` double NOT NULL DEFAULT 0.99," + "`max` tinyint(4) NOT NULL DEFAULT 100," + "`size` float NOT NULL DEFAULT 0," + "PRIMARY KEY (`record`)," + "UNIQUE KEY `uuid` (`uuid`)," + "KEY `lab_form` (`laboratory`,`form`) USING BTREE" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Yeast packages data'"); + if (query1.lastError().isValid()) { + qWarning() << " create inventory_yeastpack" << query1.lastError(); + } else { + query1.exec("SELECT DISTINCT laboratory,form FROM inventory_yeasts"); + while (query1.next()) { + query2.prepare("SELECT record FROM inventory_yeastpack WHERE laboratory=:laboratory AND form=:form"); + query2.bindValue(":laboratory", query1.value("laboratory").toString()); + query2.bindValue(":form", query1.value("form").toInt()); + query2.exec(); + if (! query2.first()) { + qDebug() << " add yeastpack" << query1.value("laboratory").toString() << query1.value("form").toInt(); + + query3.prepare("SELECT record,cells FROM inventory_yeasts WHERE laboratory=:laboratory AND form=:form"); + query3.bindValue(":laboratory", query1.value("laboratory").toString()); + query3.bindValue(":form", query1.value("form").toInt()); + query3.exec(); + query3.first(); + /* Should succeed */ + + query4.prepare("INSERT INTO inventory_yeastpack SET uuid=:uuid, laboratory=:laboratory, " + "form=:form, package=:package, cells=:cells"); + query4.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); + query4.bindValue(":laboratory", query1.value("laboratory").toString()); + query4.bindValue(":form", query1.value("form").toInt()); + query4.bindValue(":package", g_yeast_forms[query1.value("form").toInt()]); + query4.bindValue(":cells", query3.value("cells").toDouble()); + query4.exec(); + if (query4.lastError().isValid()) { + qWarning() << " add yeastpack" << query4.lastError(); + } else { + count++; + } + } + } + } + + qDebug() << "updateDatabase()" << count << "updates"; +} + + +/* * On the server where bmsd runs, there is a crontask.php that does these checks * too. Here we do some of the same commands so that we have the results sooner. * Currently this takes 6 to 9 mSecs. diff -r a3653722b0d6 -r 28f0e43e9f08 src/MainWindow.h --- a/src/MainWindow.h Sat Jan 28 10:36:59 2023 +0100 +++ b/src/MainWindow.h Sun Jan 29 14:40:43 2023 +0100 @@ -213,6 +213,11 @@ void loadSetup(); /** + * @brief Do database updates. + */ + void updateDataBase(); + + /** * @brief Do database maintenance. */ void maintDataBase(); diff -r a3653722b0d6 -r 28f0e43e9f08 translations/bmsapp_en.ts --- a/translations/bmsapp_en.ts Sat Jan 28 10:36:59 2023 +0100 +++ b/translations/bmsapp_en.ts Sun Jan 29 14:40:43 2023 +0100 @@ -2350,8 +2350,8 @@ - - + + Delete @@ -3424,7 +3424,7 @@ - + Volume @@ -4230,7 +4230,7 @@ - + Type @@ -4254,7 +4254,7 @@ - + Amount @@ -4262,7 +4262,7 @@ - + Stock @@ -4283,8 +4283,8 @@ - - + + Edit @@ -4330,7 +4330,7 @@ - + @@ -4366,7 +4366,7 @@ - + Use at: @@ -4380,7 +4380,7 @@ - + In stock: @@ -4522,8 +4522,8 @@ - - + + Amount in gr: @@ -4562,8 +4562,8 @@ - - + + Amount in ml: @@ -4574,13 +4574,13 @@ - + Primary - + Secondary @@ -4590,185 +4590,185 @@ - + Yeast - + Laboratory - + Code - + Use for - + Min. - + Max. - + Tol. - + Attn. - + STA - - + + Yeast already used - + Method - + Inj. factor - + New cells - + Total cells - + Grow factor - + BMSapp - Pitchrate + + Beer pitch type: + + + - Beer pitch type: - - - - 0.075 Real Kveik - + 0.75 Ale, upto 1.060 - + 1.0 Ale, above 1.060 - + 1.5 Lager, upto 1.060 - + 2.0 Lager, above 1.060 - + Retry starter - + Retry to automatic create starter steps - + Start step type: + + Starter step volume: + + + + + Stirred + + + - Starter step volume: - - - - - Stirred - - - - Shaken - + Simple - + Delete yeast - - + + Total packs: - + Yeast name: - - + + Laboratory: - + Select yeast: - + Tertiary - + Bottle @@ -6092,7 +6092,7 @@ - + Delete @@ -6963,7 +6963,7 @@ - + Edit @@ -6978,7 +6978,7 @@ - + Delete %1 @@ -7013,7 +7013,7 @@ - + Use at: @@ -7027,7 +7027,7 @@ - + In stock: @@ -7055,7 +7055,7 @@ - + Bottle @@ -7168,8 +7168,8 @@ - - + + Amount in gr: @@ -7258,8 +7258,8 @@ - - + + Amount in ml: @@ -7270,13 +7270,13 @@ - + Primary - + Secondary @@ -7321,34 +7321,39 @@ - + + STA + + + + Delete yeast - - + + Total packs: - + Yeast name: - - + + Laboratory: - + Select yeast: - + Tertiary diff -r a3653722b0d6 -r 28f0e43e9f08 translations/bmsapp_nl.ts --- a/translations/bmsapp_nl.ts Sat Jan 28 10:36:59 2023 +0100 +++ b/translations/bmsapp_nl.ts Sun Jan 29 14:40:43 2023 +0100 @@ -2650,8 +2650,8 @@ - - + + Delete Verwijder @@ -3314,7 +3314,7 @@ - + Volume Volume @@ -4734,7 +4734,7 @@ - + Type Soort @@ -4758,7 +4758,7 @@ - + Amount Hoeveel @@ -4766,7 +4766,7 @@ - + Stock Voorraad @@ -4787,8 +4787,8 @@ - - + + Edit Wijzig @@ -4846,7 +4846,7 @@ - + @@ -4882,7 +4882,7 @@ - + Use at: Toevoegen bij: @@ -4896,7 +4896,7 @@ - + In stock: In voorraad: @@ -5038,8 +5038,8 @@ - - + + Amount in gr: Gewicht in gr: @@ -5097,8 +5097,8 @@ - - + + Amount in ml: Hoeveelheid in ml: @@ -5109,13 +5109,13 @@ - + Primary Hoofdgisting - + Secondary Nagisting/lagering @@ -5125,185 +5125,185 @@ Bottelen - + Yeast Gist - + Laboratory Laboratorium - + Code Product code - + Use for Toepassing - + Min. - + Max. - + Tol. - + Attn. - + STA STA - - + + Yeast already used Gist is al verwerkt - + Method Methode - + Inj. factor Injectie - + New cells Celgroei - + Total cells Totaal - + Grow factor Groeifactor - + BMSapp - Pitchrate BMSapp - Gist enten + + Beer pitch type: + Biergist nodig: + + - Beer pitch type: - Biergist nodig: - - - 0.075 Real Kveik 0,075 Echte Kveik - + 0.75 Ale, upto 1.060 0,75 Bovengist tot 1.060 - + 1.0 Ale, above 1.060 1,0 Bovengist hoger 1.060 - + 1.5 Lager, upto 1.060 1,5 Ondergist tot 1.060 - + 2.0 Lager, above 1.060 2,0 Ondergist hoger 1.060 - + Retry starter Ververs starter - + Retry to automatic create starter steps Ververs de starter stappen automatisch - + Start step type: Starter stap type: + + Starter step volume: + Starter stap volume: + + + + Stirred + Geroerd + + - Starter step volume: - Starter stap volume: - - - - Stirred - Geroerd - - - Shaken Geschud - + Simple Simpel - + Delete yeast Verwijder gist - - + + Total packs: Aantal pakken: - + Yeast name: Gist naam: - - + + Laboratory: Laboratorium: - + Select yeast: Kies gist: - + Tertiary Lageren - + Bottle Bottelen @@ -6724,7 +6724,7 @@ - + Delete @@ -7676,7 +7676,7 @@ - + Edit @@ -7691,7 +7691,7 @@ - + Delete %1 @@ -7726,7 +7726,7 @@ - + Use at: Toevoegen bij: @@ -7740,7 +7740,7 @@ - + In stock: In voorraad: @@ -7768,7 +7768,7 @@ - + Bottle Bottelen @@ -7881,8 +7881,8 @@ - - + + Amount in gr: Gewicht in gr: @@ -7969,8 +7969,8 @@ - - + + Amount in ml: Hoeveelheid in ml: @@ -7981,13 +7981,13 @@ - + Primary Hoofdgisting - + Secondary Nagisting/lagering @@ -8038,34 +8038,39 @@ SVG % - + + STA + STA + + + Delete yeast Verwijder gist - - + + Total packs: Aantal pakken: - + Yeast name: Gist naam: - - + + Laboratory: Laboratorium: - + Select yeast: Kies gist: - + Tertiary Lageren