-
Notifications
You must be signed in to change notification settings - Fork 236
INT-1393 migrate userdata #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
var Preferences = require('../models/preferences'); | ||
var User = require('../models/user'); | ||
var pkg = require('../../../package.json'); | ||
var async = require('async'); | ||
var app = require('ampersand-app'); | ||
|
||
var PreferenceMigrationModel = Preferences.extend({ | ||
idAttribute: 'id', | ||
namespace: 'Preferences', | ||
storage: { | ||
backend: 'local', | ||
appName: pkg.productName | ||
} | ||
}); | ||
|
||
var UserMigrationModel = User.extend({ | ||
idAttribute: 'id', | ||
namespace: 'Users', | ||
storage: { | ||
backend: 'local', | ||
appName: pkg.productName | ||
} | ||
}); | ||
|
||
// var debug = require('debug')('mongodb-compass:migrations:1.2.0'); | ||
|
||
/** | ||
* Imports the preferences from IndexedDB and converts them to JSON, using | ||
* the `disk` storage backend in the storage-mixin module. | ||
* | ||
* @param {Function} done callback when finished | ||
*/ | ||
function convertPreferencesBackendToJSON(done) { | ||
var oldPrefs = new PreferenceMigrationModel(); | ||
oldPrefs.once('sync', function() { | ||
app.preferences.save(oldPrefs.serialize(), { | ||
success: function() { | ||
oldPrefs.destroy(); | ||
done(null); | ||
}, | ||
error: function(model, err) { | ||
done(err); | ||
} | ||
}); | ||
}); | ||
oldPrefs.fetch(); | ||
} | ||
|
||
/** | ||
* Imports the user data from IndexedDB and converts it to JSON, using | ||
* the `disk` storage backend in the storage-mixin module. | ||
* | ||
* @param {Function} done callback when finished | ||
*/ | ||
function convertUserBackendToJSON(done) { | ||
var oldUser = new UserMigrationModel(); | ||
oldUser.once('sync', function() { | ||
app.user.save(oldUser.serialize(), { | ||
success: function() { | ||
oldUser.destroy(); | ||
done(null); | ||
}, | ||
error: function(model, err) { | ||
done(err); | ||
} | ||
}); | ||
}); | ||
oldUser.fetch(); | ||
} | ||
|
||
module.exports = function(previousVersion, currentVersion, callback) { | ||
// do migration tasks here | ||
async.series([ | ||
convertPreferencesBackendToJSON, | ||
convertUserBackendToJSON | ||
], function(err) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
callback(null, 'successful migration to 1.2.0'); | ||
}); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// var async = require('async'); | ||
var ncp = require('ncp'); | ||
var rimraf = require('rimraf'); | ||
var path = require('path'); | ||
var app = require('electron').app; | ||
|
||
// var debug = require('debug')('mongodb-compass:migrations:1.2.0'); | ||
|
||
/** | ||
* In 1.2.0 we changed the user preferences location directory from | ||
* `mongodb-compass` to `MongoDB Compass`. | ||
* | ||
* This migration moves the directory to the new location. | ||
* | ||
* @param {Function} done callback when finished | ||
*/ | ||
function changeUserDataDirectoryLocation(done) { | ||
var oldDir = 'mongodb-compass'; | ||
// check if old preferences directory exists | ||
var oldUserDir = path.join(app.getPath('appData'), oldDir); | ||
var newUserDir = app.getPath('userData'); | ||
try { | ||
ncp(oldUserDir, newUserDir, function(errCp) { | ||
if (errCp) { | ||
return done(errCp); | ||
} | ||
rimraf(oldUserDir, function(errRm) { | ||
if (errRm) { | ||
return done(errRm); | ||
} | ||
done(); | ||
}); | ||
}); | ||
} catch (e) { | ||
// failed migration, handle gracefully | ||
done(new Error('Failed migration ChangeUserDataDirectoryLocation: ' + e.message)); | ||
} | ||
} | ||
|
||
module.exports = function(previousVersion, currentVersion, callback) { | ||
// do migration tasks here | ||
changeUserDataDirectoryLocation(function(err) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
callback(null, 'successful migration to 1.2.0'); | ||
}); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
var pkg = require('../../../package.json'); | ||
var Model = require('ampersand-model'); | ||
var storageMixin = require('storage-mixin'); | ||
var electronApp = require('electron').app; | ||
|
||
var migrations = { | ||
'1.2.0': require('./1.2.0') | ||
}; | ||
|
||
var migrate = require('app-migrations')(migrations); | ||
|
||
var debug = require('debug')('mongodb-compass:main:migrations'); | ||
|
||
function getPreviousVersion(done) { | ||
var DiskPrefModel = Model.extend(storageMixin, { | ||
extraProperties: 'ignore', | ||
idAttribute: 'id', | ||
namespace: 'AppPreferences', | ||
storage: { | ||
backend: 'disk', | ||
basepath: electronApp.getPath('userData') | ||
}, | ||
props: { | ||
id: ['string', true, 'General'], | ||
lastKnownVersion: ['string', false, ''] | ||
} | ||
}); | ||
|
||
// try to get previous version from disk-backed (JSON) model, else return 0.0.0 | ||
var diskPrefs = new DiskPrefModel(); | ||
diskPrefs.once('sync', function(ret) { | ||
return done(null, ret.lastKnownVersion || '0.0.0'); | ||
}); | ||
diskPrefs.fetch(); | ||
} | ||
|
||
module.exports = function(done) { | ||
getPreviousVersion(function(err, previousVersion) { | ||
if (err) { | ||
return done(err); | ||
} | ||
// strip any prerelease parts off | ||
previousVersion = previousVersion.split('-')[0]; | ||
var currentVersion = pkg.version.split('-')[0]; | ||
debug('main process migrations from %s to %s', previousVersion, currentVersion); | ||
migrate(previousVersion, currentVersion, done); | ||
}); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo. you wanted "ncp", not "npc". I'll fix.