File indexing completed on 2025-01-05 04:46:58

0001 /*
0002     SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QMap>
0010 #include <QObject>
0011 #include <QSqlDatabase>
0012 #include <QStringList>
0013 
0014 class QDomElement;
0015 class DbUpdaterTest;
0016 
0017 namespace Akonadi
0018 {
0019 namespace Server
0020 {
0021 /**
0022  * @short A helper class that contains an update set.
0023  */
0024 class UpdateSet
0025 {
0026 public:
0027     using Map = QMap<int, UpdateSet>;
0028 
0029     UpdateSet()
0030         : version(-1)
0031         , abortOnFailure(false)
0032         , complex(false)
0033     {
0034     }
0035 
0036     int version;
0037     bool abortOnFailure;
0038     QStringList statements;
0039     bool complex;
0040 };
0041 
0042 /**
0043   Updates the database schema.
0044 */
0045 class DbUpdater : public QObject
0046 {
0047     Q_OBJECT
0048 
0049 public:
0050     /**
0051      * Creates a new database updates.
0052      *
0053      * @param database The reference to the database.
0054      * @param filename The file containing the update descriptions.
0055      */
0056     DbUpdater(const QSqlDatabase &database, const QString &filename);
0057 
0058     /**
0059      * Starts the update process.
0060      * On success true is returned, false otherwise.
0061      */
0062     bool run();
0063 
0064 private Q_SLOTS:
0065     bool complexUpdate_25();
0066     bool complexUpdate_36();
0067 
0068 private:
0069     friend class ::DbUpdaterTest;
0070 
0071     bool updateApplicable(const QString &backends) const;
0072     QString buildRawSqlStatement(const QDomElement &element) const;
0073 
0074     bool parseUpdateSets(int, UpdateSet::Map &updates) const;
0075 
0076     QSqlDatabase m_database;
0077     QString m_filename;
0078 };
0079 
0080 } // namespace Server
0081 } // namespace Akonadi