132 lines
3.9 KiB
Plaintext
132 lines
3.9 KiB
Plaintext
// Templates2 Base — core data model shared by every case.
|
|
// SQLite in development (file:./dev.db); switch the datasource url to Postgres in production.
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
email String @unique
|
|
passwordHash String
|
|
name String?
|
|
role String @default("user") // user | admin
|
|
createdAt DateTime @default(now())
|
|
sessions Session[]
|
|
subscription Subscription?
|
|
auditLogs AuditLog[]
|
|
bookings Booking[]
|
|
}
|
|
|
|
model Session {
|
|
id String @id @default(cuid())
|
|
token String @unique
|
|
userId String
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
expiresAt DateTime
|
|
createdAt DateTime @default(now())
|
|
|
|
@@index([userId])
|
|
}
|
|
|
|
model Subscription {
|
|
id String @id @default(cuid())
|
|
userId String @unique
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
plan String @default("free") // free | pro
|
|
status String @default("active") // active | canceled | past_due
|
|
provider String @default("mock") // mock | stripe
|
|
currentPeriodEnd DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model AuditLog {
|
|
id String @id @default(cuid())
|
|
actorId String?
|
|
actor User? @relation(fields: [actorId], references: [id], onDelete: SetNull)
|
|
action String
|
|
target String?
|
|
meta String?
|
|
createdAt DateTime @default(now())
|
|
|
|
@@index([actorId])
|
|
}
|
|
|
|
// --- Booking domain ---------------------------------------------------------
|
|
|
|
model Service {
|
|
id String @id @default(cuid())
|
|
slug String @unique
|
|
name String
|
|
description String @default("")
|
|
durationMin Int
|
|
priceCents Int
|
|
active Boolean @default(true)
|
|
createdAt DateTime @default(now())
|
|
staff StaffService[]
|
|
bookings Booking[]
|
|
}
|
|
|
|
model Staff {
|
|
id String @id @default(cuid())
|
|
slug String @unique
|
|
name String
|
|
title String @default("")
|
|
bio String?
|
|
avatarColor String @default("#4f46e5")
|
|
createdAt DateTime @default(now())
|
|
services StaffService[]
|
|
hours WorkingHour[]
|
|
bookings Booking[]
|
|
}
|
|
|
|
model StaffService {
|
|
staffId String
|
|
serviceId String
|
|
staff Staff @relation(fields: [staffId], references: [id], onDelete: Cascade)
|
|
service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
|
|
|
|
@@id([staffId, serviceId])
|
|
@@index([serviceId])
|
|
}
|
|
|
|
model WorkingHour {
|
|
id String @id @default(cuid())
|
|
staffId String
|
|
weekday Int // 0 = Sunday … 6 = Saturday
|
|
startMin Int // minutes from midnight, in the site timezone
|
|
endMin Int
|
|
staff Staff @relation(fields: [staffId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([staffId])
|
|
}
|
|
|
|
model Booking {
|
|
id String @id @default(cuid())
|
|
serviceId String
|
|
service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
|
|
staffId String?
|
|
staff Staff? @relation(fields: [staffId], references: [id], onDelete: SetNull)
|
|
userId String?
|
|
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
|
startsAt DateTime
|
|
endsAt DateTime
|
|
status String @default("pending") // pending | confirmed | cancelled | completed | no_show
|
|
customerName String
|
|
customerEmail String
|
|
notes String?
|
|
confirmationSentAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@index([userId])
|
|
@@index([staffId])
|
|
@@index([startsAt])
|
|
}
|