Skip to content

Commit

Permalink
migration: Add remedial migration after #3553.
Browse files Browse the repository at this point in the history
Now that #3553 is fixed so that migrations actually work again, let's
ensure that any install which missed a previous migration due to that
bug gets the effect of it now.

Fortunately, because `dropCache` is idempotent, this is pretty simple.
We can drop the `AsyncStorage.removeItem`, too, because we've re-used
the same `messages` key since then.
  • Loading branch information
gnprice committed Jul 13, 2019
1 parent 5c00b7f commit bd6c155
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/boot/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { applyMiddleware, compose, createStore } from 'redux';
import type { Store } from 'redux';
import { persistStore, autoRehydrate } from 'redux-persist';
import type { Config } from 'redux-persist';
import { AsyncStorage } from 'react-native';

import type { Action, GlobalState } from '../types';
import rootReducer from './reducers';
Expand Down Expand Up @@ -88,21 +87,23 @@ const migrations: { [string]: (GlobalState) => GlobalState } = {
//
// Still, it seems a more helpful approximation than nothing. Where the
// falsehoods show through, we freely tell Flow to ignore them.
'0': state => {
// We deleted `messages` and created `narrows`. (Really we renamed
// `messages` to `narrows, but a migration for delete + create is
// simpler, and is good enough because these are "cache" data anyway.)
AsyncStorage.removeItem('reduxPersist:messages');
// $FlowMigrationFudge
return dropCache(state);
},
// $FlowMigrationFudge
'3': dropCache,
'4': state => ({

// Example if removing a top-level subtree entirely:
// import { AsyncStorage } from 'react-native';
// ...
// AsyncStorage.removeItem('reduxPersist:messages');

'6': state => ({
// This rolls up all previous migrations, to clean up after our bug #3553.
// Mostly we can just `dropCache`, to reload data from the server...
...dropCache(state),
accounts: state.accounts.map(a => ({ ...a, ackedPushToken: null })),
accounts: state.accounts.map(a => ({
...a,
// but in the case of `ackedPushToken` let's be a bit more precise,
// and avoid clobbering it if present.
ackedPushToken: a.ackedPushToken !== undefined ? a.ackedPushToken : null,
})),
}),
'5': dropCache,
};

const reduxPersistConfig: Config = {
Expand Down

0 comments on commit bd6c155

Please sign in to comment.