All files / web/src/db/schema parent-child.ts

100% Statements 36/36
100% Branches 3/3
100% Functions 2/2
100% Lines 36/36

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 372x 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 2x 2x 2x 2x  
import { integer, primaryKey, sqliteTable, text } from 'drizzle-orm/sqlite-core'
import { players } from './players'
import { users } from './users'
 
/**
 * Parent-child relationships
 *
 * Many-to-many relationship between parents (users) and children (players).
 * A child can have multiple parents, and a parent can have multiple children.
 * All linked parents have equal access to the child.
 */
export const parentChild = sqliteTable(
  'parent_child',
  {
    /** Parent's user ID */
    parentUserId: text('parent_user_id')
      .notNull()
      .references(() => users.id, { onDelete: 'cascade' }),
 
    /** Child's player ID */
    childPlayerId: text('child_player_id')
      .notNull()
      .references(() => players.id, { onDelete: 'cascade' }),
 
    /** When this relationship was created */
    linkedAt: integer('linked_at', { mode: 'timestamp' })
      .notNull()
      .$defaultFn(() => new Date()),
  },
  (table) => ({
    pk: primaryKey({ columns: [table.parentUserId, table.childPlayerId] }),
  })
)
 
export type ParentChild = typeof parentChild.$inferSelect
export type NewParentChild = typeof parentChild.$inferInsert