Skip to content

Commit

Permalink
fix: migration
Browse files Browse the repository at this point in the history
  • Loading branch information
limpbrains committed Feb 5, 2024
1 parent 051a187 commit 8d68c4f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const persistConfig = {
key: 'root',
storage: mmkvStorage,
// increase version after store shape changes
version: 34,
version: 35,
stateReconciler: autoMergeLevel2,
blacklist: ['receive', 'ui'],
migrate: createMigrate(migrations, { debug: __ENABLE_MIGRATION_DEBUG__ }),
Expand Down
42 changes: 33 additions & 9 deletions src/store/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { initialActivityState } from '../slices/activity';
import { initialChecksState } from '../slices/checks';
import { initialWidgetsState } from '../slices/widgets';
import cloneDeep from 'lodash/cloneDeep';
import { EBackupCategories } from '../utils/backup';

const migrations = {
0: (state): PersistedState => {
Expand Down Expand Up @@ -444,18 +444,42 @@ const migrations = {
};
}

// force backup
const backup = cloneDeep(initialBackupState);
for (const key in initialBackupState) {
backup[key].synced = backup[key].required - 10;
const now = Date.now();
const old = state.backup;
const backup = {};

for (const [oldKey, newKey] of [
['remoteBlocktankBackup', EBackupCategories.blocktank],
['remoteLdkActivityBackup', EBackupCategories.ldkActivity],
['remoteMetadataBackup', EBackupCategories.metadata],
['remoteSettingsBackup', EBackupCategories.settings],
['remoteSlashtagsBackup', EBackupCategories.slashtags],
['remoteWidgetsBackup', EBackupCategories.widgets],
]) {
const oldLastSync = old[`${oldKey}LastSync`];
const oldSynced = old[`${oldKey}Synced`];
const oldSyncRequired = old[`${oldKey}SyncRequired`];

if (oldSynced === false && !oldSyncRequired) {
// backup not required
backup[newKey] = {
required: now - 1000,
synced: now,
running: false,
};
} else {
// force backup
backup[newKey] = {
required: now,
synced: oldLastSync ?? now - 1000,
running: false,
};
}
}

return {
...state,
backup: {
...backup,
...state.backup,
},
backup,
lightning: {
...state.lightning,
nodes: newNodes,
Expand Down

0 comments on commit 8d68c4f

Please sign in to comment.