diff --git a/functions/src/scripts/backfill-subsidy-pool.ts b/functions/src/scripts/backfill-subsidy-pool.ts new file mode 100644 index 00000000..092e026d --- /dev/null +++ b/functions/src/scripts/backfill-subsidy-pool.ts @@ -0,0 +1,24 @@ +import * as admin from 'firebase-admin' +import { initAdmin } from './script-init' + +initAdmin() +const firestore = admin.firestore() + +if (require.main === module) { + const contractsRef = firestore.collection('contracts') + contractsRef.get().then(async (contractsSnaps) => { + + console.log(`Loaded ${contractsSnaps.size} contracts.`) + + const needsFilling = contractsSnaps.docs.filter((ct) => { + return !('subsidyPool' in ct.data()) + }) + + console.log(`Found ${needsFilling.length} contracts to update.`) + await Promise.all( + needsFilling.map((ct) => ct.ref.update({ subsidyPool: 0 })) + ) + + console.log(`Updated all contracts.`) + }) +}