diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h @@ -196,6 +196,8 @@ virtual std::vector getDMOperations() const = 0; virtual std::vector getDMOperationsByType(const std::string &operationType) const = 0; + virtual int getDatabaseVersion() const = 0; + virtual ~DatabaseQueryExecutor() = default; }; diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h @@ -188,6 +188,7 @@ std::vector getDMOperations() const override; std::vector getDMOperationsByType(const std::string &operationType) const override; + int getDatabaseVersion() const override; }; } // namespace comm diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -1540,4 +1540,8 @@ this->connectionManager->restoreFromBackupLog(backupLog); } +int SQLiteQueryExecutor::getDatabaseVersion() const { + return SQLiteUtils::getDatabaseVersion(this->getConnection()); +} + } // namespace comm diff --git a/web/cpp/SQLiteQueryExecutorBindings.cpp b/web/cpp/SQLiteQueryExecutorBindings.cpp --- a/web/cpp/SQLiteQueryExecutorBindings.cpp +++ b/web/cpp/SQLiteQueryExecutorBindings.cpp @@ -340,7 +340,8 @@ "deleteMessageFromSearchIndex", &SQLiteQueryExecutor::deleteMessageFromSearchIndex) .function("searchMessages", &SQLiteQueryExecutor::searchMessages) - .function("fetchMessages", &SQLiteQueryExecutor::fetchMessages); + .function("fetchMessages", &SQLiteQueryExecutor::fetchMessages) + .function("getDatabaseVersion", &SQLiteQueryExecutor::getDatabaseVersion); class_("SQLiteBackup") .class_function( diff --git a/web/shared-worker/_generated/comm_query_executor.wasm b/web/shared-worker/_generated/comm_query_executor.wasm index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ d.key === draftKey); expect(backupDraft?.text).toBe(backupDraftContent); }); + + it('returns correct database version', () => { + const migratedFilePath = 'migrated.sqlite'; + const migratedQueryExecutor = new dbModule.SQLiteQueryExecutor( + migratedFilePath, + false, + ); + expect(migratedQueryExecutor.getDatabaseVersion()).toBeGreaterThan(0); + clearSensitiveData(dbModule, migratedFilePath, migratedQueryExecutor); + + const notMigratedFilePath = 'not-migrated.sqlite'; + const notMigratedQueryExecutor = new dbModule.SQLiteQueryExecutor( + notMigratedFilePath, + true, + ); + expect(notMigratedQueryExecutor.getDatabaseVersion()).toBe(0); + clearSensitiveData(dbModule, notMigratedFilePath, notMigratedQueryExecutor); + }); }); diff --git a/web/shared-worker/types/sqlite-query-executor.js b/web/shared-worker/types/sqlite-query-executor.js --- a/web/shared-worker/types/sqlite-query-executor.js +++ b/web/shared-worker/types/sqlite-query-executor.js @@ -217,6 +217,8 @@ messageIDCursor: ?string, ): $ReadOnlyArray; + getDatabaseVersion(): number; + // method is provided to manually signal that a C++ object // is no longer needed and can be deleted delete(): void;