mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #3904 from MetaMask/migrations-template
meta - create a migration template
This commit is contained in:
commit
b8efe120a9
29
app/scripts/migrations/template.js
Normal file
29
app/scripts/migrations/template.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// next version number
|
||||||
|
const version = 0
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
description of migration and what it does
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
const clone = require('clone')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
version,
|
||||||
|
|
||||||
|
migrate: async function (originalVersionedData) {
|
||||||
|
const versionedData = clone(originalVersionedData)
|
||||||
|
versionedData.meta.version = version
|
||||||
|
const state = versionedData.data
|
||||||
|
const newState = transformState(state)
|
||||||
|
versionedData.data = newState
|
||||||
|
return versionedData
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformState (state) {
|
||||||
|
const newState = state
|
||||||
|
// transform state here
|
||||||
|
return newState
|
||||||
|
}
|
17
test/unit/migrations/template-test.js
Normal file
17
test/unit/migrations/template-test.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
const assert = require('assert')
|
||||||
|
const migrationTemplate = require('../../../app/scripts/migrations/template')
|
||||||
|
const properTime = (new Date()).getTime()
|
||||||
|
const storage = {
|
||||||
|
meta: {},
|
||||||
|
data: {},
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('storage is migrated successfully', () => {
|
||||||
|
it('should work', (done) => {
|
||||||
|
migrationTemplate.migrate(storage)
|
||||||
|
.then((migratedData) => {
|
||||||
|
assert.equal(migratedData.meta.version, 0)
|
||||||
|
done()
|
||||||
|
}).catch(done)
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user