All files / web/src/db/schema room-bans.ts

100% Statements 45/45
100% Branches 4/4
100% Functions 1/1
100% Lines 45/45

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 462x 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'
 
/**
 * Users banned from specific rooms by hosts
 */
export const roomBans = sqliteTable(
  'room_bans',
  {
    id: text('id')
      .primaryKey()
      .$defaultFn(() => createId()),
 
    roomId: text('room_id')
      .notNull()
      .references(() => arcadeRooms.id, { onDelete: 'cascade' }),
 
    // Banned user
    userId: text('user_id').notNull(),
    userName: text('user_name', { length: 50 }).notNull(), // Name at time of ban
 
    // Who banned them
    bannedBy: text('banned_by').notNull(), // Host user ID
    bannedByName: text('banned_by_name', { length: 50 }).notNull(),
 
    // Ban details
    reason: text('reason', {
      enum: ['harassment', 'cheating', 'inappropriate-name', 'spam', 'afk', 'other'],
    }).notNull(),
    notes: text('notes', { length: 500 }), // Optional notes from host
 
    // Timestamps
    createdAt: integer('created_at', { mode: 'timestamp' })
      .notNull()
      .$defaultFn(() => new Date()),
  },
  (table) => ({
    // One ban record per user per room
    userRoomIdx: uniqueIndex('idx_room_bans_user_room').on(table.userId, table.roomId),
  })
)
 
export type RoomBan = typeof roomBans.$inferSelect
export type NewRoomBan = typeof roomBans.$inferInsert