backfill subsidyPool
This commit is contained in:
parent
d9f57b7daa
commit
aa717a767d
24
functions/src/scripts/backfill-subsidy-pool.ts
Normal file
24
functions/src/scripts/backfill-subsidy-pool.ts
Normal file
|
@ -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.`)
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user