From 50ebdd1ece578f5b2a8e92c4b2e8736e3268f194 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Mon, 25 Jun 2018 23:14:35 +0200 Subject: [PATCH] tasks hsitory migration: prevent it from running twice --- .../tasks/habits-one-history-entry-per-day-users.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/migrations/tasks/habits-one-history-entry-per-day-users.js b/migrations/tasks/habits-one-history-entry-per-day-users.js index 8eb52e8f90..509aa71eb7 100644 --- a/migrations/tasks/habits-one-history-entry-per-day-users.js +++ b/migrations/tasks/habits-one-history-entry-per-day-users.js @@ -1,4 +1,4 @@ -// const migrationName = 'habits-one-history-entry-per-day'; +const migrationName = 'habits-one-history-entry-per-day'; const authorName = 'paglias'; // in case script author needs to know when their ... const authorUuid = 'ed4c688c-6652-4a92-9d03-a5a79844174a'; // ... own data is done @@ -14,7 +14,9 @@ const dbTasks = monk(connectionString).get('tasks', { castIds: false }); const dbUsers = monk(connectionString).get('users', { castIds: false }); function processUsers (lastId) { - let query = {}; + let query = { + migration: {$ne: migrationName}, + }; if (lastId) { query._id = { @@ -127,6 +129,11 @@ function updateUser (user) { .then(habits => { return Promise.all(habits.map(habit => updateHabit(habit, timezoneOffset, dayStart))); }) + .then(() => { + return dbUsers.update({_id: user._id}, { + $set: {migration: migrationName}, + }); + }) .catch((err) => { console.log(err); return exiting(1, `ERROR! ${ err}`);