Page MenuHomePhorge

D14909.1765167987.diff
No OneTemporary

Size
9 KB
Referenced Files
None
Subscribers
None

D14909.1765167987.diff

diff --git a/lib/backup/use-user-data-restore.js b/lib/backup/use-user-data-restore.js
--- a/lib/backup/use-user-data-restore.js
+++ b/lib/backup/use-user-data-restore.js
@@ -65,122 +65,132 @@
// 1. Download database and apply all logs
if (startStepIndex === 0) {
- await dispatchActionPromise(
+ const restoreUserDataPromise = sqliteAPI.restoreUserData(
+ backupData,
+ identityAuthResult,
+ );
+ void dispatchActionPromise(
restoreUserDataStepActionTypes,
- sqliteAPI.restoreUserData(backupData, identityAuthResult),
+ restoreUserDataPromise,
undefined,
{ step: 'restore_database' },
);
+ await restoreUserDataPromise;
}
// 2. Check database versions and migrate if needed
if (startStepIndex <= 1) {
- await dispatchActionPromise(
+ const migrateBackupSchemaPromise = (async () => {
+ const [mainDatabaseVersion, restoredDatabaseVersion] =
+ await Promise.all([
+ sqliteAPI.getDatabaseVersion(databaseIdentifier.MAIN),
+ sqliteAPI.getDatabaseVersion(databaseIdentifier.RESTORED),
+ ]);
+
+ if (mainDatabaseVersion === restoredDatabaseVersion) {
+ addLog(
+ 'User Data Restore',
+ `Main and restored database versions are equal: ` +
+ `${mainDatabaseVersion}, skipping schema migrations.`,
+ new Set([logTypes.BACKUP]),
+ );
+ } else if (mainDatabaseVersion > restoredDatabaseVersion) {
+ addLog(
+ 'User Data Restore',
+ `Main database version (${mainDatabaseVersion}) is higher ` +
+ `than restored database version (${restoredDatabaseVersion}), ` +
+ `migrating schema.`,
+ new Set([logTypes.BACKUP]),
+ );
+ await sqliteAPI.migrateBackupSchema();
+ } else if (mainDatabaseVersion < restoredDatabaseVersion) {
+ addLog(
+ 'User Data Restore',
+ `Main database version (${mainDatabaseVersion}) is lower ` +
+ `than restored database version (${restoredDatabaseVersion}), ` +
+ ` aborting.`,
+ new Set([logTypes.BACKUP, logTypes.ERROR]),
+ );
+ throw new Error('backup_is_newer');
+ }
+ })();
+ void dispatchActionPromise(
restoreUserDataStepActionTypes,
- (async () => {
- const [mainDatabaseVersion, restoredDatabaseVersion] =
- await Promise.all([
- sqliteAPI.getDatabaseVersion(databaseIdentifier.MAIN),
- sqliteAPI.getDatabaseVersion(databaseIdentifier.RESTORED),
- ]);
-
- if (mainDatabaseVersion === restoredDatabaseVersion) {
- addLog(
- 'User Data Restore',
- `Main and restored database versions are equal: ` +
- `${mainDatabaseVersion}, skipping schema migrations.`,
- new Set([logTypes.BACKUP]),
- );
- } else if (mainDatabaseVersion > restoredDatabaseVersion) {
- addLog(
- 'User Data Restore',
- `Main database version (${mainDatabaseVersion}) is higher ` +
- `than restored database version (${restoredDatabaseVersion}), ` +
- `migrating schema.`,
- new Set([logTypes.BACKUP]),
- );
- await sqliteAPI.migrateBackupSchema();
- } else if (mainDatabaseVersion < restoredDatabaseVersion) {
- addLog(
- 'User Data Restore',
- `Main database version (${mainDatabaseVersion}) is lower ` +
- `than restored database version (${restoredDatabaseVersion}), ` +
- ` aborting.`,
- new Set([logTypes.BACKUP, logTypes.ERROR]),
- );
- throw new Error('backup_is_newer');
- }
- })(),
+ migrateBackupSchemaPromise,
undefined,
{ step: 'migrate_backup_schema' },
);
+ await migrateBackupSchemaPromise;
}
// 3. Check store versions and migrate if needed
if (startStepIndex <= 2) {
- await dispatchActionPromise(
+ const runRestoredMigrationsPromise = (async () => {
+ const mainStoreVersion = getConfig().platformDetails.stateVersion;
+ const restoredStoreVersionString = await sqliteAPI.getSyncedMetadata(
+ syncedMetadataNames.STORE_VERSION,
+ databaseIdentifier.RESTORED,
+ );
+
+ if (!mainStoreVersion || !restoredStoreVersionString) {
+ addLog(
+ 'User Data Restore',
+ `Error when restoring user data, main store version(${
+ mainStoreVersion ?? 'undefined'
+ }) or restored store version (${
+ restoredStoreVersionString ?? 'undefined'
+ }) are undefined`,
+ new Set([logTypes.BACKUP, logTypes.ERROR]),
+ );
+ throw new Error('version_check_failed');
+ }
+
+ const restoredStoreVersion = parseInt(restoredStoreVersionString);
+
+ if (mainStoreVersion === restoredStoreVersion) {
+ addLog(
+ 'User Data Restore',
+ `Main and restored store versions are equal: ${mainStoreVersion}, ` +
+ `skipping data migrations`,
+ new Set([logTypes.BACKUP]),
+ );
+ } else if (mainStoreVersion > restoredStoreVersion) {
+ addLog(
+ 'User Data Restore',
+ `Main store version (${mainStoreVersion}) is higher than ` +
+ `restored store version (${restoredStoreVersion}), migrating data`,
+ new Set([logTypes.BACKUP]),
+ );
+ await runRestoredBackupMigrations();
+ } else if (mainStoreVersion < restoredStoreVersion) {
+ addLog(
+ 'User Data Restore',
+ `Main store version (${mainStoreVersion}) is lower than ` +
+ `restored store version (${restoredStoreVersion}), aborting`,
+ new Set([logTypes.BACKUP, logTypes.ERROR]),
+ );
+ throw new Error('backup_is_newer');
+ }
+ })();
+ void dispatchActionPromise(
restoreUserDataStepActionTypes,
- (async () => {
- const mainStoreVersion = getConfig().platformDetails.stateVersion;
- const restoredStoreVersionString =
- await sqliteAPI.getSyncedMetadata(
- syncedMetadataNames.STORE_VERSION,
- databaseIdentifier.RESTORED,
- );
-
- if (!mainStoreVersion || !restoredStoreVersionString) {
- addLog(
- 'User Data Restore',
- `Error when restoring user data, main store version(${
- mainStoreVersion ?? 'undefined'
- }) or restored store version (${
- restoredStoreVersionString ?? 'undefined'
- }) are undefined`,
- new Set([logTypes.BACKUP, logTypes.ERROR]),
- );
- throw new Error('version_check_failed');
- }
-
- const restoredStoreVersion = parseInt(restoredStoreVersionString);
-
- if (mainStoreVersion === restoredStoreVersion) {
- addLog(
- 'User Data Restore',
- `Main and restored store versions are equal: ${mainStoreVersion}, ` +
- `skipping data migrations`,
- new Set([logTypes.BACKUP]),
- );
- } else if (mainStoreVersion > restoredStoreVersion) {
- addLog(
- 'User Data Restore',
- `Main store version (${mainStoreVersion}) is higher than ` +
- `restored store version (${restoredStoreVersion}), migrating data`,
- new Set([logTypes.BACKUP]),
- );
- await runRestoredBackupMigrations();
- } else if (mainStoreVersion < restoredStoreVersion) {
- addLog(
- 'User Data Restore',
- `Main store version (${mainStoreVersion}) is lower than ` +
- `restored store version (${restoredStoreVersion}), aborting`,
- new Set([logTypes.BACKUP, logTypes.ERROR]),
- );
- throw new Error('backup_is_newer');
- }
- })(),
+ runRestoredMigrationsPromise,
undefined,
{ step: 'run_restored_backup_migrations' },
);
+ await runRestoredMigrationsPromise;
}
// 4. Copy content to main database
if (startStepIndex <= 3) {
- await dispatchActionPromise(
+ const copyContentPromise = sqliteAPI.copyContentFromBackupDatabase();
+ void dispatchActionPromise(
restoreUserDataStepActionTypes,
- sqliteAPI.copyContentFromBackupDatabase(),
+ copyContentPromise,
undefined,
{ step: 'copy_content_from_backup_db' },
);
+ await copyContentPromise;
}
// 5. Populate store

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 8, 4:26 AM (10 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5847055
Default Alt Text
D14909.1765167987.diff (9 KB)

Event Timeline