@@ -1,3 +1,4 @@
|
||||
import { sql } from 'drizzle-orm'
|
||||
import { boolean, integer, pgTable, serial, text, timestamp, unique } from 'drizzle-orm/pg-core'
|
||||
|
||||
export const restaurantTables = pgTable('restaurant_tables', {
|
||||
@@ -17,11 +18,28 @@ export const reservations = pgTable(
|
||||
customerEmail: text('customer_email').notNull(),
|
||||
partySize: integer('party_size').notNull(),
|
||||
reservationTime: timestamp('reservation_time', { withTimezone: true }).notNull(),
|
||||
// Captured from the reservation-duration setting at booking time, so a later
|
||||
// change to that setting doesn't retroactively change how long past bookings
|
||||
// are considered to occupy their table.
|
||||
durationMinutes: integer('duration_minutes').notNull().default(90),
|
||||
cancelToken: text('cancel_token')
|
||||
.notNull()
|
||||
.unique()
|
||||
.default(sql`gen_random_uuid()`),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => [unique().on(table.tableId, table.reservationTime)],
|
||||
)
|
||||
|
||||
// Single-row table of restaurant-wide booking rules, editable by admins.
|
||||
export const restaurantSettings = pgTable('restaurant_settings', {
|
||||
id: serial('id').primaryKey(),
|
||||
reservationIntervalMinutes: integer('reservation_interval_minutes').notNull().default(15),
|
||||
reservationDurationMinutes: integer('reservation_duration_minutes').notNull().default(90),
|
||||
minLeadTimeMinutes: integer('min_lead_time_minutes').notNull().default(60),
|
||||
maxLeadTimeDays: integer('max_lead_time_days').notNull().default(60),
|
||||
})
|
||||
|
||||
// Better Auth's standard schema (staff accounts) — see https://www.better-auth.com/docs/concepts/database
|
||||
// `role`/`banned`/`banReason`/`banExpires` and `session.impersonatedBy` are added by the `admin` plugin.
|
||||
export const user = pgTable('user', {
|
||||
@@ -82,3 +100,4 @@ export const verification = pgTable('verification', {
|
||||
export type RestaurantTable = typeof restaurantTables.$inferSelect
|
||||
export type Reservation = typeof reservations.$inferSelect
|
||||
export type NewReservation = typeof reservations.$inferInsert
|
||||
export type RestaurantSettings = typeof restaurantSettings.$inferSelect
|
||||
|
||||
Reference in New Issue
Block a user