Skip to content

Commit

Permalink
for mozilla#976: tweaks to log and exit lower-casing script
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Sep 19, 2019
1 parent 7153a72 commit b3e95c3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scripts/lowercase-all-records.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,31 @@ async function subscribeLowercaseHashToHIBP(emailAddress) {
(async () => {
const subRecordsWithUpperChars = await knex("subscribers")
.whereRaw("primary_email != lower(primary_email)");
const subsWithUpperCount = subRecordsWithUpperChars.length;
console.log(`found ${subsWithUpperCount} subscribers records with primary_email != lower(primary_email). fixing ...`);
for (const subRecord of subRecordsWithUpperChars) {
const lowerCasedSha1 = await subscribeLowercaseHashToHIBP(subRecord.primary_email);
await knex("subscribers")
.update({
primary_sha1: lowerCasedSha1,
})
.where("id", subRecord.id);
console.log(`fixed subscribers record ID: ${subRecord.id}`);
}

const emailRecordsWithUpperChars = await knex("email_addresses")
.whereRaw("email != lower(email)");
const emailsWithUpperCount = emailRecordsWithUpperChars.length;
console.log(`found ${emailsWithUpperCount} email_addresses records with email != lower(email)`);
for (const emailRecord of emailRecordsWithUpperChars) {
const lowerCasedSha1 = await subscribeLowercaseHashToHIBP(emailRecord.email);
await knex("email_addresses")
.update({
sha1: lowerCasedSha1,
})
.where("id", emailRecord.id);
console.log(`fixed email_addresses record ID: ${emailRecord.id}`);
}
console.log("done.");
process.exit();
})();

0 comments on commit b3e95c3

Please sign in to comment.