-
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.
Merge pull request #10 from EqualifyEverything/staging
Removed userId association from messages/tags, using dev scan on staging
- Loading branch information
Showing
7 changed files
with
90 additions
and
31 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
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,5 @@ | ||
import { createHash } from 'crypto'; | ||
|
||
export const hashStringToUuid = (input) => { | ||
return createHash('md5').update(input).digest('hex'); | ||
} |
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