legacyMigrator: fix duplicate blocked users sometimes breaking migration (race condition)

master
Dragory 2018-02-18 21:05:38 +02:00
parent 9d61becba9
commit 2bb4aec249
1 changed files with 4 additions and 5 deletions

View File

@ -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() {