make all emails lowercase closes #89

This commit is contained in:
Milo Schwartz 2025-01-21 18:36:50 -05:00
parent f378d77f8f
commit ece694ff20
10 changed files with 73 additions and 15 deletions

View file

@ -11,7 +11,7 @@ import m2 from "./scripts/1.0.0-beta2";
import m3 from "./scripts/1.0.0-beta3";
import m4 from "./scripts/1.0.0-beta5";
import m5 from "./scripts/1.0.0-beta6";
import { existsSync, mkdirSync } from "fs";
import m6 from "./scripts/1.0.0-beta9";
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
// EXCEPT FOR THE DATABASE AND THE SCHEMA
@ -22,7 +22,8 @@ const migrations = [
{ version: "1.0.0-beta.2", run: m2 },
{ version: "1.0.0-beta.3", run: m3 },
{ version: "1.0.0-beta.5", run: m4 },
{ version: "1.0.0-beta.6", run: m5 }
{ version: "1.0.0-beta.6", run: m5 },
{ version: "1.0.0-beta.9", run: m6 }
// Add new migrations here as they are created
] as const;

View file

@ -0,0 +1,40 @@
import db from "@server/db";
import {
emailVerificationCodes,
passwordResetTokens,
resourceOtp,
resourceWhitelist,
userInvites,
users
} from "@server/db/schema";
import { sql } from "drizzle-orm";
export default async function migration() {
console.log("Running setup script 1.0.0-beta.9...");
try {
await db.transaction(async (trx) => {
await db.transaction(async (trx) => {
trx.run(sql`UPDATE ${users} SET email = LOWER(email);`);
trx.run(
sql`UPDATE ${emailVerificationCodes} SET email = LOWER(email);`
);
trx.run(
sql`UPDATE ${passwordResetTokens} SET email = LOWER(email);`
);
trx.run(sql`UPDATE ${userInvites} SET email = LOWER(email);`);
trx.run(
sql`UPDATE ${resourceWhitelist} SET email = LOWER(email);`
);
trx.run(sql`UPDATE ${resourceOtp} SET email = LOWER(email);`);
});
});
} catch (error) {
console.log(
"We were unable to make all emails lower case in the database."
);
console.error(error);
}
console.log("Done.");
}