Add script to backfill contract collectedFees

This commit is contained in:
Marshall Polaris 2022-05-26 22:07:56 -07:00
parent 1e0845f4b9
commit 3e25faf74c

View File

@ -0,0 +1,25 @@
// We have many old contracts without a collectedFees data structure. Let's fill them in.
import * as admin from 'firebase-admin'
import { initAdmin } from './script-init'
import { noFees } from '../../../common/fees'
initAdmin()
const firestore = admin.firestore()
if (require.main === module) {
const contractsRef = firestore.collection('contracts')
contractsRef.get().then((contractsSnaps) => {
let n = 0
console.log(`Loaded ${contractsSnaps.size} contracts.`)
contractsSnaps.forEach((ct) => {
const data = 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.`)
})
}