From a7a7bb7ad3af33f8b2d589fded5f076f25670a0c Mon Sep 17 00:00:00 2001 From: Jacob Bowdoin <7559478+jacob-8@users.noreply.github.com> Date: Thu, 27 Feb 2025 10:37:13 -0600 Subject: [PATCH] Migration post tasks (#542) --- eslint.config.js | 3 +- package.json | 1 - packages/scripts/config-supabase.ts | 2 +- packages/scripts/migrate-to-supabase/notes.md | 5 +- packages/scripts/refactor/get-email.ts | 36 ------ .../refactor/move-firestore-document.ts | 109 ------------------ packages/site/package.json | 1 - packages/site/src/docs/misc/media-urls.md | 4 +- .../routes/admin/dictionaries/+page.svelte | 2 +- .../site/src/routes/admin/users/+page.svelte | 2 +- supabase/ideas/trigger-edge-function.sql | 23 ---- 11 files changed, 7 insertions(+), 181 deletions(-) delete mode 100644 packages/scripts/refactor/get-email.ts delete mode 100644 packages/scripts/refactor/move-firestore-document.ts diff --git a/eslint.config.js b/eslint.config.js index b49378c2a..887c1e702 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -18,7 +18,6 @@ export default antfu( { ignores: [ '**/.svelte-kit**', - '**/functions/lib/**', '.eslintcache', 'packages/scripts/import/old**', '**/route/kitbook/**', @@ -83,7 +82,7 @@ export default antfu( }, { name: 'ld/script-exceptions', - files: ['packages/{scripts,functions}/**'], + files: ['packages/scripts/**'], rules: { 'no-console': 'off', 'ts/no-unused-vars': 'off', diff --git a/package.json b/package.json index 333ca9770..b6f30aeed 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "scripts": { "dev": "pnpm --filter=site dev", "prod": "pnpm --filter=site prod", - "mixed": "pnpm --filter=site mixed", "dev:open": "pnpm --filter=site dev --open", "build": "pnpm --filter=site build", "preview": "pnpm --filter=site preview", diff --git a/packages/scripts/config-supabase.ts b/packages/scripts/config-supabase.ts index dd20ad554..eef21ea76 100644 --- a/packages/scripts/config-supabase.ts +++ b/packages/scripts/config-supabase.ts @@ -7,7 +7,7 @@ import './record-logs' import { S3Client } from '@aws-sdk/client-s3' program - .option('-e, --environment [dev/prod]', 'Firebase/Supabase Project', 'dev') + .option('-e, --environment [dev/prod]', 'Supabase Project', 'dev') .allowUnknownOption() // because config is shared by multiple scripts .parse(process.argv) diff --git a/packages/scripts/migrate-to-supabase/notes.md b/packages/scripts/migrate-to-supabase/notes.md index 973901347..c5676716f 100644 --- a/packages/scripts/migrate-to-supabase/notes.md +++ b/packages/scripts/migrate-to-supabase/notes.md @@ -1,8 +1,8 @@ ## Final Migration cleanup +- use line-clamp instead of truncateString in SelectedDict.svelte and also look at inline-children-elements purpose - show entry history from pop-up entry modal - test admin rls, alternative is auth.jwt() read https://supabase.com/docs/guides/database/postgres/row-level-security#authjwt to see if better - Diego: AuthModal.svelte translations -- review updated_by triggers across all tables - review created_by forcers to see which tables need set_created_by - audio_speakers - dictionary_info @@ -11,12 +11,9 @@ - invites - sense_photos - remove Entry History i18n -- remove firebase vercel credentials - remove import_meta from content update endpoint -- remove firebase in SQL - remove unneeded urls from https://console.cloud.google.com/auth/clients/215143435444-fugm4gpav71r3l89n6i0iath4m436qnv.apps.googleusercontent.com?inv=1&invt=AboyXQ&project=talking-dictionaries-alpha - move featured images to photos table and make a connection to the dictionary -- use line-clamp instead of truncateString in SelectedDict.svelte and also look at inline-children-elements purpose - delete dev Firebase project and create new gcs dev bucket - adjust user migration to set these fields to empty strings and not null to avoid db errors: `confirmation_token`, `recovery_token`, `email_change_token_new`, `email_change` diff --git a/packages/scripts/refactor/get-email.ts b/packages/scripts/refactor/get-email.ts deleted file mode 100644 index decb22522..000000000 --- a/packages/scripts/refactor/get-email.ts +++ /dev/null @@ -1,36 +0,0 @@ -import type { IUser } from '@living-dictionaries/types' -import { db } from '../config-firebase' - -const dictionary_ids = ['shauki', 'nongtrai'] - -// get_dictionary_emails(dictionary_ids) - -async function get_dictionary_emails(dictionary_ids: string[]) { - const emails = new Set() - for (const dictionary_id of dictionary_ids) { - const snapshot = await db.collection(`dictionaries/${dictionary_id}/managers`).get() - for (const snap of snapshot.docs) { - const user = (await db.collection('users').doc(snap.id).get()).data() as IUser - console.log({ user }) - emails.add(user.email) - } - - const snapshot2 = await db.collection(`dictionaries/${dictionary_id}/contributors`).get() - for (const snap of snapshot2.docs) { - const user = (await db.collection('users').doc(snap.id).get()).data() as IUser - console.log({ user }) - emails.add(user.email) - } - } - console.log(Array.from(emails)) -} - -async function get_all_emails() { - const userSnapshots = await db.collection('users').get() - const users = userSnapshots.docs.map(doc => doc.data()) as IUser[] - for (const user of users) { - console.log(user.email) - } -} - -get_all_emails() diff --git a/packages/scripts/refactor/move-firestore-document.ts b/packages/scripts/refactor/move-firestore-document.ts deleted file mode 100644 index 54bb62383..000000000 --- a/packages/scripts/refactor/move-firestore-document.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { db } from '../config-firebase' - -// deleteDocRecursively(`dictionaries/sipu`); -// copyDoc(`dictionaries/sipu`, `dictionaries/conestoga_language`, {}, true); -// copyDoc(`dictionaries/olùkùmi`, `dictionaries/olukumi`, {}, true); -// moveDoc(`dictionaries/olùkùmi`, `dictionaries/olukumi`); - -// from https://leechy.dev/firestore-move -export async function moveDoc( - oldDocPath: string, - newDocPath: string, - addData?: any, -): Promise { - const copied = await copyDoc(oldDocPath, newDocPath, addData, true) - - if (copied) { - await deleteDocRecursively(`${oldDocPath}`) - return true - } - throw new Error('Data was not copied properly to the target collection, please try again.') -} - -export async function copyDoc( - oldDocPath: string, - newDocPath: string, - addData: any = {}, - recursive = false, -): Promise { - const docRef = db.doc(oldDocPath) - - const docData = await docRef - .get() - .then(doc => doc.exists && doc.data()) - .catch((error) => { - throw new Error(`Error reading document ${oldDocPath}: ${JSON.stringify(error)}`) - }) - - if (docData) { - await db - .doc(newDocPath) - .set({ ...docData, ...addData }) - .catch((error) => { - throw new Error(`Error creating document ${newDocPath}: ${JSON.stringify(error)}`) - }) - - // if copying of the subcollections is needed - if (recursive) { - // subcollections - const subcollections = await docRef.listCollections() - for await (const subcollectionRef of subcollections) { - const subcollectionPath = `${oldDocPath}/${subcollectionRef.id}` - - await subcollectionRef - .get() - .then(async (snapshot) => { - const { docs } = snapshot - for await (const doc of docs) { - await copyDoc( - `${subcollectionPath}/${doc.id}`, - `${newDocPath}/${subcollectionRef.id}/${doc.id}`, - true, - ) - } - }) - .catch((error) => { - throw new Error( - `Error reading subcollection ${subcollectionPath}: ${JSON.stringify(error)}`, - ) - }) - } - } - return true - } - return false -} - -export async function deleteDocRecursively(docPath: string): Promise { - const docRef = db.doc(docPath) - - const subcollections = await docRef.listCollections() - for await (const subcollectionRef of subcollections) { - await subcollectionRef - .get() - .then(async (snapshot) => { - const { docs } = snapshot - for await (const doc of docs) - await deleteDocRecursively(`${docPath}/${subcollectionRef.id}/${doc.id}`) - - return true - }) - .catch((error) => { - console.error( - 'Error reading subcollection', - `${docPath}/${subcollectionRef.id}`, - JSON.stringify(error), - ) - return false - }) - } - - // when all subcollections are deleted, delete the document itself - return docRef - .delete() - .then(() => true) - .catch((error) => { - console.error('Error deleting document', docPath, JSON.stringify(error)) - return false - }) -} diff --git a/packages/site/package.json b/packages/site/package.json index b2b96c21f..1adf118d6 100644 --- a/packages/site/package.json +++ b/packages/site/package.json @@ -7,7 +7,6 @@ "scripts": { "dev": "vite dev", "prod": "vite dev --mode production", - "mixed": "vite dev --mode mixed", "build": "vite build", "preview": "vite preview", "sync": "svelte-kit sync", diff --git a/packages/site/src/docs/misc/media-urls.md b/packages/site/src/docs/misc/media-urls.md index 16718759e..a88345c32 100644 --- a/packages/site/src/docs/misc/media-urls.md +++ b/packages/site/src/docs/misc/media-urls.md @@ -1,6 +1,6 @@ # Media Urls for exporting -Audio urls are made by taking the path string, converting `/` to `%2F` and then plugging the `convertedPath` into +Audio urls are made by taking the path string, converting `/` to `%2F` and then plugging the `convertedPath` into ``` https://firebasestorage.googleapis.com/v0/b/${firebaseConfig.storageBucket}/o/${convertedPath}?alt=media ``` @@ -9,5 +9,5 @@ resulting in something like https://firebasestorage.googleapis.com/v0/b/talking- Photo urls are formed by the path and plugging it into the path below to come up with something like https://firebasestorage.googleapis.com/v0/b/talking-dictionaries-alpha.appspot.com/o/images%2Fmandarin-practice%2FmogAtD3lTCtkuwj7tLDD_1630105898118.jpg?alt=media ``` -https://firebasestorage.googleapis.com/v0/b/${firebaseConfig.storageBucket}/o/${convertedPath}?alt=media +https://firebasestorage.googleapis.com/v0/b/${storageBucket}/o/${convertedPath}?alt=media ``` diff --git a/packages/site/src/routes/admin/dictionaries/+page.svelte b/packages/site/src/routes/admin/dictionaries/+page.svelte index 10fffb788..77a9fb755 100644 --- a/packages/site/src/routes/admin/dictionaries/+page.svelte +++ b/packages/site/src/routes/admin/dictionaries/+page.svelte @@ -83,7 +83,7 @@
- + {#each sortedDictionaries as dictionary, index (dictionary.id)} diff --git a/packages/site/src/routes/admin/users/+page.svelte b/packages/site/src/routes/admin/users/+page.svelte index 0f8984801..e26e5ce94 100644 --- a/packages/site/src/routes/admin/users/+page.svelte +++ b/packages/site/src/routes/admin/users/+page.svelte @@ -44,7 +44,7 @@
- + {#each sortedUsers as user (user.id)}