From f791282dd72f8aa9ca4cbce35be592245316a453 Mon Sep 17 00:00:00 2001 From: tommasini <46944231+tommasini@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:20:18 +0000 Subject: [PATCH] fix: migrations not being applied on 7.14.0 (#8271) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This pull request addresses an issue we were facing with migrations not being applied. The root cause was a change in how Babel v6 and v7 compiles ES6 `export default` to CommonJS, which differs from its previous behavior in Babel v5. source: https://stackoverflow.com/questions/33704714/cant-require-default-export-value-in-babel-6-x Previously, we were using `require` to load the migration files. However, due to the change in Babel's compilation, we would need to append `.default` to each migration when using `require`, as Babel now compiles `export default` to `exports.default`. To maintain consistency with the current pattern in our app and to avoid appending `.default` to each migration, I have switched from using `require` to `import`. This change aligns with our usage of ES6 syntax throughout the application and ensures that migrations are correctly applied. ## **Related issues** Fixes: ## **Manual testing steps** -> Install 7.12.5 -> Import an account via SRP -> Install 7.14.0 -> Vault recovery shouldn't happen ## **Screenshots/Recordings** This recording shows 7.14.0 after being updated from 7.12.5 IOS: https://github.com/MetaMask/metamask-mobile/assets/46944231/a7618468-c816-4b3c-a900-19ab3c2c2d5a Android: https://github.com/MetaMask/metamask-mobile/assets/46944231/c97a03eb-153f-4bc3-9103-b2712f99e41f ### **Before** ### **After** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [ ] I've linked related issues - [x] I've included manual testing steps - [x] I've included screenshots/recordings if applicable - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: sethkfman --- app/store/migrations/index.ts | 88 +++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/app/store/migrations/index.ts b/app/store/migrations/index.ts index 421ec976f9a..e71da0e3de1 100644 --- a/app/store/migrations/index.ts +++ b/app/store/migrations/index.ts @@ -1,37 +1,63 @@ -/* eslint-disable import/no-commonjs */ -/* eslint-disable @typescript-eslint/no-require-imports */ - import { MigrationManifest } from 'redux-persist'; +import migration00 from './000'; +import migration01 from './001'; +import migration02 from './002'; +import migration03 from './003'; +import migration04 from './004'; +import migration05 from './005'; +import migration06 from './006'; +import migration07 from './007'; +import migration08 from './008'; +import migration09 from './009'; +import migration10 from './010'; +import migration11 from './011'; +import migration12 from './012'; +import migration13 from './013'; +import migration14 from './014'; +import migration15 from './015'; +import migration16 from './016'; +import migration17 from './017'; +import migration18 from './018'; +import migration19 from './019'; +import migration20 from './020'; +import migration21 from './021'; +import migration22 from './022'; +import migration23 from './023'; +import migration24 from './024'; +import migration25 from './025'; +import migration26 from './026'; +import migration27 from './027'; + export const migrations: MigrationManifest = { - 0: require('./000'), - 1: require('./001'), - 2: require('./002'), - 3: require('./003'), - 4: require('./004'), - 5: require('./005'), - 6: require('./006'), - 7: require('./007'), - 8: require('./008'), - 9: require('./009'), - 10: require('./010'), - 11: require('./011'), - 12: require('./012'), - 13: require('./013'), - 14: require('./014'), - 15: require('./015'), - 16: require('./016'), - 17: require('./017'), - 18: require('./018'), - 19: require('./019'), - 20: require('./020'), - 21: require('./021'), - 22: require('./022'), - 23: require('./023'), - 24: require('./024'), - 25: require('./025'), - 26: require('./026'), - 27: require('./027'), + 0: migration00, + 1: migration01, + 2: migration02, + 3: migration03, + 4: migration04, + 5: migration05, + 6: migration06, + 7: migration07, + 8: migration08, + 9: migration09, + 10: migration10, + 11: migration11, + 12: migration12, + 13: migration13, + 14: migration14, + 15: migration15, + 16: migration16, + 17: migration17, + 18: migration18, + 19: migration19, + 20: migration20, + 21: migration21, + 22: migration22, + 23: migration23, + 24: migration24, + 25: migration25, + 26: migration26, + 27: migration27, }; // The latest (i.e. highest) version number.