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