Files
smartmenu-collina/prisma/schema.prisma
T
Jorem Juárez 244adaee30 Orders persistence/expiration, cart pairings, and brand header
BLOCK 1 — Orders persistence + expiration:
- New GET /api/[slug]/orders loads active orders from PostgreSQL on mount, so the
  dashboard survives reloads (SSE only carries live events); it also prunes
  completed orders older than the retention window on read (no cron)
- Restaurant.orderRetentionHours (default 24, migration 0007) + editor control in
  the Orders tab; settings PATCH accepts it

BLOCK 2 — Smart cart pairings (precomputed, zero tokens at runtime):
- Restaurant.pairings JSON (migration 0008) stores { productId: [productId] }
- Optional 'Generate smart suggestions' checkbox in the publish modal; on publish,
  one cheap Haiku call analyzes the snapshot and stores validated complements
  (lib/pairings.ts, reuses parseLenientJson). AI failure never breaks publishing
- pairings read live and exposed via the public menu; cart shows an auto-rotating,
  swipeable SuggestionCarousel of complements for what's in the cart (excluding
  items already added), each with Add — only when orders are on and pairings exist

BLOCK 3 — Brand header:
- Restaurant.bannerImage, profileImage, socialLinks (migration 0009)
- New editor Brand tab: upload banner + circular logo (reuses /upload), social
  links with common-platform suggestions and basic URL validation; saved via settings
- Public BrandHeader: full-bleed banner (edge-to-edge behind the island, safe-area
  aware), circular logo avatar, name, and clickable social icons (lucide-react).
  Graceful fallbacks (palette gradient banner, initial avatar) — no broken images.
  Images are language-independent

All read live (no republish needed). i18n es/en at parity; glassmorphism,
mobile-first and safe areas preserved. Adds lucide-react.

Verified: build passes; 9 migrations apply; orders persist + prune on read;
publish survives missing API key; pairings + brand exposed via /menu.
2026-06-15 17:25:35 -06:00

111 lines
4.1 KiB
Plaintext

generator client {
provider = "prisma-client-js"
// native = host platform (builder/runner are both node:20-alpine = musl).
// The explicit musl target guards the runtime engine in the final image.
binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Restaurant {
id String @id @default(cuid())
slug String @unique
name String
editorSecret String
username String
hashedPassword String
palette Json @default("{}")
qrConfig Json @default("{}") // artistic QR styling (qr-code-styling config)
ordersEnabled Boolean @default(false)
orderRetentionHours Int @default(24) // completed orders older than this are pruned on read
showMacros Boolean @default(false) // when false, the public menu hides all macro layers
pairings Json @default("{}") // precomputed cart suggestions { productId: [productId] }
bannerImage String? // wide brand banner (uploaded)
profileImage String? // circular logo/avatar (uploaded)
socialLinks Json @default("[]") // [{ platform, url }]
defaultLocale String @default("es")
active Boolean @default(true)
publishedVersionId String? @unique
createdAt DateTime @default(now())
publishedVersion MenuVersion? @relation("PublishedVersion", fields: [publishedVersionId], references: [id])
versions MenuVersion[] @relation("RestaurantVersions")
sections Section[]
products Product[]
orders Order[]
}
// Versioning system: a published snapshot of the whole menu.
model MenuVersion {
id String @id @default(cuid())
restaurantId String
versionName String
snapshot Json
publishedAt DateTime @default(now())
createdBy String?
restaurant Restaurant @relation("RestaurantVersions", fields: [restaurantId], references: [id], onDelete: Cascade)
publishedFor Restaurant? @relation("PublishedVersion")
@@index([restaurantId])
}
// Working DRAFT (not what the public sees).
model Section {
id String @id @default(cuid())
restaurantId String
name Json // { es, en }
order Int @default(0)
showMacros Boolean @default(true) // per-section override; only applies when Restaurant.showMacros is on
createdAt DateTime @default(now())
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
products Product[]
@@index([restaurantId])
}
// Working DRAFT product.
model Product {
id String @id @default(cuid())
sectionId String
restaurantId String
name Json // { es, en }
description Json @default("{}") // { es, en }
price Decimal @default(0) @db.Decimal(10, 2)
order Int @default(0)
isActive Boolean @default(true)
allergens String[] @default([])
dietTags String[] @default([])
macros Json @default("{}") // { protein, carbs, sugar, fat, fiber, kcal }
media Json @default("[]") // [{ type, path, order }]
translationStatus Json @default("{}") // { en: auto|reviewed }
aiEstimated Json @default("{}") // { macros: bool, allergens: bool } — flags AI-inferred data to verify
createdAt DateTime @default(now())
section Section @relation(fields: [sectionId], references: [id], onDelete: Cascade)
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
@@index([restaurantId])
@@index([sectionId])
}
model Order {
id String @id @default(cuid())
restaurantId String
tableNumber Int
items Json // [{ productId, name, qty, note?, price? }]
note String? // general note for the whole order
status String @default("active") // active | completed
createdAt DateTime @default(now())
completedAt DateTime?
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
@@index([restaurantId, status])
}