diff --git a/database/schema.ts b/database/schema.ts index f763fca..bff5ea5 100644 --- a/database/schema.ts +++ b/database/schema.ts @@ -1,4 +1,4 @@ -import { integer, pgTable, varchar, uuid, timestamp, pgEnum, boolean, text, date, decimal, uniqueIndex, index, jsonb } from "drizzle-orm/pg-core"; +import { check, integer, pgTable, varchar, uuid, timestamp, pgEnum, boolean, text, date, decimal, uniqueIndex, index, jsonb } from "drizzle-orm/pg-core"; import { relations, sql } from "drizzle-orm"; export const users = pgTable("users", { @@ -554,7 +554,12 @@ export const scoringEvents = pgTable("scoring_events", { completedAt: timestamp("completed_at"), createdAt: timestamp("created_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(), -}); +}, (t) => ({ + qualifyingEventsRequireTournament: check( + "scoring_events_qualifying_require_tournament", + sql`NOT ${t.isQualifyingEvent} OR ${t.tournamentId} IS NOT NULL`, + ), +})); // Results for participants in specific events export const eventResults = pgTable("event_results", {