chore: Change v3 migration to use _legacyId instead of legacyId

This commit is contained in:
Blade Barringer
2016-05-17 15:25:54 -05:00
parent 5931aee26b
commit 990d43928b
2 changed files with 8 additions and 8 deletions

View File

@@ -129,16 +129,16 @@ function processChallenges (afterId) {
oldTasks.forEach(function (oldTask) { oldTasks.forEach(function (oldTask) {
oldTask._id = uuid.v4(); oldTask._id = uuid.v4();
oldTask.legacyId = oldTask.id; // store the old task id oldTask._legacyId = oldTask.id; // store the old task id
delete oldTask.id; delete oldTask.id;
oldTask.challenge = oldTask.challenge || {}; oldTask.challenge = oldTask.challenge || {};
oldTask.challenge.id = newChallenge._id; oldTask.challenge.id = newChallenge._id;
if (newTasksIds[oldTask.legacyId + '-' + newChallenge._id]) { if (newTasksIds[oldTask._legacyId + '-' + newChallenge._id]) {
throw new Error('duplicate :('); throw new Error('duplicate :(');
} else { } else {
newTasksIds[oldTask.legacyId + '-' + newChallenge._id] = oldTask._id; newTasksIds[oldTask._legacyId + '-' + newChallenge._id] = oldTask._id;
} }
oldTask.tags = _.map(oldTask.tags || {}, function (tagPresent, tagId) { oldTask.tags = _.map(oldTask.tags || {}, function (tagPresent, tagId) {

View File

@@ -131,20 +131,20 @@ function processUsers (afterId) {
oldTasks.forEach(function (oldTask) { oldTasks.forEach(function (oldTask) {
oldTask._id = uuid.v4(); // create a new unique uuid oldTask._id = uuid.v4(); // create a new unique uuid
oldTask.userId = newUser._id; oldTask.userId = newUser._id;
oldTask.legacyId = oldTask.id; // store the old task id oldTask._legacyId = oldTask.id; // store the old task id
delete oldTask.id; delete oldTask.id;
oldTask.challenge = oldTask.challenge || {}; oldTask.challenge = oldTask.challenge || {};
if (oldTask.challenge.id) { if (oldTask.challenge.id) {
if (oldTask.challenge.broken) { if (oldTask.challenge.broken) {
oldTask.challenge.taskId = oldTask.legacyId; oldTask.challenge.taskId = oldTask._legacyId;
} else { } else {
var newId = newTasksIds[oldTask.legacyId + '-' + oldTask.challenge.id]; var newId = newTasksIds[oldTask._legacyId + '-' + oldTask.challenge.id];
// Challenges' tasks ids changed // Challenges' tasks ids changed
if (!newId && !oldTask.challenge.broken) { if (!newId && !oldTask.challenge.broken) {
challengeTaskNoMatchingId++; challengeTaskNoMatchingId++;
oldTask.challenge.taskId = oldTask.legacyId; oldTask.challenge.taskId = oldTask._legacyId;
oldTask.challenge.broken = 'CHALLENGE_TASK_NOT_FOUND'; oldTask.challenge.broken = 'CHALLENGE_TASK_NOT_FOUND';
} else { } else {
challengeTaskWithMatchingId++; challengeTaskWithMatchingId++;
@@ -173,7 +173,7 @@ function processUsers (afterId) {
newUser.tasksOrder[`${oldTask.type}s`].push(oldTask._id); newUser.tasksOrder[`${oldTask.type}s`].push(oldTask._id);
} }
var allTasksFields = ['_id', 'type', 'text', 'notes', 'tags', 'value', 'priority', 'attribute', 'challenge', 'reminders', 'userId', 'legacyId', 'createdAt']; var allTasksFields = ['_id', 'type', 'text', 'notes', 'tags', 'value', 'priority', 'attribute', 'challenge', 'reminders', 'userId', '_legacyId', 'createdAt'];
// using mongoose models is too slow // using mongoose models is too slow
if (oldTask.type === 'habit') { if (oldTask.type === 'habit') {
oldTask = _.pick(oldTask, allTasksFields.concat(['history', 'up', 'down'])); oldTask = _.pick(oldTask, allTasksFields.concat(['history', 'up', 'down']));