Files
botfights/server/src/db/schema.ts
T

52 lines
2.1 KiB
TypeScript
Raw Normal View History

import { sqliteTable, text, integer, real } from 'drizzle-orm/sqlite-core'
export const bots = sqliteTable('bots', {
id: text('id').primaryKey(),
name: text('name').notNull().unique(),
webhookUrl: text('webhook_url').notNull(),
avatarSeed: text('avatar_seed').notNull(),
secretHash: text('secret_hash').notNull(),
publicKey: text('public_key'),
eloRating: real('elo_rating').notNull().default(1200),
wins: integer('wins').notNull().default(0),
losses: integer('losses').notNull().default(0),
winStreak: integer('win_streak').notNull().default(0),
bestStreak: integer('best_streak').notNull().default(0),
tier: integer('tier').notNull().default(0),
isActive: integer('is_active', { mode: 'boolean' }).notNull().default(true),
createdAt: text('created_at').notNull(),
})
export const fights = sqliteTable('fights', {
id: text('id').primaryKey(),
botAId: text('bot_a_id').notNull().references(() => bots.id),
botBId: text('bot_b_id').notNull().references(() => bots.id),
arena: text('arena').notNull(),
status: text('status', { enum: ['scheduled', 'live', 'finished', 'cancelled'] }).notNull().default('scheduled'),
winnerId: text('winner_id').references(() => bots.id),
botAHp: integer('bot_a_hp').notNull().default(100),
botBHp: integer('bot_b_hp').notNull().default(100),
totalRounds: integer('total_rounds').notNull().default(0),
scheduledAt: text('scheduled_at'),
startedAt: text('started_at'),
endedAt: text('ended_at'),
createdAt: text('created_at').notNull(),
})
export const rounds = sqliteTable('rounds', {
id: text('id').primaryKey(),
fightId: text('fight_id').notNull().references(() => fights.id),
roundNumber: integer('round_number').notNull(),
challengeType: text('challenge_type').notNull(),
challengeData: text('challenge_data').notNull(),
botAResponse: text('bot_a_response'),
botATimeMs: integer('bot_a_time_ms'),
botAScore: real('bot_a_score'),
botBResponse: text('bot_b_response'),
botBTimeMs: integer('bot_b_time_ms'),
botBScore: real('bot_b_score'),
winnerId: text('winner_id').references(() => bots.id),
narration: text('narration'),
createdAt: text('created_at').notNull(),
})