|
21 | 21 | FORCE_CREATE_TABLES = False
|
22 | 22 | SQL_LOGGING = True
|
23 | 23 |
|
24 |
| -CURRENT_DATABASE_SCHEME_VERSION = 5 |
| 24 | +CURRENT_DATABASE_SCHEME_VERSION = 6 |
25 | 25 |
|
26 | 26 | # List all Models
|
27 | 27 | MODELS = [PluginMetaDataModel, PrintJobModel, FilamentModel, TemperatureModel]
|
@@ -73,14 +73,73 @@ def _createOrUpgradeSchemeIfNecessary(self):
|
73 | 73 |
|
74 | 74 | def _upgradeDatabase(self,currentDatabaseSchemeVersion, targetDatabaseSchemeVersion):
|
75 | 75 |
|
76 |
| - migrationFunctions = [self._upgradeFrom1To2, self._upgradeFrom2To3, self._upgradeFrom3To4, self._upgradeFrom4To5] |
| 76 | + migrationFunctions = [self._upgradeFrom1To2, |
| 77 | + self._upgradeFrom2To3, |
| 78 | + self._upgradeFrom3To4, |
| 79 | + self._upgradeFrom4To5, |
| 80 | + self._upgradeFrom5To6, |
| 81 | + self._upgradeFrom6To7, |
| 82 | + self._upgradeFrom7To8, |
| 83 | + self._upgradeFrom8To9, |
| 84 | + self._upgradeFrom9To10 |
| 85 | + ] |
77 | 86 |
|
78 | 87 | for migrationMethodIndex in range(currentDatabaseSchemeVersion -1, targetDatabaseSchemeVersion -1):
|
79 | 88 | self._logger.info("Database migration from '" + str(migrationMethodIndex + 1) + "' to '" + str(migrationMethodIndex + 2) + "'")
|
80 | 89 | migrationFunctions[migrationMethodIndex]()
|
81 | 90 | pass
|
82 | 91 | pass
|
83 | 92 |
|
| 93 | + def _upgradeFrom9To10(self): |
| 94 | + self._logger.info(" Starting 9 -> 10") |
| 95 | + self._logger.info(" Successfully 9 -> 10") |
| 96 | + pass |
| 97 | + |
| 98 | + def _upgradeFrom8To9(self): |
| 99 | + self._logger.info(" Starting 8 -> 9") |
| 100 | + self._logger.info(" Successfully 8 -> 9") |
| 101 | + pass |
| 102 | + |
| 103 | + def _upgradeFrom7To8(self): |
| 104 | + self._logger.info(" Starting 7 -> 8") |
| 105 | + self._logger.info(" Successfully 7 -> 8") |
| 106 | + pass |
| 107 | + |
| 108 | + def _upgradeFrom6To7(self): |
| 109 | + self._logger.info(" Starting 6 -> 7") |
| 110 | + self._logger.info(" Successfully 6 -> 7") |
| 111 | + pass |
| 112 | + |
| 113 | + def _upgradeFrom5To6(self): |
| 114 | + self._logger.info(" Starting 5 -> 6") |
| 115 | + # What is changed: |
| 116 | + # - FilamentModel: |
| 117 | + # - renameing: |
| 118 | + # profileVendor -> vendor |
| 119 | + # spoolWeight -> weight |
| 120 | + # (ALTER TABLE spo_spoolmodel RENAME COLUMN encloserTemperature to enclosureTemperature; not working SQLite did not support the ALTER TABLE RENAME COLUMN syntax before version 3.25.0. |
| 121 | + # see https://www.sqlitetutorial.net/sqlite-rename-column/#:~:text=SQLite%20did%20not%20support%20the,the%20version%20lower%20than%203.25.) |
| 122 | + |
| 123 | + connection = sqlite3.connect(self._databaseFileLocation) |
| 124 | + cursor = connection.cursor() |
| 125 | + |
| 126 | + sql = """ |
| 127 | + PRAGMA foreign_keys=off; |
| 128 | + BEGIN TRANSACTION; |
| 129 | +
|
| 130 | + UPDATE 'pjh_filamentmodel' SET toolId='total' where toolId is NULL; |
| 131 | +
|
| 132 | + UPDATE 'pjh_pluginmetadatamodel' SET value=6 WHERE key='databaseSchemeVersion'; |
| 133 | + COMMIT; |
| 134 | + PRAGMA foreign_keys=on; |
| 135 | + """ |
| 136 | + cursor.executescript(sql) |
| 137 | + |
| 138 | + connection.close() |
| 139 | + self._logger.info(" Successfully 5 -> 6") |
| 140 | + pass |
| 141 | + |
| 142 | + |
84 | 143 | def _upgradeFrom4To5(self):
|
85 | 144 | self._logger.info(" Starting 4 -> 5")
|
86 | 145 | # What is changed:
|
@@ -477,7 +536,8 @@ def calculatePrintJobsStatisticByQuery(self, tableQuery):
|
477 | 536 | printJobCount = printJobCount + 1
|
478 | 537 | if (firstDate == None):
|
479 | 538 | firstDate = job.printStartDateTime
|
480 |
| - lastDate = job.printEndDateTime |
| 539 | + if (job.printEndDateTime != None): |
| 540 | + lastDate = job.printEndDateTime |
481 | 541 | tempJobFileSize = job.fileSize
|
482 | 542 | if (tempJobFileSize == None):
|
483 | 543 | tempJobFileSize = 0
|
@@ -520,7 +580,10 @@ def calculatePrintJobsStatisticByQuery(self, tableQuery):
|
520 | 580 |
|
521 | 581 | # do formatting
|
522 | 582 | queryString = self._buildQueryString(tableQuery)
|
523 |
| - fromToString = firstDate.strftime('%d.%m.%Y %H:%M') + " - " + lastDate.strftime('%d.%m.%Y %H:%M') |
| 583 | + lastDateString = "" |
| 584 | + if (lastDate != None): |
| 585 | + lastDateString = lastDate.strftime('%d.%m.%Y %H:%M') |
| 586 | + fromToString = firstDate.strftime('%d.%m.%Y %H:%M') + " - " + lastDateString |
524 | 587 | durationString = StringUtils.secondsToText(duration)
|
525 | 588 | lengthString = self._buildLengthString(length)
|
526 | 589 | weightString = self._buildWeightString(weight)
|
|
0 commit comments