File indexing completed on 2025-01-05 03:53:59

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-04-16
0007  * Description : Core database Schema updater
0008  *
0009  * SPDX-FileCopyrightText: 2007-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_COREDB_SCHEMA_UPDATER_H
0017 #define DIGIKAM_COREDB_SCHEMA_UPDATER_H
0018 
0019 // Qt includes
0020 
0021 #include <QString>
0022 #include <QVariant>
0023 
0024 // Local includes
0025 
0026 #include "coredb.h"
0027 #include "coredbaccess.h"
0028 #include "coredbbackend.h"
0029 #include "dbengineparameters.h"
0030 
0031 namespace Digikam
0032 {
0033 
0034 class CoreDbAccess;
0035 class InitializationObserver;
0036 
0037 class DIGIKAM_DATABASE_EXPORT CoreDbSchemaUpdater
0038 {
0039 public:
0040 
0041     static int  schemaVersion();
0042     static int  filterSettingsVersion();
0043     static int  uniqueHashVersion();
0044     static bool isUniqueHashUpToDate();
0045 
0046 public:
0047 
0048     explicit CoreDbSchemaUpdater(CoreDB* const albumDB,
0049                                  CoreDbBackend* const backend,
0050                                  const DbEngineParameters& parameters);
0051     virtual ~CoreDbSchemaUpdater();
0052 
0053     bool  update();
0054     bool  updateUniqueHash();
0055     void  setObserver(InitializationObserver* const observer);
0056     const QString getLastErrorMessage();
0057     void  setCoreDbAccess(CoreDbAccess* const dbAccess);
0058 
0059 private:
0060 
0061     bool startUpdates();
0062     bool makeUpdates();
0063     bool beginWrapSchemaUpdateStep();
0064     bool endWrapSchemaUpdateStep(bool stepOperationSuccess, const QString& errorMsg);
0065     void defaultFilterSettings(QStringList& defaultItemFilter,
0066                                QStringList& defaultVideoFilter,
0067                                QStringList& defaultAudioFilter);
0068     void defaultIgnoreDirectoryFilterSettings(QStringList& defaultIgnoreDirectoryFilter);
0069     bool createFilterSettings();
0070     bool updateFilterSettings();
0071     bool createDatabase();
0072     bool createTables();
0073     bool createIndices();
0074     bool createTriggers();
0075     bool copyV3toV4(const QString& digikam3DBPath, const QString& currentDBPath);
0076     bool performUpdateToVersion(const QString& actionName, int newVersion, int newRequiredVersion);
0077     bool updateToVersion(int targetVersion);
0078     bool updateV4toV7();
0079     void setLegacySettingEntries();
0080     void readVersionSettings();
0081     void setVersionSettings();
0082 
0083 private:
0084 
0085     // cppcheck-suppress unusedPrivateFunction
0086     bool createTablesV3();
0087     // cppcheck-suppress unusedPrivateFunction
0088     void preAlpha010Update1();
0089     // cppcheck-suppress unusedPrivateFunction
0090     void preAlpha010Update2();
0091     // cppcheck-suppress unusedPrivateFunction
0092     void preAlpha010Update3();
0093     // cppcheck-suppress unusedPrivateFunction
0094     void beta010Update1();
0095     // cppcheck-suppress unusedPrivateFunction
0096     void beta010Update2();
0097 
0098 private:
0099 
0100     // Disable
0101     CoreDbSchemaUpdater(const CoreDbSchemaUpdater&)            = delete;
0102     CoreDbSchemaUpdater& operator=(const CoreDbSchemaUpdater&) = delete;
0103 
0104 private:
0105 
0106     class Private;
0107     Private* const d;
0108 };
0109 
0110 } // namespace Digikam
0111 
0112 #endif // DIGIKAM_COREDB_SCHEMA_UPDATER_H