diff --git a/migrations/migration-runner.js b/migrations/migration-runner.js index 33b6d35279..a29f068bd5 100644 --- a/migrations/migration-runner.js +++ b/migrations/migration-runner.js @@ -17,8 +17,12 @@ function setUpServer () { setUpServer(); // Replace this with your migration -var processUsers = require('./groups/update-groups-with-group-plans'); +const processUsers = require('./users/account-transfer'); processUsers() - .catch(function (err) { - console.log(err) + .then(() => { + process.exit(); }) + .catch(function (err) { + console.log(err); + process.exit(); + }); diff --git a/migrations/users/account-transfer.js b/migrations/users/account-transfer.js new file mode 100644 index 0000000000..7d57dac08b --- /dev/null +++ b/migrations/users/account-transfer.js @@ -0,0 +1,38 @@ +var migrationName = 'AccountTransfer'; +var authorName = 'TheHollidayInn'; // in case script author needs to know when their ... +var authorUuid = ''; //... own data is done + +/* + * This migraition will copy user data from prod to test + */ + +const monk = require('monk'); +const connectionString = ''; +const Users = monk(connectionString).get('users', { castIds: false }); + +import uniq from 'lodash/uniq'; +import Bluebird from 'bluebird'; + + +module.exports = async function accountTransfer () { + const fromAccountId = ''; + const toAccountId = ''; + + const fromAccount = await Users.findOne({_id: fromAccountId}); + const toAccount = await Users.findOne({_id: toAccountId}); + + const newMounts = Object.assign({}, fromAccount.items.mounts, toAccount.items.mounts); + const newPets = Object.assign({}, fromAccount.items.pets, toAccount.items.pets); + const newBackgrounds = Object.assign({}, fromAccount.purchased.background, toAccount.purchased.background); + + await Users.update({_id: toAccountId}, { + $set: { + 'items.pets': newPets, + 'items.mounts': newMounts, + 'purchased.background': newBackgrounds, + }, + }) + .then((result) => { + console.log(result); + }); +};