|
1 | | -import { pgEnum, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"; |
| 1 | +import { |
| 2 | + pgTable, |
| 3 | + text, |
| 4 | + timestamp, |
| 5 | + uuid, |
| 6 | + pgEnum, |
| 7 | + integer, |
| 8 | + boolean, |
| 9 | + jsonb, |
| 10 | +} from "drizzle-orm/pg-core"; |
2 | 11 |
|
3 | | -export const userRoleEnum = pgEnum("user_role", ["admin", "coach", "user"]); |
| 12 | +export const roleEnum = pgEnum("role", ["user", "admin", "coach"]); |
| 13 | +export const serviceTypeEnum = pgEnum("service_type", [ |
| 14 | + "coaching_session", |
| 15 | + "booking", |
| 16 | +]); |
| 17 | +export const bookingStatusEnum = pgEnum("booking_status", [ |
| 18 | + "pending", |
| 19 | + "confirmed", |
| 20 | + "cancelled", |
| 21 | +]); |
| 22 | +export const webinarTierEnum = pgEnum("webinar_tier", ["free", "premium"]); |
| 23 | +export const sessionStatusEnum = pgEnum("session_status", [ |
| 24 | + "pending", |
| 25 | + "confirmed", |
| 26 | + "cancelled", |
| 27 | + "completed", |
| 28 | +]); |
4 | 29 |
|
5 | 30 | export const profiles = pgTable("profiles", { |
6 | 31 | id: uuid("id").primaryKey(), |
7 | | - firstName: text("first_name"), |
8 | | - lastName: text("last_name"), |
9 | | - stripeCustomerId: text("stripe_customer_id"), |
10 | | - role: userRoleEnum("role").default("user").notNull(), |
11 | | - createdAt: timestamp("created_at").defaultNow(), |
12 | | - updatedAt: timestamp("updated_at"), |
| 32 | + firstName: text("first_name").notNull(), |
| 33 | + lastName: text("last_name").notNull(), |
| 34 | + role: roleEnum("role").notNull().default("user"), |
| 35 | + stripeCustomerId: text("stripe_customer_id").unique(), |
| 36 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 37 | + updatedAt: timestamp("updated_at").defaultNow().notNull(), |
| 38 | +}); |
| 39 | + |
| 40 | +export const services = pgTable("services", { |
| 41 | + id: uuid("id").primaryKey().defaultRandom(), |
| 42 | + title: text("title").notNull(), |
| 43 | + description: text("description"), |
| 44 | + type: serviceTypeEnum("type").notNull(), |
| 45 | + scheduledAt: jsonb("scheduled_at"), |
| 46 | + durationMinutes: integer("duration_minutes").notNull(), |
| 47 | + price: integer("price").notNull().default(0), |
| 48 | + isActive: boolean("is_active").notNull().default(true), |
| 49 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 50 | + updatedAt: timestamp("updated_at").defaultNow().notNull(), |
| 51 | +}); |
| 52 | + |
| 53 | +export const serviceBookings = pgTable("service_bookings", { |
| 54 | + id: uuid("id").primaryKey().defaultRandom(), |
| 55 | + userId: uuid("user_id") |
| 56 | + .references(() => profiles.id, { onDelete: "cascade" }) |
| 57 | + .notNull(), |
| 58 | + serviceId: uuid("service_id") |
| 59 | + .references(() => services.id, { onDelete: "cascade" }) |
| 60 | + .notNull(), |
| 61 | + status: bookingStatusEnum("status").notNull().default("pending"), |
| 62 | + notes: text("notes"), |
| 63 | + isActive: boolean("is_active").notNull().default(true), |
| 64 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 65 | + updatedAt: timestamp("updated_at").defaultNow().notNull(), |
| 66 | +}); |
| 67 | + |
| 68 | +export const webinars = pgTable("webinars", { |
| 69 | + id: uuid("id").primaryKey().defaultRandom(), |
| 70 | + title: text("title").notNull(), |
| 71 | + description: text("description"), |
| 72 | + tier: webinarTierEnum("tier").notNull().default("free"), |
| 73 | + durationMinutes: integer("duration_minutes").notNull(), |
| 74 | + youtubeUrl: text("youtube_url"), |
| 75 | + isActive: boolean("is_active").notNull().default(true), |
| 76 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 77 | + updatedAt: timestamp("updated_at").defaultNow().notNull(), |
| 78 | +}); |
| 79 | + |
| 80 | +export const coachingSessions = pgTable("coaching_sessions", { |
| 81 | + id: uuid("id").primaryKey().defaultRandom(), |
| 82 | + serviceId: uuid("service_id") |
| 83 | + .references(() => services.id, { onDelete: "cascade" }) |
| 84 | + .notNull(), |
| 85 | + coachId: uuid("coach_id") |
| 86 | + .references(() => profiles.id, { onDelete: "cascade" }) |
| 87 | + .notNull(), |
| 88 | + userId: uuid("user_id") |
| 89 | + .references(() => profiles.id, { onDelete: "cascade" }) |
| 90 | + .notNull(), |
| 91 | + scheduledAt: timestamp("scheduled_at"), |
| 92 | + durationMinutes: integer("duration_minutes").notNull().default(60), |
| 93 | + status: sessionStatusEnum("status").notNull().default("pending"), |
| 94 | + meetingUrl: text("meeting_url"), |
| 95 | + notes: text("notes"), |
| 96 | + selectedTimeSlots: jsonb("selected_time_slots").notNull(), |
| 97 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 98 | + updatedAt: timestamp("updated_at").defaultNow().notNull(), |
| 99 | +}); |
| 100 | + |
| 101 | +export const subscriptions = pgTable("subscriptions", { |
| 102 | + id: uuid("id").primaryKey().defaultRandom(), |
| 103 | + userId: uuid("user_id") |
| 104 | + .references(() => profiles.id, { onDelete: "cascade" }) |
| 105 | + .notNull() |
| 106 | + .unique(), |
| 107 | + stripeSubscriptionId: text("stripe_subscription_id").unique(), |
| 108 | + status: text("status").notNull().default("none"), |
| 109 | + stripePriceId: text("stripe_price_id"), |
| 110 | + cancelAtPeriodEnd: boolean("cancel_at_period_end").notNull().default(false), |
| 111 | + paymentMethodBrand: text("payment_method_brand"), |
| 112 | + paymentMethodLast4: text("payment_method_last4"), |
| 113 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 114 | + updatedAt: timestamp("updated_at").defaultNow().notNull(), |
| 115 | +}); |
| 116 | + |
| 117 | +export const purchases = pgTable("purchases", { |
| 118 | + id: uuid("id").primaryKey().defaultRandom(), |
| 119 | + userId: uuid("user_id") |
| 120 | + .references(() => profiles.id, { onDelete: "cascade" }) |
| 121 | + .notNull(), |
| 122 | + stripePriceId: text("stripe_price_id").notNull(), |
| 123 | + stripeSessionId: text("stripe_session_id").notNull().unique(), |
| 124 | + productName: text("product_name").notNull(), |
| 125 | + amount: integer("amount").notNull(), |
| 126 | + currency: text("currency").notNull(), |
| 127 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 128 | + updatedAt: timestamp("updated_at").defaultNow().notNull(), |
13 | 129 | }); |
0 commit comments