diff --git a/web/redux/persist-constants.js b/web/redux/persist-constants.js --- a/web/redux/persist-constants.js +++ b/web/redux/persist-constants.js @@ -3,5 +3,6 @@ const rootKey = 'root'; const rootKeyPrefix = 'persist:'; const completeRootKey = `${rootKeyPrefix}${rootKey}`; +const storeVersion = 75; -export { rootKey, rootKeyPrefix, completeRootKey }; +export { rootKey, rootKeyPrefix, completeRootKey, storeVersion }; diff --git a/web/redux/persist.js b/web/redux/persist.js --- a/web/redux/persist.js +++ b/web/redux/persist.js @@ -46,7 +46,7 @@ handleReduxMigrationFailure, persistWhitelist, } from './handle-redux-migration-failure.js'; -import { rootKey, rootKeyPrefix } from './persist-constants.js'; +import { rootKey, rootKeyPrefix, storeVersion } from './persist-constants.js'; import type { AppState } from './redux-setup.js'; import { unshimClientDB } from './unshim-utils.js'; import { authoritativeKeyserverID } from '../authoritative-keyserver.js'; @@ -523,7 +523,7 @@ migrations, migrateStorageToSQLite, ): any), - version: 75, + version: storeVersion, transforms: [messageStoreMessagesBlocklistTransform, keyserverStoreTransform], }; diff --git a/web/shared-worker/worker/backup.js b/web/shared-worker/worker/backup.js --- a/web/shared-worker/worker/backup.js +++ b/web/shared-worker/worker/backup.js @@ -3,13 +3,17 @@ import backupService from 'lib/facts/backup-service.js'; import { decryptCommon } from 'lib/media/aes-crypto-utils-common.js'; import type { AuthMetadata } from 'lib/shared/identity-client-context.js'; +import { syncedMetadataNames } from 'lib/types/synced-metadata-types.js'; import { getProcessingStoreOpsExceptionMessage } from './process-operations.js'; import { BackupClient, RequestedData, } from '../../backup-client-wasm/wasm/backup-client-wasm.js'; -import { completeRootKey } from '../../redux/persist-constants.js'; +import { + completeRootKey, + storeVersion, +} from '../../redux/persist-constants.js'; import type { EmscriptenModule } from '../types/module.js'; import type { SQLiteQueryExecutor } from '../types/sqlite-query-executor.js'; import { COMM_SQLITE_BACKUP_RESTORE_DATABASE_PATH } from '../utils/constants.js'; @@ -55,6 +59,13 @@ backupDataKey, ); + const backupVersion = sqliteQueryExecutor + .getAllSyncedMetadata() + .find(entry => entry.name === syncedMetadataNames.DB_VERSION)?.data; + if (!backupVersion || parseInt(backupVersion) > (storeVersion ?? 0)) { + throw new Error(`Incompatible backup version ${backupVersion ?? -1}`); + } + sqliteQueryExecutor.setPersistStorageItem( completeRootKey, reduxPersistData,