diff options
author | Tobias Fella <fella@posteo.de> | 2022-03-23 20:42:28 +0100 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2022-03-23 20:42:28 +0100 |
commit | 7cd71c978f39a0bd8f82ebdf01cbaaf317ebe020 (patch) | |
tree | 8ef848f79de35e055d3be7d0c7c8fb9a09caedd3 /lib | |
parent | 336f8b2e93b43e85b9ea4b9da2b2b34221e657aa (diff) | |
download | libquotient-7cd71c978f39a0bd8f82ebdf01cbaaf317ebe020.tar.gz libquotient-7cd71c978f39a0bd8f82ebdf01cbaaf317ebe020.zip |
Add database migration
Diffstat (limited to 'lib')
-rw-r--r-- | lib/database.cpp | 15 | ||||
-rw-r--r-- | lib/database.h | 1 |
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/database.cpp b/lib/database.cpp index d9dce517..b0e3b415 100644 --- a/lib/database.cpp +++ b/lib/database.cpp @@ -33,6 +33,7 @@ Database::Database(const QString& matrixId, const QString& deviceId, QObject* pa switch(version()) { case 0: migrateTo1(); case 1: migrateTo2(); + case 2: migrateTo3(); } } @@ -89,12 +90,11 @@ void Database::migrateTo1() execute(QStringLiteral("CREATE TABLE accounts (pickle TEXT);")); execute(QStringLiteral("CREATE TABLE olm_sessions (senderKey TEXT, sessionId TEXT, pickle TEXT);")); execute(QStringLiteral("CREATE TABLE inbound_megolm_sessions (roomId TEXT, senderKey TEXT, sessionId TEXT, pickle TEXT);")); - execute(QStringLiteral("CREATE TABLE outbound_megolm_sessions (roomId TEXT, sessionId TEXT, pickle TEXT, creationTime TEXT, messageCount INTEGER);")); + execute(QStringLiteral("CREATE TABLE outbound_megolm_sessions (roomId TEXT, senderKey TEXT, sessionId TEXT, pickle TEXT);")); execute(QStringLiteral("CREATE TABLE group_session_record_index (roomId TEXT, sessionId TEXT, i INTEGER, eventId TEXT, ts INTEGER);")); execute(QStringLiteral("CREATE TABLE tracked_users (matrixId TEXT);")); execute(QStringLiteral("CREATE TABLE outdated_users (matrixId TEXT);")); execute(QStringLiteral("CREATE TABLE tracked_devices (matrixId TEXT, deviceId TEXT, curveKeyId TEXT, curveKey TEXT, edKeyId TEXT, edKey TEXT);")); - execute(QStringLiteral("CREATE TABLE sent_megolm_sessions (roomId TEXT, userId TEXT, deviceId TEXT, identityKey TEXT, sessionId TEXT, i INTEGER);")); execute(QStringLiteral("PRAGMA user_version = 1;")); commit(); @@ -106,7 +106,7 @@ void Database::migrateTo2() transaction(); execute(QStringLiteral("ALTER TABLE inbound_megolm_sessions ADD ed25519Key TEXT")); execute(QStringLiteral("ALTER TABLE olm_sessions ADD lastReceived TEXT")); - + // Add indexes for improving queries speed on larger database execute(QStringLiteral("CREATE INDEX sessions_session_idx ON olm_sessions(sessionId)")); execute(QStringLiteral("CREATE INDEX outbound_room_idx ON outbound_megolm_sessions(roomId)")); @@ -116,6 +116,15 @@ void Database::migrateTo2() commit(); } +void Database::migrateTo3() +{ + qCDebug(DATABASE) << "Migrating database to version 3"; + execute(QStringLiteral("CREATE TABLE sent_megolm_sessions (roomId TEXT, userId TEXT, deviceId TEXT, identityKey TEXT, sessionId TEXT, i INTEGER);")); + execute(QStringLiteral("ALTER TABLE outbound_megolm_sessions ADD creationTime TEXT;")); + execute(QStringLiteral("ALTER TABLE outbound_megolm_sessions ADD messageCount INTEGER;")); + execute(QStringLiteral("PRAGMA user_version = 3;")); +} + QByteArray Database::accountPickle() { auto query = prepareQuery(QStringLiteral("SELECT pickle FROM accounts;")); diff --git a/lib/database.h b/lib/database.h index 76d86f12..4a047161 100644 --- a/lib/database.h +++ b/lib/database.h @@ -52,6 +52,7 @@ public: private: void migrateTo1(); void migrateTo2(); + void migrateTo3(); QString m_matrixId; }; } |