From 2bb4aec2494ae1204c1b5ffad8d2e52103357988 Mon Sep 17 00:00:00 2001 From: Dragory Date: Sun, 18 Feb 2018 21:05:38 +0200 Subject: [PATCH] legacyMigrator: fix duplicate blocked users sometimes breaking migration (race condition) --- src/legacy/legacyMigrator.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/legacy/legacyMigrator.js b/src/legacy/legacyMigrator.js index a81e9fc..249ffd9 100644 --- a/src/legacy/legacyMigrator.js +++ b/src/legacy/legacyMigrator.js @@ -144,22 +144,21 @@ async function migrateLogs() { async function migrateBlockedUsers() { const now = moment.utc().format('YYYY-MM-DD HH:mm:ss'); const blockedUsers = await jsonDb.get('blocked', []); - const promises = blockedUsers.map(async userId => { + + for (const userId of blockedUsers) { const existingBlockedUser = await knex('blocked_users') .where('user_id', userId) .first(); if (existingBlockedUser) return; - return knex('blocked_users').insert({ + await knex('blocked_users').insert({ user_id: userId, user_name: '', blocked_by: 0, blocked_at: now }); - }); - - return Promise.all(promises); + } } async function migrateSnippets() {