All files / web/src/db/schema room-game-configs.ts

100% Statements 49/49
100% Branches 2/2
100% Functions 1/1
100% Lines 49/49

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 502x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 39x 39x 39x 2x 2x 2x 2x  
import { createId } from '@paralleldrive/cuid2'
import { integer, sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core'
import { arcadeRooms } from './arcade-rooms'
 
/**
 * Game-specific configuration settings for arcade rooms
 * Each row represents one game's settings for one room
 */
export const roomGameConfigs = sqliteTable(
  'room_game_configs',
  {
    id: text('id')
      .primaryKey()
      .$defaultFn(() => createId()),
 
    // Room reference
    roomId: text('room_id')
      .notNull()
      .references(() => arcadeRooms.id, { onDelete: 'cascade' }),
 
    // Game identifier
    // Accepts any string - validation happens at runtime against validator registry
    gameName: text('game_name').notNull(),
 
    // Game-specific configuration JSON
    // Structure depends on gameName:
    // - matching: { gameType, difficulty, turnTimer }
    // - memory-quiz: { selectedCount, displayTime, selectedDifficulty, playMode }
    // - complement-race: TBD
    // - number-guesser: { minNumber, maxNumber, roundsToWin }
    // - math-sprint: { difficulty, questionsPerRound, timePerQuestion }
    config: text('config', { mode: 'json' }).notNull(),
 
    // Timestamps
    createdAt: integer('created_at', { mode: 'timestamp' })
      .notNull()
      .$defaultFn(() => new Date()),
    updatedAt: integer('updated_at', { mode: 'timestamp' })
      .notNull()
      .$defaultFn(() => new Date()),
  },
  (table) => ({
    // Ensure only one config per game per room
    uniqueRoomGame: uniqueIndex('room_game_idx').on(table.roomId, table.gameName),
  })
)
 
export type RoomGameConfig = typeof roomGameConfigs.$inferSelect
export type NewRoomGameConfig = typeof roomGameConfigs.$inferInsert