2025-10-11 00:07:39 -07:00
|
|
|
import { integer, pgTable, varchar, uuid, timestamp, pgEnum } from "drizzle-orm/pg-core";
|
2025-10-10 23:04:50 -07:00
|
|
|
|
2025-10-11 00:53:39 -07:00
|
|
|
// Users table - synced from Clerk
|
|
|
|
|
export const users = pgTable("users", {
|
|
|
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
|
|
|
clerkId: varchar("clerk_id", { length: 255 }).notNull().unique(),
|
|
|
|
|
email: varchar("email", { length: 255 }).notNull(),
|
|
|
|
|
displayName: varchar("display_name", { length: 255 }),
|
|
|
|
|
firstName: varchar("first_name", { length: 255 }),
|
|
|
|
|
lastName: varchar("last_name", { length: 255 }),
|
|
|
|
|
imageUrl: varchar("image_url", { length: 512 }),
|
|
|
|
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
|
|
|
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-11 00:07:39 -07:00
|
|
|
// Fantasy League Tables
|
|
|
|
|
export const seasonStatusEnum = pgEnum("season_status", [
|
|
|
|
|
"pre_draft",
|
|
|
|
|
"draft",
|
|
|
|
|
"active",
|
|
|
|
|
"completed",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
export const leagues = pgTable("leagues", {
|
|
|
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
|
|
|
name: varchar("name", { length: 255 }).notNull(),
|
|
|
|
|
createdBy: varchar("created_by", { length: 255 }).notNull(), // Clerk user ID
|
|
|
|
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
|
|
|
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const seasons = pgTable("seasons", {
|
|
|
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
|
|
|
leagueId: uuid("league_id")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => leagues.id, { onDelete: "cascade" }),
|
|
|
|
|
year: integer("year").notNull(),
|
|
|
|
|
status: seasonStatusEnum("status").notNull().default("pre_draft"),
|
|
|
|
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
|
|
|
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const teams = pgTable("teams", {
|
|
|
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
|
|
|
seasonId: uuid("season_id")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => seasons.id, { onDelete: "cascade" }),
|
|
|
|
|
name: varchar("name", { length: 255 }).notNull(),
|
|
|
|
|
ownerId: varchar("owner_id", { length: 255 }), // Clerk user ID, nullable
|
|
|
|
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
|
|
|
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
|
|
|
});
|
2025-10-11 00:29:04 -07:00
|
|
|
|
|
|
|
|
export const commissioners = pgTable("commissioners", {
|
|
|
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
|
|
|
leagueId: uuid("league_id")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => leagues.id, { onDelete: "cascade" }),
|
|
|
|
|
userId: varchar("user_id", { length: 255 }).notNull(), // Clerk user ID
|
|
|
|
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
|
|
|
});
|