diff --git a/octoprint_SpoolManager/DatabaseManager.py b/octoprint_SpoolManager/DatabaseManager.py index 44981a3f..df75e682 100644 --- a/octoprint_SpoolManager/DatabaseManager.py +++ b/octoprint_SpoolManager/DatabaseManager.py @@ -21,7 +21,7 @@ FORCE_CREATE_TABLES = False -CURRENT_DATABASE_SCHEME_VERSION = 4 +CURRENT_DATABASE_SCHEME_VERSION = 5 # List all Models MODELS = [PluginMetaDataModel, SpoolModel] @@ -176,8 +176,39 @@ def _upgradeDatabase(self,currentDatabaseSchemeVersion, targetDatabaseSchemeVers def _upgradeFrom4To5(self): self._logger.info(" Starting 4 -> 5") + # What is changed: + # SpoolModel (needed, because lats script created a new table and altering was already done + # - materialCharacteristic = CharField(null=True, index=True) # strong, soft,... # since V4: new + # - material = CharField(null=True, index=True) # since V4: added index + # - vendor = CharField(null=True, index=True) # since V4: added index + connection = sqlite3.connect(self._databaseSettings.fileLocation) + cursor = connection.cursor() + + sql = """ + PRAGMA foreign_keys=off; + BEGIN TRANSACTION; + + ALTER TABLE 'spo_spoolmodel' ADD 'updated' DATETIME; + ALTER TABLE 'spo_spoolmodel' ADD 'originator' CHAR(60); + ALTER TABLE 'spo_spoolmodel' ADD 'materialCharacteristic' VARCHAR(255); + ALTER TABLE 'spo_spoolmodel' ADD 'isActive' INTEGER; + UPDATE 'spo_spoolmodel' SET isActive=1; + + CREATE INDEX spoolmodel_materialCharacteristic ON spo_spoolmodel (materialCharacteristic); + CREATE INDEX spoolmodel_material ON spo_spoolmodel (material); + CREATE INDEX spoolmodel_vendor ON spo_spoolmodel (vendor); + + UPDATE 'spo_pluginmetadatamodel' SET value=5 WHERE key='databaseSchemeVersion'; + COMMIT; + PRAGMA foreign_keys=on; + """ + cursor.executescript(sql) + + connection.close() self._logger.info(" Successfully 4 -> 5") + pass + def _upgradeFrom3To4(self): self._logger.info(" Starting 3 -> 4") diff --git a/setup.py b/setup.py index 4b7fb007..1d589a01 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module # -plugin_version = "1.3.3-dev" +plugin_version = "1.3.3" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module