Fix up backfill script (and I ran it)

This commit is contained in:
Marshall Polaris 2022-05-27 13:11:32 -07:00
parent 3e25faf74c
commit e5ce17c2ad

View File

@ -9,17 +9,15 @@ const firestore = admin.firestore()
if (require.main === module) { if (require.main === module) {
const contractsRef = firestore.collection('contracts') const contractsRef = firestore.collection('contracts')
contractsRef.get().then((contractsSnaps) => { contractsRef.get().then(async (contractsSnaps) => {
let n = 0
console.log(`Loaded ${contractsSnaps.size} contracts.`) console.log(`Loaded ${contractsSnaps.size} contracts.`)
contractsSnaps.forEach((ct) => { const needsFilling = contractsSnaps.docs.filter((ct) => {
const data = ct.data() return !('collectedFees' in ct.data())
if (!('collectedFees' in data)) {
n += 1
console.log(`Filling in missing fees on contract ${data.id}...`)
ct.ref.update({ collectedFees: noFees })
}
}) })
console.log(`Updated ${n} contracts.`) console.log(`Found ${needsFilling.length} contracts to update.`)
await Promise.all(
needsFilling.map((ct) => ct.ref.update({ collectedFees: noFees }))
)
console.log(`Updated all contracts.`)
}) })
} }