major functionalities are fixed
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Appointment" ADD COLUMN "staffId" INTEGER;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Staff" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"email" TEXT,
|
||||
"role" TEXT NOT NULL,
|
||||
"phone" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "Staff_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Appointment" ADD CONSTRAINT "Appointment_staffId_fkey" FOREIGN KEY ("staffId") REFERENCES "Staff"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Appointment" ALTER COLUMN "startTime" SET DATA TYPE TEXT,
|
||||
ALTER COLUMN "endTime" SET DATA TYPE TEXT;
|
||||
@@ -8,9 +8,10 @@ generator client {
|
||||
provider = "prisma-client-js"
|
||||
output = "../generated/prisma"
|
||||
}
|
||||
|
||||
generator zod {
|
||||
provider = "prisma-zod-generator"
|
||||
output = "../shared/" // Zod schemas will be generated here inside `db/shared`
|
||||
output = "../shared/" // Zod schemas will be generated here inside `db/shared`
|
||||
}
|
||||
|
||||
datasource db {
|
||||
@@ -18,53 +19,63 @@ datasource db {
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
username String @unique
|
||||
password String
|
||||
patients Patient[]
|
||||
id Int @id @default(autoincrement())
|
||||
username String @unique
|
||||
password String
|
||||
patients Patient[]
|
||||
appointments Appointment[]
|
||||
}
|
||||
|
||||
model Patient {
|
||||
id Int @id @default(autoincrement())
|
||||
firstName String
|
||||
lastName String
|
||||
dateOfBirth DateTime @db.Date
|
||||
gender String
|
||||
phone String
|
||||
email String?
|
||||
address String?
|
||||
city String?
|
||||
zipCode String?
|
||||
insuranceProvider String?
|
||||
insuranceId String?
|
||||
groupNumber String?
|
||||
policyHolder String?
|
||||
allergies String?
|
||||
medicalConditions String?
|
||||
status String @default("active")
|
||||
userId Int
|
||||
createdAt DateTime @default(now())
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
appointments Appointment[]
|
||||
id Int @id @default(autoincrement())
|
||||
firstName String
|
||||
lastName String
|
||||
dateOfBirth DateTime @db.Date
|
||||
gender String
|
||||
phone String
|
||||
email String?
|
||||
address String?
|
||||
city String?
|
||||
zipCode String?
|
||||
insuranceProvider String?
|
||||
insuranceId String?
|
||||
groupNumber String?
|
||||
policyHolder String?
|
||||
allergies String?
|
||||
medicalConditions String?
|
||||
status String @default("active")
|
||||
userId Int
|
||||
createdAt DateTime @default(now())
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
appointments Appointment[]
|
||||
}
|
||||
|
||||
model Appointment {
|
||||
id Int @id @default(autoincrement())
|
||||
patientId Int
|
||||
userId Int
|
||||
staffId Int? // Optional: Appointment may or may not have staff assigned
|
||||
title String
|
||||
date DateTime @db.Date
|
||||
startTime DateTime @db.Time
|
||||
endTime DateTime @db.Time
|
||||
startTime String // Store time as "hh:mm"
|
||||
endTime String // Store time as "hh:mm"
|
||||
type String // e.g., "checkup", "cleaning", "filling", etc.
|
||||
notes String?
|
||||
status String @default("scheduled") // "scheduled", "completed", "cancelled", "no-show"
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
patient Patient @relation(fields: [patientId], references: [id])
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
patient Patient @relation(fields: [patientId], references: [id])
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
staff Staff? @relation(fields: [staffId], references: [id])
|
||||
}
|
||||
|
||||
model Staff {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
email String?
|
||||
role String // e.g., "Dentist", "Hygienist", "Assistant"
|
||||
phone String?
|
||||
createdAt DateTime @default(now())
|
||||
appointments Appointment[]
|
||||
}
|
||||
93
packages/db/prisma/seed.ts
Normal file
93
packages/db/prisma/seed.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { PrismaClient } from '../generated/prisma';
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
console.log("Here")
|
||||
async function main() {
|
||||
// Create multiple users
|
||||
const users = await prisma.user.createMany({
|
||||
data: [
|
||||
{ username: 'admin2', password: '123456' },
|
||||
{ username: 'bob', password: '123456' },
|
||||
],
|
||||
});
|
||||
|
||||
const createdUsers = await prisma.user.findMany();
|
||||
|
||||
// Creatin staff
|
||||
await prisma.staff.createMany({
|
||||
data: [
|
||||
{ name: 'Dr. Kai Gao', role: 'Doctor' },
|
||||
{ name: 'Dr. Jane Smith', role: 'Doctor' },
|
||||
],
|
||||
});
|
||||
|
||||
const staffMembers = await prisma.staff.findMany();
|
||||
|
||||
// Create multiple patients
|
||||
const patients = await prisma.patient.createMany({
|
||||
data: [
|
||||
{
|
||||
firstName: 'Emily',
|
||||
lastName: 'Clark',
|
||||
dateOfBirth: new Date('1985-06-15'),
|
||||
gender: 'female',
|
||||
phone: '555-0001',
|
||||
email: 'emily@example.com',
|
||||
address: '101 Apple Rd',
|
||||
city: 'Newtown',
|
||||
zipCode: '10001',
|
||||
userId: createdUsers[0].id,
|
||||
},
|
||||
{
|
||||
firstName: 'Michael',
|
||||
lastName: 'Brown',
|
||||
dateOfBirth: new Date('1979-09-10'),
|
||||
gender: 'male',
|
||||
phone: '555-0002',
|
||||
email: 'michael@example.com',
|
||||
address: '202 Banana Ave',
|
||||
city: 'Oldtown',
|
||||
zipCode: '10002',
|
||||
userId: createdUsers[1].id,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const createdPatients = await prisma.patient.findMany();
|
||||
|
||||
// Create multiple appointments
|
||||
await prisma.appointment.createMany({
|
||||
data: [
|
||||
{
|
||||
patientId: createdPatients[0].id,
|
||||
userId: createdUsers[0].id,
|
||||
title: 'Initial Consultation',
|
||||
date: new Date('2025-06-01'),
|
||||
startTime: new Date('2025-06-01T10:00:00'),
|
||||
endTime: new Date('2025-06-01T10:30:00'),
|
||||
type: 'consultation',
|
||||
},
|
||||
{
|
||||
patientId: createdPatients[1].id,
|
||||
userId: createdUsers[1].id,
|
||||
title: 'Follow-up',
|
||||
date: new Date('2025-06-02'),
|
||||
startTime: new Date('2025-06-02T14:00:00'),
|
||||
endTime: new Date('2025-06-02T14:30:00'),
|
||||
type: 'checkup',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
console.log('✅ Seeded multiple users, patients, and appointments.');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
console.log("Done seeding logged.")
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user