-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script to migrate from user ID based messages/tags to global rows
- Loading branch information
1 parent
2790247
commit 1632ab2
Showing
5 changed files
with
55 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { processScans } from '#src/internal/index'; | ||
import { migrateMessagesAndTags, processScans } from '#src/internal/index'; | ||
|
||
export const internal = async (event) => { | ||
if (event.path.endsWith('/processScans')) { | ||
return processScans(event); | ||
} | ||
else if (event.path.endsWith('/migrateMessagesAndTags')) { | ||
return migrateMessagesAndTags(event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './processScans' | ||
export * from './processScans' | ||
export * from './migrateMessagesAndTags' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { db, hashStringToUuid } from '#src/utils'; | ||
|
||
export const migrateMessagesAndTags = async () => { | ||
await db.connect(); | ||
// Make sure we have distinct message/tag rows | ||
const distinctMessages = (await db.query(`SELECT DISTINCT "message", "type" FROM "messages"`)).rows; | ||
for (const row of distinctMessages) { | ||
const messageId = hashStringToUuid(row.message); | ||
try { | ||
await db.query({ | ||
text: `INSERT INTO "messages" ("id","message","type") VALUES ($1, $2, $3)`, | ||
values: [messageId, row.message, row.type] | ||
}); | ||
} | ||
catch (err) { } | ||
} | ||
const distinctTags = (await db.query(`SELECT DISTINCT "tag" FROM "tags"`)).rows; | ||
for (const row of distinctTags) { | ||
const tagId = hashStringToUuid(row.tag); | ||
try { | ||
await db.query({ | ||
text: `INSERT INTO "tags" ("id","tag") VALUES ($1, $2)`, | ||
values: [tagId, row.tag], | ||
}); | ||
} | ||
catch (err) { } | ||
} | ||
|
||
// Now, find all old messages and adjust. | ||
|
||
await db.clean(); | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters