Third time's the charm
This commit is contained in:
parent
e0ff67c0b4
commit
1b1ae98714
1 changed files with 16 additions and 9 deletions
|
@ -38,15 +38,22 @@ export class MigrateUsernamesToNewHistoryTable1556909512501 implements Migration
|
||||||
stream.on("end", async () => {
|
stream.on("end", async () => {
|
||||||
if (toInsert.length || toDelete.length) {
|
if (toInsert.length || toDelete.length) {
|
||||||
await queryRunner.query("START TRANSACTION");
|
await queryRunner.query("START TRANSACTION");
|
||||||
await queryRunner.query(
|
|
||||||
"INSERT INTO username_history (user_id, username, timestamp) VALUES " +
|
if (toInsert.length) {
|
||||||
Array.from({ length: toInsert.length }, () => "(?, ?, ?)").join(","),
|
await queryRunner.query(
|
||||||
toInsert.flat(),
|
"INSERT INTO username_history (user_id, username, timestamp) VALUES " +
|
||||||
);
|
Array.from({ length: toInsert.length }, () => "(?, ?, ?)").join(","),
|
||||||
await queryRunner.query(
|
toInsert.flat(),
|
||||||
"DELETE FROM name_history WHERE id IN (" + Array.from("?".repeat(toDelete.length)).join(", ") + ")",
|
);
|
||||||
toDelete,
|
}
|
||||||
);
|
|
||||||
|
if (toDelete.length) {
|
||||||
|
await queryRunner.query(
|
||||||
|
"DELETE FROM name_history WHERE id IN (" + Array.from("?".repeat(toDelete.length)).join(", ") + ")",
|
||||||
|
toDelete,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await queryRunner.query("COMMIT");
|
await queryRunner.query("COMMIT");
|
||||||
|
|
||||||
resolve({ finished: false, migrated: toInsert.length });
|
resolve({ finished: false, migrated: toInsert.length });
|
||||||
|
|
Loading…
Add table
Reference in a new issue