[Server] Move the database lifecycle calls onto the interface (#7859)

This commit is contained in:
BruebachL 2026-11-10 12:16:34 +01:00 • committed by GitHub
parent 526d528e96
commit 0caacb27c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 6 deletions

View file

@ -816,6 +816,24 @@ public:
return false; return false;
} }
/** @brief Opens the server's main database connection; false when it cannot be opened. */
virtual bool openDatabase(const QString & /* type */,
const QString & /* hostName */,
const QString & /* databaseName */,
const QString & /* userName */,
const QString & /* password */)
{
return false;
}
/** @brief Drops expired deck shares; a no-op when persistence is unavailable. */
virtual void cleanupExpiredDeckShares()
{
}
/** @brief Purges expired legacy password backups; a no-op when persistence is unavailable. */
virtual void purgeExpiredLegacyBackups()
{
}
virtual void clearSessionTables() virtual void clearSessionTables()
{ {
} }

View file

@ -382,7 +382,7 @@ bool Servatrice::initServer()
if (databaseType != DatabaseNone) { if (databaseType != DatabaseNone) {
dbPrefix = getDBPrefixString(); dbPrefix = getDBPrefixString();
bool dbOpened = servatriceDatabaseInterface->initDatabase( bool dbOpened = servatriceDatabaseInterface->openDatabase(
"QMYSQL", getDBHostNameString(), getDBDatabaseNameString(), getDBUserNameString(), getDBPasswordString()); "QMYSQL", getDBHostNameString(), getDBDatabaseNameString(), getDBUserNameString(), getDBPasswordString());
if (!dbOpened) { if (!dbOpened) {
qCCritical(ServatriceLog) << "Failed to open the database; refusing to start."; qCCritical(ServatriceLog) << "Failed to open the database; refusing to start.";

View file

@ -81,7 +81,7 @@ void Servatrice_DatabaseInterface::initDatabase(const QSqlDatabase &_sqlDatabase
} }
} }
bool Servatrice_DatabaseInterface::initDatabase(const QString &type, bool Servatrice_DatabaseInterface::openDatabase(const QString &type,
const QString &hostName, const QString &hostName,
const QString &databaseName, const QString &databaseName,
const QString &userName, const QString &userName,

View file

@ -66,11 +66,11 @@ public slots:
public: public:
explicit Servatrice_DatabaseInterface(int _instanceId, Servatrice *_server); explicit Servatrice_DatabaseInterface(int _instanceId, Servatrice *_server);
~Servatrice_DatabaseInterface() override; ~Servatrice_DatabaseInterface() override;
bool initDatabase(const QString &type, bool openDatabase(const QString &type,
const QString &hostName, const QString &hostName,
const QString &databaseName, const QString &databaseName,
const QString &userName, const QString &userName,
const QString &password); const QString &password) override;
bool openDatabase(); bool openDatabase();
bool checkSql() override; bool checkSql() override;
QSqlQuery *prepareQuery(const QString &queryText); QSqlQuery *prepareQuery(const QString &queryText);
@ -94,7 +94,7 @@ public:
/** @brief Drop the account's legacy password backup. */ /** @brief Drop the account's legacy password backup. */
void clearLegacyBackup(const QString &user); void clearLegacyBackup(const QString &user);
/** @brief Drop every legacy password backup that has not been used within the TTL. */ /** @brief Drop every legacy password backup that has not been used within the TTL. */
void purgeExpiredLegacyBackups(); void purgeExpiredLegacyBackups() override;
int getUserIdInDB(const QString &name); int getUserIdInDB(const QString &name);
int getUserId(const QString &name) override; int getUserId(const QString &name) override;
bool addToBuddyList(int userId, int targetId) override; bool addToBuddyList(int userId, int targetId) override;
@ -172,7 +172,7 @@ public:
ReplayAccessResult getLatestReplayForGame(int gameId, int &replayId, QByteArray &data) override; ReplayAccessResult getLatestReplayForGame(int gameId, int &replayId, QByteArray &data) override;
ReplayWriteResult grantReplayAccessByName(int gameId, const QString &userName) override; ReplayWriteResult grantReplayAccessByName(int gameId, const QString &userName) override;
/** @brief Deletes all expired share bundles (cascades to their items). */ /** @brief Deletes all expired share bundles (cascades to their items). */
void cleanupExpiredDeckShares(); void cleanupExpiredDeckShares() override;
int getNextGameId() override; int getNextGameId() override;
int getNextReplayId() override; int getNextReplayId() override;