Fix AddNameToUsersMigration not calling callbacks

This commit is contained in:
Alice Gaudon 2021-01-26 17:56:57 +01:00
parent a1d5597e96
commit dbf6128747
1 changed files with 3 additions and 1 deletions

View File

@ -15,10 +15,12 @@ export default class AddNameToUsersMigration extends Migration {
// Give every user a random name
const users = await User.select().get(this.getCurrentConnection());
const callbacks: (() => Promise<void>)[] = [];
await Promise.all(users.map(user => {
user.name = nanoid();
return user.save(this.getCurrentConnection());
return user.save(this.getCurrentConnection(), c => callbacks.push(c));
}));
await Promise.all(callbacks);
await this.query(`ALTER TABLE users
ADD CONSTRAINT UNIQUE (name)`);