@@ -7,56 +7,22 @@ datasource db {
77 url = env (" DATABASE_URL " )
88}
99
10- enum UserRole {
11- USER
12- ADMIN
13- SUPER_ADMIN
14- }
15-
16- enum BookingStatus {
17- PENDING
18- CONFIRMED
19- CANCELLED
20- COMPLETED
21- }
22-
23- enum WaitlistStatus {
24- ACTIVE
25- FULFILLED
26- CANCELLED
27- }
28-
29- enum LabStatus {
30- ACTIVE
31- MAINTENANCE
32- INACTIVE
33- }
34-
35- enum NotificationType {
36- BOOKING_CONFIRMATION
37- BOOKING_CANCELLATION
38- WAITLIST_NOTIFICATION
39- GENERAL_ANNOUNCEMENT
40- SLOT_AVAILABLE
41- SYSTEM_NOTIFICATION
42- }
43-
4410model User {
4511 id String @id @default (uuid () )
4612 user_name String
4713 user_email String @unique
4814 user_password String
4915 user_role UserRole @default (USER )
50- validation_key String ? @unique // SAMAGRA ID for alternative authentication
16+ validation_key String ? @unique
5117 resetToken String ? @unique
5218 resetTokenExpiry DateTime ?
53- organizationId String ? // Optional as users can book from multiple organizations
54- organization Organization ? @relation (fields : [organizationId ] , references : [id ] )
55- bookings Booking []
56- waitlists Waitlist []
57- notifications Notification []
19+ organizationId String ?
5820 createdAt DateTime @default (now () )
5921 updatedAt DateTime @updatedAt
22+ bookings Booking []
23+ notifications Notification []
24+ organization Organization ? @relation (fields : [organizationId ] , references : [id ] )
25+ waitlists Waitlist []
6026
6127 @@index ([user_email ] )
6228 @@index ([validation_key ] )
@@ -70,25 +36,25 @@ model Admin {
7036 admin_email String @unique
7137 admin_password String
7238 organizationId String
73- organization Organization @relation (fields : [organizationId ] , references : [id ] )
74- labs Lab [] // Labs managed by this admin
7539 createdAt DateTime @default (now () )
7640 updatedAt DateTime @updatedAt
41+ organization Organization @relation (fields : [organizationId ] , references : [id ] )
42+ labs Lab []
7743
7844 @@index ([admin_email ] )
79- @@index ([organizationId ] ) // Added index for foreign key
45+ @@index ([organizationId ] )
8046}
8147
8248model SuperAdmin {
8349 id String @id @default (uuid () )
8450 super_admin_name String
8551 super_admin_email String @unique
8652 super_admin_password String
87- validation_key String ? @unique // For system authentication if needed
88- organizations Organization []
89- managedBookings Booking [] // Direct relation to bookings managed by this SuperAdmin
53+ validation_key String ? @unique
9054 createdAt DateTime @default (now () )
9155 updatedAt DateTime @updatedAt
56+ managedBookings Booking []
57+ organizations Organization []
9258
9359 @@index ([super_admin_email ] )
9460}
@@ -98,30 +64,29 @@ model Organization {
9864 org_name String
9965 org_type String
10066 org_location String
101- users User []
102- admins Admin []
103- labs Lab []
104- notifications OrganizationNotification []
10567 superAdminId String ?
106- superAdmin SuperAdmin ? @relation (fields : [superAdminId ] , references : [id ] )
10768 createdAt DateTime @default (now () )
10869 updatedAt DateTime @updatedAt
70+ admins Admin []
71+ labs Lab []
72+ superAdmin SuperAdmin ? @relation (fields : [superAdminId ] , references : [id ] )
73+ notifications OrganizationNotification []
74+ users User []
10975
11076 @@index ([org_name ] )
11177 @@index ([superAdminId ] )
11278}
11379
114- // Added to match ERD relationship: Organization can receive Notification
11580model OrganizationNotification {
11681 id String @id @default (uuid () )
11782 organizationId String
118- organization Organization @relation (fields : [organizationId ] , references : [id ] )
11983 notification_type NotificationType
12084 notification_message String
12185 notification_timestamp DateTime @default (now () )
12286 read Boolean @default (false )
12387 createdAt DateTime @default (now () )
12488 updatedAt DateTime @updatedAt
89+ organization Organization @relation (fields : [organizationId ] , references : [id ] )
12590
12691 @@index ([organizationId ] )
12792}
@@ -133,49 +98,48 @@ model Lab {
13398 status LabStatus @default (ACTIVE )
13499 location String ?
135100 description String ?
136- timeSlots TimeSlot []
137101 organizationId String
138- organization Organization @relation (fields : [organizationId ] , references : [id ] )
139102 adminId String
140- admin Admin @relation (fields : [adminId ] , references : [id ] )
141103 createdAt DateTime @default (now () )
142104 updatedAt DateTime @updatedAt
105+ admin Admin @relation (fields : [adminId ] , references : [id ] )
106+ organization Organization @relation (fields : [organizationId ] , references : [id ] )
107+ timeSlots TimeSlot []
143108
144109 @@index ([organizationId ] )
145- @@index ([adminId ] ) // Added index for foreign key
110+ @@index ([adminId ] )
146111}
147112
148113model TimeSlot {
149114 id String @id @default (uuid () )
150115 lab_id String
151- lab Lab @relation (fields : [lab_id ] , references : [id ] )
152116 date DateTime
153117 start_time DateTime
154118 end_time DateTime
155119 status String @default (" AVAILABLE " )
156- bookings Booking []
157- waitlists Waitlist []
158120 createdAt DateTime @default (now () )
159121 updatedAt DateTime @updatedAt
122+ bookings Booking []
123+ lab Lab @relation (fields : [lab_id ] , references : [id ] )
124+ waitlists Waitlist []
160125
161126 @@index ([lab_id ] )
162127 @@index ([date ] )
163- @@index ([lab_id , date ] ) // Added composite index for common queries
128+ @@index ([lab_id , date ] )
164129}
165130
166131model Booking {
167132 id String @id @default (uuid () )
168133 user_id String
169- user User @relation (fields : [user_id ] , references : [id ] )
170134 slot_id String
171- timeSlot TimeSlot @relation (fields : [slot_id ] , references : [id ] )
172135 booking_status BookingStatus @default (PENDING )
173136 booking_timestamp DateTime @default (now () )
174- // Direct relation to SuperAdmin who manages this booking
175137 managedBy String ?
176- superAdmin SuperAdmin ? @relation (fields : [managedBy ] , references : [id ] )
177138 createdAt DateTime @default (now () )
178139 updatedAt DateTime @updatedAt
140+ superAdmin SuperAdmin ? @relation (fields : [managedBy ] , references : [id ] )
141+ timeSlot TimeSlot @relation (fields : [slot_id ] , references : [id ] )
142+ user User @relation (fields : [user_id ] , references : [id ] )
179143
180144 @@index ([user_id ] )
181145 @@index ([slot_id ] )
@@ -186,31 +150,65 @@ model Booking {
186150model Waitlist {
187151 id String @id @default (uuid () )
188152 user_id String
189- user User @relation (fields : [user_id ] , references : [id ] )
190153 slot_id String
191- timeSlot TimeSlot @relation (fields : [slot_id ] , references : [id ] )
192154 waitlist_position Int
193155 waitlist_status WaitlistStatus @default (ACTIVE )
194156 createdAt DateTime @default (now () )
195157 updatedAt DateTime @updatedAt
158+ timeSlot TimeSlot @relation (fields : [slot_id ] , references : [id ] )
159+ user User @relation (fields : [user_id ] , references : [id ] )
196160
197161 @@index ([user_id ] )
198162 @@index ([slot_id ] )
199- @@index ([waitlist_status ] ) // Added index for status queries
200- @@index ([slot_id , waitlist_position ] ) // Added composite index for position queries
163+ @@index ([waitlist_status ] )
164+ @@index ([slot_id , waitlist_position ] )
201165}
202166
203167model Notification {
204168 id String @id @default (uuid () )
205169 user_id String
206- user User @relation (fields : [user_id ] , references : [id ] )
207170 notification_type NotificationType
208171 notification_message String
209172 notification_timestamp DateTime @default (now () )
210173 read Boolean @default (false )
211174 createdAt DateTime @default (now () )
212175 updatedAt DateTime @updatedAt
176+ user User @relation (fields : [user_id ] , references : [id ] )
213177
214178 @@index ([user_id ] )
215- @@index ([read ] ) // Added index for unread notification queries
179+ @@index ([read ] )
180+ }
181+
182+ enum UserRole {
183+ USER
184+ ADMIN
185+ SUPER_ADMIN
186+ }
187+
188+ enum BookingStatus {
189+ PENDING
190+ CONFIRMED
191+ CANCELLED
192+ COMPLETED
193+ }
194+
195+ enum WaitlistStatus {
196+ ACTIVE
197+ FULFILLED
198+ CANCELLED
199+ }
200+
201+ enum LabStatus {
202+ ACTIVE
203+ MAINTENANCE
204+ INACTIVE
205+ }
206+
207+ enum NotificationType {
208+ BOOKING_CONFIRMATION
209+ BOOKING_CANCELLATION
210+ WAITLIST_NOTIFICATION
211+ GENERAL_ANNOUNCEMENT
212+ SLOT_AVAILABLE
213+ SYSTEM_NOTIFICATION
216214}
0 commit comments