| 1 | import { |
| 2 | pgTable, |
| 3 | uuid, |
| 4 | varchar, |
| 5 | timestamp, |
| 6 | integer, |
| 7 | pgEnum, |
| 8 | } from 'drizzle-orm/pg-core'; |
| 9 | import { users } from './users'; |
| 10 | import { events } from './events'; |
| 11 | |
| 12 | export const ticketStatusEnum = pgEnum('ticket_status', [ |
| 13 | 'PENDING', |
| 14 | 'CONFIRMED', |
| 15 | 'CHECKED_IN', |
| 16 | 'CANCELLED', |
| 17 | ]); |
| 18 | |
| 19 | export const tickets = pgTable('tickets', { |
| 20 | id: uuid('id').defaultRandom().primaryKey(), |
| 21 | eventId: uuid('event_id') |
| 22 | .references(() => events.id) |
| 23 | .notNull(), |
| 24 | userId: uuid('user_id') |
| 25 | .references(() => users.id) |
| 26 | .notNull(), |
| 27 | quantity: integer('quantity').default(1).notNull(), |
| 28 | totalPrice: integer('total_price').notNull(), |
| 29 | status: ticketStatusEnum('status').default('PENDING').notNull(), |
| 30 | ticketCode: varchar('ticket_code', { length: 20 }).unique().notNull(), |
| 31 | purchasedAt: timestamp('purchased_at').defaultNow().notNull(), |
| 32 | checkedInAt: timestamp('checked_in_at'), |
| 33 | createdAt: timestamp('created_at').defaultNow().notNull(), |
| 34 | updatedAt: timestamp('updated_at').defaultNow().notNull(), |
| 35 | }); |
| 36 | |
| 37 | export type Ticket = typeof tickets.$inferSelect; |
| 38 | export type NewTicket = typeof tickets.$inferInsert; |