predikt/oracle/backend/scripts/supabase/backfill-user-ids.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

47 lines
1.3 KiB
TypeScript

import * as admin from 'firebase-admin'
import { initAdmin } from 'shared/init-admin'
initAdmin()
import { createSupabaseClient } from 'shared/supabase/init'
const firestore = admin.firestore()
const main = async () => {
const db = createSupabaseClient()
// get all api keys from discord_users table
const { data: discordUsers, error } = await db
.from('discord_users')
.select('api_key')
if (error) {
console.log('error getting discord users', error)
return
}
const discordUserApiKeys = discordUsers.map((user) => user.api_key)
// get user ids for all api keys and fill them in the user_id column in discord_users table
await Promise.all(
discordUserApiKeys.map(async (apiKey) => {
const userId = (
await firestore
.collection('private-users')
.where('apiKey', '==', apiKey)
.get()
).docs[0].id
if (!userId) {
console.log('no user id found for api key', apiKey)
return
}
console.log('found user id', userId, 'for api key', apiKey)
const { error } = await db
.from('discord_users')
.update({ user_id: userId })
.match({ api_key: apiKey })
if (error) {
console.log('error updating discord user', error)
return
}
})
)
}
if (require.main === module) main().then(() => process.exit())