File indexing completed on 2025-01-05 04:46:57
0001 /* 0002 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "dbconfig.h" 0010 0011 #include <optional> 0012 0013 namespace Akonadi 0014 { 0015 namespace Server 0016 { 0017 class DbConfigPostgresql : public DbConfig 0018 { 0019 public: 0020 /** 0021 * Constructs a new DbConfig for PostgreSQL reading configuration from the standard akonadiserverrc config file. 0022 */ 0023 explicit DbConfigPostgresql() = default; 0024 0025 /** 0026 * Constructs a new DbConfig for PostgreSQL reading configuration from the @p configFile. 0027 */ 0028 explicit DbConfigPostgresql(const QString &configFile); 0029 0030 /** 0031 * Returns the name of the used driver. 0032 */ 0033 QString driverName() const override; 0034 0035 /** 0036 * Returns the database name. 0037 */ 0038 QString databaseName() const override; 0039 0040 /** 0041 * Return path to the database file or directory. 0042 */ 0043 QString databasePath() const override; 0044 0045 /** 0046 * Sets path to the database file or directory. 0047 */ 0048 void setDatabasePath(const QString &path, QSettings &settings) override; 0049 0050 /** 0051 * This method is called whenever the Akonadi server is started 0052 * and before the initial database connection is set up. 0053 * 0054 * At this point the default settings should be determined, merged 0055 * with the given @p settings and written back if @p storeSettings is true. 0056 */ 0057 bool init(QSettings &settings, bool storeSettings = true, const QString &dbPathOverride = {}) override; 0058 0059 /** 0060 * This method checks if the requirements for this database connection are 0061 * met in the system (QPOSTGRESQL driver is available, postgresql binary is 0062 * found, etc.). 0063 */ 0064 bool isAvailable(QSettings &settings) override; 0065 0066 /** 0067 * This method applies the configured settings to the QtSql @p database 0068 * instance. 0069 */ 0070 void apply(QSqlDatabase &database) override; 0071 0072 /** 0073 * Returns whether an internal server needs to be used. 0074 */ 0075 bool useInternalServer() const override; 0076 0077 /** 0078 * This method is called to start an external server. 0079 */ 0080 bool startInternalServer() override; 0081 0082 /** 0083 * This method is called to stop the external server. 0084 */ 0085 void stopInternalServer() override; 0086 0087 /// reimpl 0088 bool disableConstraintChecks(const QSqlDatabase &db) override; 0089 0090 /// reimpl 0091 bool enableConstraintChecks(const QSqlDatabase &db) override; 0092 0093 protected: 0094 QStringList postgresSearchPaths(const QString &versionedPath) const; 0095 0096 private: 0097 struct Versions { 0098 int clusterVersion = 0; 0099 int pgServerVersion = 0; 0100 }; 0101 std::optional<Versions> checkPgVersion() const; 0102 bool upgradeCluster(int clusterVersion); 0103 bool runInitDb(const QString &dbDataPath); 0104 0105 bool checkServerIsRunning(); 0106 0107 QString mDatabaseName; 0108 QString mHostName; 0109 int mHostPort = 0; 0110 QString mUserName; 0111 QString mPassword; 0112 QString mConnectionOptions; 0113 QString mServerPath; 0114 QString mInitDbPath; 0115 QString mPgData; 0116 QString mPgUpgradePath; 0117 bool mInternalServer = true; 0118 }; 0119 0120 } // namespace Server 0121 } // namespace Akonadi