Skip to content

Commit

Permalink
Ability to ignore ids when importing seed
Browse files Browse the repository at this point in the history
  • Loading branch information
carletex committed Feb 26, 2024
1 parent f003c09 commit 90538e8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/local_db/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ async function importCollectionData(
database: Firestore,
collectionName: string,
data: Record<string, object>,
ignoreId: boolean = false,
) {
for (const [id, docData] of Object.entries(data)) {
if (ignoreId) {
await database.collection(collectionName).add(docData);
continue;
}
await database.collection(collectionName).doc(id).set(docData);
}
}
Expand Down Expand Up @@ -64,7 +69,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! 🌱");
Expand Down

0 comments on commit 90538e8

Please sign in to comment.