diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index 85b1e21cd..7b8a46ab2 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -130,25 +130,5 @@ services: volumes: - ..:/app - backfill-user-emails: - build: - context: .. - dockerfile: infra/Dockerfile.firebase - command: yarn backfill-user-emails - depends_on: - - firebase - volumes: - - ..:/app - - backfill-user-nf: - build: - context: .. - dockerfile: infra/Dockerfile.firebase - command: yarn backfill-user-nf - depends_on: - - firebase - volumes: - - ..:/app - volumes: search: {} diff --git a/package.json b/package.json index ce8a00874..808a44e28 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,6 @@ "build-storybook": "storybook build", "chromatic": "chromatic --project-token=f8618e690599", "copy-handlebars": "echo 'Copying handlebars files to /lib/email/...' && ncp functions/src/email/ functions/lib/email/ && echo '...done!'", - "backfill-user-emails": "ts-node -P tsconfig.script.json scripts/firebase-admin//backfillUserEmails.ts --swc", - "backfill-user-nf": "ts-node -P tsconfig.script.json scripts/firebase-admin/backfillNotificationFrequency.ts --swc", "setRole": "ts-node -P tsconfig.script.json scripts/firebase-admin/setRole.ts" }, "engines": { diff --git a/scripts/firebase-admin/backfillNotificationFrequency.ts b/scripts/firebase-admin/backfillNotificationFrequency.ts deleted file mode 100644 index 2e5c08f58..000000000 --- a/scripts/firebase-admin/backfillNotificationFrequency.ts +++ /dev/null @@ -1,35 +0,0 @@ -// DEPRECATED - This will no longer be useful after we've moved notificationFrequency to profiles -// This should no longer be run and will be removed in a future update - -import { Script } from "./types" -import { listAllUsers } from "./list-all-users" - -export const script: Script = async ({ db, auth }) => { - const allUsers = await listAllUsers(auth) - const usersById = new Map(allUsers.map(u => [u.uid, u])) - - console.log(`Configuring ${allUsers.length} users notification frequency`) - - for (const user of allUsers) { - // Get user document from Firestore - const userDoc = db.collection("profiles").doc(user.uid) - const doc = await userDoc.get() - - // If the user document exists in Firestore - if (doc.exists) { - const userData = doc.data() - - // If userData is not undefined and notificationFrequency is not set already - if (userData && !userData.notificationFrequency) { - // Remove second condition to run on all users, not just those without a notificationFrequency field set - // Update the user document in Firestore - await userDoc.update({ - notificationFrequency: "None" - }) - console.log(`Updated user ${user.uid} notification frequency to None.`) - } - } else { - console.log(`No document for user ${user.uid}`) - } - } -} diff --git a/scripts/firebase-admin/backfillUserEmails.ts b/scripts/firebase-admin/backfillUserEmails.ts deleted file mode 100644 index d3dc7c3e4..000000000 --- a/scripts/firebase-admin/backfillUserEmails.ts +++ /dev/null @@ -1,53 +0,0 @@ -// DEPRECATED - This will no longer be useful going forward -// We plan to rely on the `profiles` collection for casual email use -// and the firebase-auth API where we need verified email addresses -// This should no longer be run and will be removed in a future update - -import { UserRecord } from "firebase-admin/auth" -import { Auth } from "functions/src/types" -import { Script } from "./types" -import { listAllUsers } from "./list-all-users" - -/** Backfill the email field on user documents in Firestore. - * If the email does not exist, set it. - */ -export const script: Script = async ({ db, auth }) => { - const allUsers = await listAllUsers(auth), - usersById = new Map(allUsers.map(u => [u.uid, u])) - - console.log(`Configuring ${allUsers.length} users emails`) - - const writer = db.bulkWriter() - - for (const user of allUsers) { - try { - // Get the user's email - const existingEmail = user.email - - // Check if the email exists, if not, throw an error - if (!existingEmail) { - throw new Error(`User ${user.uid} does not have an email.`) - } - - // Get the user's document - const userDoc = db.collection("users").doc(user.uid) - const docData = (await userDoc.get()).data() || {} - - // If the email is not set in the user's document, set it. - if (!docData.email) { - console.log(`Updating email for user ${user.uid}`) - writer.set( - userDoc, - { ...docData, email: existingEmail }, - { merge: true } - ) - } - } catch (error) { - // Log the error and continue with the next user - console.error(`Error updating email for user ${user.uid}: `, error) - } - } - - await writer.close() - console.log(`Completed updating emails`) -}