From fc4066e78e4b20d39d0fb54f73395ca46bcab3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez?= Date: Mon, 26 Feb 2024 11:34:08 +0100 Subject: [PATCH] Ability to ignore ids when importing seed --- packages/local_db/utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/local_db/utils.ts b/packages/local_db/utils.ts index 53d6d86..e033257 100644 --- a/packages/local_db/utils.ts +++ b/packages/local_db/utils.ts @@ -16,8 +16,12 @@ async function importCollectionData( database: Firestore, collectionName: string, data: Record, + ignoreId: boolean = false, ) { for (const [id, docData] of Object.entries(data)) { + if (ignoreId) { + await database.collection(collectionName).add(docData); + } await database.collection(collectionName).doc(id).set(docData); } } @@ -64,7 +68,7 @@ export const importSeed = async (database: Firestore) => { importCollectionData(database, "config", seedToImport.config), importCollectionData(database, "cohorts", seedToImport.cohorts), importCollectionData(database, "notifications", seedToImport.notifications), - importCollectionData(database, "grants", seedToImport.grants), + importCollectionData(database, "grants", seedToImport.grants, true), ]); console.log("Seed completed successfully! 🌱");