brackt/database/schema.ts

67 lines
2.5 KiB
TypeScript

import { integer, pgTable, varchar, uuid, timestamp, pgEnum } from "drizzle-orm/pg-core";
export const guestBook = pgTable("guestBook", {
id: integer().primaryKey().generatedAlwaysAsIdentity(),
name: varchar({ length: 255 }).notNull(),
email: varchar({ length: 255 }).notNull().unique(),
});
// 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(),
});
// 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(),
});
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(),
});