Username migration tweaks
This commit is contained in:
parent
56f746787f
commit
ed6eee47f3
1 changed files with 13 additions and 3 deletions
|
@ -9,6 +9,14 @@ export class MigrateUsernamesToNewHistoryTable1556909512501 implements Migration
|
||||||
|
|
||||||
const migratedUsernames = new Set();
|
const migratedUsernames = new Set();
|
||||||
|
|
||||||
|
await new Promise(async resolve => {
|
||||||
|
const stream = await queryRunner.stream("SELECT CONCAT(user_id, '-', username) AS `key` FROM username_history");
|
||||||
|
stream.on("result", row => {
|
||||||
|
migratedUsernames.add(row.key);
|
||||||
|
});
|
||||||
|
stream.on("end", resolve);
|
||||||
|
});
|
||||||
|
|
||||||
const migrateNextBatch = (): Promise<{ finished: boolean; migrated?: number }> => {
|
const migrateNextBatch = (): Promise<{ finished: boolean; migrated?: number }> => {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
const toInsert = [];
|
const toInsert = [];
|
||||||
|
@ -19,10 +27,12 @@ export class MigrateUsernamesToNewHistoryTable1556909512501 implements Migration
|
||||||
);
|
);
|
||||||
stream.on("result", row => {
|
stream.on("result", row => {
|
||||||
const key = `${row.user_id}-${row.value}`;
|
const key = `${row.user_id}-${row.value}`;
|
||||||
if (migratedUsernames.has(key)) return;
|
|
||||||
migratedUsernames.add(key);
|
|
||||||
|
|
||||||
|
if (!migratedUsernames.has(key)) {
|
||||||
|
migratedUsernames.add(key);
|
||||||
toInsert.push([row.user_id, row.value, row.timestamp]);
|
toInsert.push([row.user_id, row.value, row.timestamp]);
|
||||||
|
}
|
||||||
|
|
||||||
toDelete.push(row.id);
|
toDelete.push(row.id);
|
||||||
});
|
});
|
||||||
stream.on("end", async () => {
|
stream.on("end", async () => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue