From a97f6fcfb2cecb8fb15b3e23381d8e6729f596d1 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 25 Oct 2018 11:11:31 +0200 Subject: [PATCH] Database: future-proof to allow downgrade from future version The 2.6 client will introduce an index that depends on a custom function. This causes insersion onto the metadata database to fail if the database it opened with older version of the client. (Which will cause the client to abort) Delete this index in this version in order to allow downgrade. In addition, allow to load folder with version '2', but still write version '1' in the config file Of course this commit need not to be in the 2.6 release --- src/common/syncjournaldb.cpp | 14 ++++++++++++++ src/gui/folder.cpp | 2 +- src/gui/folder.h | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index 8dee44a2fc..736c4aefa9 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -313,6 +313,20 @@ bool SyncJournalDb::checkConnect() qCInfo(lcDb) << "sqlite3 version" << pragma1.stringValue(0); } + { + // Future version of the client (2.6) will have an index 'metadata_parent' which + // depends on a custom sqlite function which does not exist yet in 2.5. + // So make sure to remove the index if it exists, otherwise we will crash when inserting + // rows in the metadata database. + // This needs to be done before the synchronous mode is enabled. + // The 2.6 client will anyway re-creates this index if it does not exist. + SqlQuery query(_db); + query.prepare("DROP INDEX IF EXISTS metadata_parent;"); + if (!query.exec()) { + return sqlFail("updateMetadataTableStructure: remove index metadata_parent", query); + } + } + pragma1.prepare("PRAGMA journal_mode=" + _journalMode + ";"); if (!pragma1.exec()) { return sqlFail("Set PRAGMA journal_mode", pragma1); diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index fc7716ab79..62cb060f51 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -1142,7 +1142,7 @@ void FolderDefinition::save(QSettings &settings, const FolderDefinition &folder) settings.setValue(QLatin1String("paused"), folder.paused); settings.setValue(QLatin1String("ignoreHiddenFiles"), folder.ignoreHiddenFiles); settings.setValue(QLatin1String("usePlaceholders"), folder.useVirtualFiles); - settings.setValue(QLatin1String(versionC), maxSettingsVersion()); + settings.setValue(QLatin1String(versionC), 1); // Happens only on Windows when the explorer integration is enabled. if (!folder.navigationPaneClsid.isNull()) diff --git a/src/gui/folder.h b/src/gui/folder.h index 50e3e5fa2d..d7ce5fa9da 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -79,7 +79,7 @@ public: FolderDefinition *folder); /// The highest version in the settings that load() can read - static int maxSettingsVersion() { return 1; } + static int maxSettingsVersion() { return 2; } /// Ensure / as separator and trailing /. static QString prepareLocalPath(const QString &path);