X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcore%2Fabstractsqlstorage.h;h=c911732a40c44fc69c373e7c7f6a55656c97b22d;hb=c3263d1f2db00c39c2057b4126f9a1599d7f9570;hp=9bcd28684acd2e2053ac316e6b8db1d978cfcace;hpb=68878dc8366f2f4a0afe132847aad9a51a80cdbf;p=quassel.git diff --git a/src/core/abstractsqlstorage.h b/src/core/abstractsqlstorage.h index 9bcd2868..c911732a 100644 --- a/src/core/abstractsqlstorage.h +++ b/src/core/abstractsqlstorage.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -42,9 +43,25 @@ public: virtual std::unique_ptr createMigrationReader() { return {}; } virtual std::unique_ptr createMigrationWriter() { return {}; } + /** + * An SQL query with associated resource filename + */ + struct SqlQueryResource { + QString queryString; ///< SQL query string + QString queryFilename; ///< Path to the resource file providing this query + + SqlQueryResource(const QString& queryString, const QString& queryFilename) + : queryString(std::move(queryString)), + queryFilename(std::move(queryFilename)) {} + }; + public slots: - virtual State init(const QVariantMap &settings = QVariantMap()); - virtual bool setup(const QVariantMap &settings = QVariantMap()); + virtual State init(const QVariantMap &settings = QVariantMap(), + const QProcessEnvironment &environment = {}, + bool loadFromEnvironment = false); + virtual bool setup(const QVariantMap &settings = QVariantMap(), + const QProcessEnvironment &environment = {}, + bool loadFromEnvironment = false); protected: inline virtual void sync() {}; @@ -70,19 +87,55 @@ protected: */ QString queryString(const QString &queryName, int version = 0); - QStringList setupQueries(); + /** + * Gets the collection of SQL setup queries and filenames to create a new database + * + * @return List of SQL query strings and filenames + */ + QList setupQueries(); - QStringList upgradeQueries(int ver); + /** + * Gets the collection of SQL upgrade queries and filenames for a given schema version + * + * @param ver SQL schema version + * @return List of SQL query strings and filenames + */ + QList upgradeQueries(int ver); bool upgradeDb(); bool watchQuery(QSqlQuery &query); int schemaVersion(); virtual int installedSchemaVersion() { return -1; }; - virtual bool updateSchemaVersion(int newVersion) = 0; + + /** + * Update the stored schema version number, optionally clearing the record of mid-schema steps + * + * @param newVersion New schema version number + * @param clearUpgradeStep If true, clear the record of any in-progress schema upgrades + * @return + */ + virtual bool updateSchemaVersion(int newVersion, bool clearUpgradeStep = true) = 0; + virtual bool setupSchemaVersion(int version) = 0; - virtual void setConnectionProperties(const QVariantMap &properties) = 0; + /** + * Gets the last successful schema upgrade step, or an empty string if no upgrade is in progress + * + * @return Filename of last successful schema upgrade query, or empty string if not upgrading + */ + virtual QString schemaVersionUpgradeStep(); + + /** + * Sets the last successful schema upgrade step + * + * @param upgradeQuery The filename of the last successful schema upgrade query + * @return True if successfully set, otherwise false + */ + virtual bool setSchemaVersionUpgradeStep(QString upgradeQuery) = 0; + virtual void setConnectionProperties(const QVariantMap &properties, + const QProcessEnvironment &environment, + bool loadFromEnvironment) = 0; virtual QString driverName() = 0; inline virtual QString hostName() { return QString(); } inline virtual int port() { return -1; } @@ -118,6 +171,14 @@ private: QHash _connectionPool; }; +struct SenderData { + QString sender; + QString realname; + QString avatarurl; + + friend uint qHash(const SenderData &key); + friend bool operator==(const SenderData &a, const SenderData &b); +}; // ======================================== // AbstractSqlStorage::Connection @@ -153,8 +214,10 @@ public: }; struct SenderMO { - int senderId; + qint64 senderId; QString sender; + QString realname; + QString avatarurl; SenderMO() : senderId(0) {} }; @@ -173,7 +236,7 @@ public: bool autoAwayReasonEnabled; bool detachAwayEnabled; QString detachAwayReason; - bool detchAwayReasonEnabled; + bool detachAwayReasonEnabled; QString ident; QString kickReason; QString partReason; @@ -189,37 +252,35 @@ public: }; struct NetworkMO { - NetworkId networkid; UserId userid; QString networkname; - IdentityId identityid; - QString encodingcodec; - QString decodingcodec; - QString servercodec; - bool userandomserver; QString perform; - bool useautoidentify; QString autoidentifyservice; QString autoidentifypassword; - bool useautoreconnect; + QString saslaccount; + QString saslpassword; + QString servercodec; + QString encodingcodec; + QString decodingcodec; + QString usermode; + QString awaymessage; + QString attachperform; + QString detachperform; + NetworkId networkid; + IdentityId identityid; + int messagerateburstsize; + int messageratedelay; int autoreconnectinterval; int autoreconnectretries; - bool unlimitedconnectretries; bool rejoinchannels; - // Custom rate limiting + bool userandomserver; + bool useautoidentify; + bool usesasl; + bool useautoreconnect; + bool unlimitedconnectretries; bool usecustommessagerate; - int messagerateburstsize; - int messageratedelay; bool unlimitedmessagerate; - // ... bool connected; - QString usermode; - QString awaymessage; - QString attachperform; - QString detachperform; - bool usesasl; - QString saslaccount; - QString saslpassword; }; struct BufferMO { @@ -230,12 +291,14 @@ public: QString buffername; QString buffercname; int buffertype; - int lastmsgid; - int lastseenmsgid; - int markerlinemsgid; + qint64 lastmsgid; + qint64 lastseenmsgid; + qint64 markerlinemsgid; int bufferactivity; + int highlightcount; QString key; bool joined; + QString cipher; }; struct BacklogMO { @@ -244,7 +307,7 @@ public: BufferId bufferid; int type; int flags; - int senderid; + qint64 senderid; QString senderprefixes; QString message; }; @@ -273,6 +336,11 @@ public: QByteArray settingvalue; }; + struct CoreStateMO { + QString key; + QByteArray value; + }; + enum MigrationObject { QuasselUser, Sender, @@ -282,7 +350,8 @@ public: Buffer, Backlog, IrcServer, - UserSetting + UserSetting, + CoreState }; AbstractSqlMigrator(); @@ -328,6 +397,7 @@ public: virtual bool readMo(BacklogMO &backlog) = 0; virtual bool readMo(IrcServerMO &ircserver) = 0; virtual bool readMo(UserSettingMO &userSetting) = 0; + virtual bool readMo(CoreStateMO &coreState) = 0; bool migrateTo(AbstractSqlMigrationWriter *writer); @@ -353,6 +423,7 @@ public: virtual bool writeMo(const BacklogMO &backlog) = 0; virtual bool writeMo(const IrcServerMO &ircserver) = 0; virtual bool writeMo(const UserSettingMO &userSetting) = 0; + virtual bool writeMo(const CoreStateMO &coreState) = 0; inline bool migrateFrom(AbstractSqlMigrationReader *reader) { return reader->migrateTo(this); }