- Prisma com SQLite configurado - Tabelas: users, sessions, subscriptions, children, etc - Auth.js com credentials provider - API de registro com criação de usuário + criança - Middleware para proteger rotas - Login/Cadastro funcionais - Dashboard com sessão real
180 lines
5.1 KiB
Plaintext
180 lines
5.1 KiB
Plaintext
// This is your Prisma schema file,
|
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
// ============ AUTENTICAÇÃO ============
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
email String @unique
|
|
password String
|
|
name String
|
|
phone String?
|
|
city String?
|
|
state String?
|
|
role String @default("parent") // parent, therapist, admin
|
|
emailVerified DateTime?
|
|
image String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relações
|
|
accounts Account[]
|
|
sessions Session[]
|
|
subscription Subscription?
|
|
children Child[]
|
|
|
|
// Para terapeutas
|
|
patients TherapistPatient[] @relation("TherapistPatients")
|
|
assignedTo TherapistPatient[] @relation("PatientAssignments")
|
|
appointments Appointment[] @relation("TherapistAppointments")
|
|
sessionsNotes SessionNote[]
|
|
}
|
|
|
|
model Account {
|
|
id String @id @default(cuid())
|
|
userId String
|
|
type String
|
|
provider String
|
|
providerAccountId String
|
|
refresh_token String?
|
|
access_token String?
|
|
expires_at Int?
|
|
token_type String?
|
|
scope String?
|
|
id_token String?
|
|
session_state String?
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([provider, providerAccountId])
|
|
}
|
|
|
|
model Session {
|
|
id String @id @default(cuid())
|
|
sessionToken String @unique
|
|
userId String
|
|
expires DateTime
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
model VerificationToken {
|
|
identifier String
|
|
token String @unique
|
|
expires DateTime
|
|
|
|
@@unique([identifier, token])
|
|
}
|
|
|
|
// ============ PAGAMENTOS ============
|
|
|
|
model Subscription {
|
|
id String @id @default(cuid())
|
|
userId String @unique
|
|
plan String // essencial, completo, intensivo
|
|
status String @default("pending") // pending, active, cancelled, expired
|
|
stripeCustomerId String?
|
|
stripeSubId String?
|
|
currentPeriodEnd DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
// ============ CRIANÇAS ============
|
|
|
|
model Child {
|
|
id String @id @default(cuid())
|
|
parentId String
|
|
name String
|
|
birthDate DateTime
|
|
diagnosis String
|
|
diagnosisDate String?
|
|
currentTherapies String? // JSON array
|
|
priorities String? // JSON array
|
|
challenges String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
parent User @relation(fields: [parentId], references: [id], onDelete: Cascade)
|
|
progress Progress[]
|
|
appointments Appointment[]
|
|
sessionNotes SessionNote[]
|
|
}
|
|
|
|
// ============ TERAPEUTAS ============
|
|
|
|
model TherapistPatient {
|
|
id String @id @default(cuid())
|
|
therapistId String
|
|
patientId String
|
|
createdAt DateTime @default(now())
|
|
|
|
therapist User @relation("TherapistPatients", fields: [therapistId], references: [id])
|
|
patient User @relation("PatientAssignments", fields: [patientId], references: [id])
|
|
|
|
@@unique([therapistId, patientId])
|
|
}
|
|
|
|
// ============ AGENDAMENTOS ============
|
|
|
|
model Appointment {
|
|
id String @id @default(cuid())
|
|
childId String
|
|
therapistId String
|
|
scheduledAt DateTime
|
|
duration Int @default(50) // minutos
|
|
status String @default("scheduled") // scheduled, completed, cancelled, no-show
|
|
roomUrl String? // URL Daily.co
|
|
roomName String?
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
child Child @relation(fields: [childId], references: [id])
|
|
therapist User @relation("TherapistAppointments", fields: [therapistId], references: [id])
|
|
sessionNote SessionNote?
|
|
}
|
|
|
|
// ============ NOTAS DE SESSÃO ============
|
|
|
|
model SessionNote {
|
|
id String @id @default(cuid())
|
|
appointmentId String @unique
|
|
childId String
|
|
therapistId String
|
|
content String // Markdown ou texto
|
|
objectives String? // JSON array
|
|
progress String? // JSON object com métricas
|
|
nextSteps String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
appointment Appointment @relation(fields: [appointmentId], references: [id])
|
|
child Child @relation(fields: [childId], references: [id])
|
|
therapist User @relation(fields: [therapistId], references: [id])
|
|
}
|
|
|
|
// ============ PROGRESSO ============
|
|
|
|
model Progress {
|
|
id String @id @default(cuid())
|
|
childId String
|
|
category String // comunicacao, habilidades_sociais, autonomia, regulacao_emocional
|
|
value Int // 0-100
|
|
notes String?
|
|
date DateTime @default(now())
|
|
createdAt DateTime @default(now())
|
|
|
|
child Child @relation(fields: [childId], references: [id])
|
|
}
|