-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathmigrateOnyx.js
49 lines (45 loc) · 1.97 KB
/
migrateOnyx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import _ from 'underscore';
import Log from './Log';
import AddEncryptedAuthToken from './migrations/AddEncryptedAuthToken';
import RenameActiveClientsKey from './migrations/RenameActiveClientsKey';
import RenamePriorityModeKey from './migrations/RenamePriorityModeKey';
import MoveToIndexedDB from './migrations/MoveToIndexedDB';
import RenameExpensifyNewsStatus from './migrations/RenameExpensifyNewsStatus';
import AddLastVisibleActionCreated from './migrations/AddLastVisibleActionCreated';
import KeyReportActionsByReportActionID from './migrations/KeyReportActionsByReportActionID';
import PersonalDetailsByAccountID from './migrations/PersonalDetailsByAccountID';
export default function () {
const startTime = Date.now();
Log.info('[Migrate Onyx] start');
return new Promise((resolve) => {
// Add all migrations to an array so they are executed in order
const migrationPromises = [
MoveToIndexedDB,
RenameActiveClientsKey,
RenamePriorityModeKey,
AddEncryptedAuthToken,
RenameExpensifyNewsStatus,
AddLastVisibleActionCreated,
KeyReportActionsByReportActionID,
PersonalDetailsByAccountID,
];
// Reduce all promises down to a single promise. All promises run in a linear fashion, waiting for the
// previous promise to finish before moving onto the next one.
/* eslint-disable arrow-body-style */
_.reduce(
migrationPromises,
(previousPromise, migrationPromise) => {
return previousPromise.then(() => {
return migrationPromise();
});
},
Promise.resolve(),
)
// Once all migrations are done, resolve the main promise
.then(() => {
const timeElapsed = Date.now() - startTime;
Log.info(`[Migrate Onyx] finished in ${timeElapsed}ms`);
resolve();
});
});
}