55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { db, schema } from '../db/index.js'
|
|||
|
|
import { sql } from 'drizzle-orm'
|
||
|
|
import { createTournament, joinTournament, startTournament } from './tournaments.js'
|
||
|
|
import { logger } from '../lib/logger.js'
|
||
|
|
|
||
|
|
/** Seed a dev tournament with mock bots for testing betting/tournament UI */
|
||
|
|
export async function seedDevTournament(): Promise<void> {
|
||
|
|
// Skip if a tournament already exists
|
||
|
|
const existing = db.select({ count: sql<number>`count(*)` })
|
||
|
|
.from(schema.tournaments)
|
||
|
|
.get()
|
||
|
|
if (existing && existing.count > 0) {
|
||
|
|
logger.info('dev-seed', 'tournaments already exist — skipping seed')
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// Grab 8 mock bots for the tournament
|
||
|
|
const bots = db.select({ id: schema.bots.id, name: schema.bots.name })
|
||
|
|
.from(schema.bots)
|
||
|
|
.limit(8)
|
||
|
|
.all()
|
||
|
|
|
||
|
|
if (bots.length < 4) {
|
||
|
|
logger.warn('dev-seed', `only ${bots.length} bots — need at least 4 for tournament seed`)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// Create tournament
|
||
|
|
const tournamentId = createTournament(
|
||
|
|
'SATOSHI SHOWDOWN #1',
|
||
|
|
'single_elim',
|
||
|
|
8,
|
||
|
|
100,
|
||
|
|
)
|
||
|
|
|
||
|
|
// Join bots
|
||
|
|
for (const bot of bots.slice(0, 8)) {
|
||
|
|
try {
|
||
|
|
joinTournament(tournamentId, bot.id)
|
||
|
|
} catch (err) {
|
||
|
|
logger.warn('dev-seed', `failed to join bot ${bot.name}: ${(err as Error).message}`)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Start the tournament (seeds by elo, generates bracket)
|
||
|
|
try {
|
||
|
|
startTournament(tournamentId)
|
||
|
|
logger.info('dev-seed', `seeded tournament "${tournamentId}" with ${Math.min(bots.length, 8)} bots`)
|
||
|
|
} catch (err) {
|
||
|
|
logger.warn('dev-seed', `failed to start tournament: ${(err as Error).message}`)
|
||
|
|
}
|
||
|
|
|
||
|
|
logger.info('dev-seed', 'dev seeding complete — tournament ready for testing')
|
||
|
|
}
|