Backfill missing group IDs (#708)
This commit is contained in:
parent
ec84245dd4
commit
b4e8c5d602
25
functions/src/scripts/backfill-group-ids.ts
Normal file
25
functions/src/scripts/backfill-group-ids.ts
Normal 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.`)
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user