Skip to content

Synced data migrations

William O'Beirne edited this page Jan 15, 2019 · 1 revision

If you change any of the reducer shapes that get backed up into storage, you'll need to create a migration to handle transforming any old stored data into the new format. Here's how to do it:

  1. Increment the version of the affected config in the SyncConfig object in src/app/utils/sync.ts
  2. Add a migration key that has a key for the version you're upgrading
    • For instance, if you're bumping from 1 -> 2, you'd have a migration config of { 2: (oldData) => ... }

Example

Old Code

Reducer shape

{
  data: string;
}

Config

{
  key: 'test',
  version: 1,
  encrypted: false,
  selector: selectTestedState,
  action: setTestedState,
  triggerActions: [...],
},

New Code

Reducer shape

{
  data: Array<string>;
}

Config

{
  key: 'test',
  version: 1,
  encrypted: false,
  selector: selectTestedState,
  action: setTestedState,
  triggerActions: [...],
  migrations: {
    2: (oldState: any) => {
      return [oldState.data];
    },
  },
},
Clone this wiki locally