legacyMigrator: fix duplicate blocked users sometimes breaking migration (race condition)
parent
9d61becba9
commit
2bb4aec249
|
@ -144,22 +144,21 @@ async function migrateLogs() {
|
||||||
async function migrateBlockedUsers() {
|
async function migrateBlockedUsers() {
|
||||||
const now = moment.utc().format('YYYY-MM-DD HH:mm:ss');
|
const now = moment.utc().format('YYYY-MM-DD HH:mm:ss');
|
||||||
const blockedUsers = await jsonDb.get('blocked', []);
|
const blockedUsers = await jsonDb.get('blocked', []);
|
||||||
const promises = blockedUsers.map(async userId => {
|
|
||||||
|
for (const userId of blockedUsers) {
|
||||||
const existingBlockedUser = await knex('blocked_users')
|
const existingBlockedUser = await knex('blocked_users')
|
||||||
.where('user_id', userId)
|
.where('user_id', userId)
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
if (existingBlockedUser) return;
|
if (existingBlockedUser) return;
|
||||||
|
|
||||||
return knex('blocked_users').insert({
|
await knex('blocked_users').insert({
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
user_name: '',
|
user_name: '',
|
||||||
blocked_by: 0,
|
blocked_by: 0,
|
||||||
blocked_at: now
|
blocked_at: now
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
return Promise.all(promises);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function migrateSnippets() {
|
async function migrateSnippets() {
|
||||||
|
|
Loading…
Reference in New Issue