predikt/oracle/backend/scripts/delete-group.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

46 lines
1.3 KiB
TypeScript

import { updateGroupLinksOnContracts } from 'merge-groups'
import { runScript } from 'run-script'
import { SupabaseDirectClient } from 'shared/supabase/init'
async function deleteGroup(pg: SupabaseDirectClient, slug: string) {
const groupId = await pg.one(
'select id from groups where slug = $1',
[slug],
(row) => row.id
)
console.log('removing group from posts')
await pg.none('update old_posts set group_id = null where group_id = $1', [
groupId,
])
const contracts = await pg.map(
'select contract_id from group_contracts where group_id = $1',
[groupId],
(row) => row.contract_id
)
if (contracts.length > 0) {
console.log('removing group from contracts')
await pg.none('delete from group_contracts where group_id = $1', [groupId])
console.log('correcting contract group slugs')
await updateGroupLinksOnContracts(pg, contracts)
}
console.log('removing group members')
await pg.none('delete from group_members where group_id = $1', [groupId])
console.log('deleting group')
await pg.none('delete from groups where id = $1', [groupId])
}
if (require.main === module) {
if (process.argv.length < 3) {
console.error('usage: delete-group.ts <group slug>')
process.exit(1)
}
runScript(async ({ pg }) => {
await deleteGroup(pg, process.argv[2])
})
}