predikt/oracle/backend/scripts/backfill-post-privacy-fields.ts
caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

48 lines
1.4 KiB
TypeScript

// Fill all groups without privacyStatus to 'public'
import * as admin from 'firebase-admin'
import { initAdmin } from 'shared/init-admin'
import { log, writeAsync } from 'shared/utils'
initAdmin()
const db = admin.firestore()
if (require.main === module) {
async function addVisibilityToPostsWithoutVisibilityField(): Promise<void> {
try {
// Get all posts
const postSnapshot = await db.collection('posts').get()
if (postSnapshot.empty) {
console.log('No posts found.')
return
}
const updatePostPromises: Promise<any>[] = []
// Iterate over posts and add 'visibility': 'public' if the 'visibility' field is missing
postSnapshot.forEach((postDoc) => {
const postData = postDoc.data()
if (!postData.hasOwnProperty('visibility')) {
const postId = postDoc.id
const postRef = db.collection('posts').doc(postId)
console.log(postId)
// Add 'visibility': 'public' to the post
updatePostPromises.push(postRef.update({ visibility: 'public' }))
}
})
// Wait for all post updates to complete
await Promise.all(updatePostPromises)
console.log('Added visibility field to all posts without visibility.')
} catch (error) {
console.error('Error adding visibility field to posts:', error)
}
}
addVisibilityToPostsWithoutVisibilityField()
}