Backfill missing group IDs (#708)

This commit is contained in:
Marshall Polaris 2022-08-01 15:40:04 -07:00 committed by GitHub
parent ec84245dd4
commit b4e8c5d602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,25 @@
// We have some groups without IDs. Let's fill them in.
import * as admin from 'firebase-admin'
import { initAdmin } from './script-init'
import { log, writeAsync } from '../utils'
initAdmin()
const firestore = admin.firestore()
if (require.main === module) {
const groupsQuery = firestore.collection('groups')
groupsQuery.get().then(async (groupSnaps) => {
log(`Loaded ${groupSnaps.size} groups.`)
const needsFilling = groupSnaps.docs.filter((ct) => {
return !('id' in ct.data())
})
log(`${needsFilling.length} groups need IDs.`)
const updates = needsFilling.map((group) => {
return { doc: group.ref, fields: { id: group.id } }
})
log(`Updating ${updates.length} groups.`)
await writeAsync(firestore, updates)
log(`Updated all groups.`)
})
}