Skip to content

Commit fc7b6b8

Browse files
committed
Add more indices
1 parent 71e9b17 commit fc7b6b8

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

prisma/schema.prisma

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ model scorecard {
3737
@@index([challengeTrack])
3838
@@index([challengeType])
3939
@@index([name])
40+
@@index([id]) // Index for direct ID lookups
41+
@@index([type]) // Index for filtering by scorecard type
42+
@@index([status]) // Index for filtering by status (e.g. ACTIVE scorecards)
4043
}
4144

4245
enum ScorecardStatus {
@@ -77,6 +80,10 @@ model scorecardGroup {
7780
7881
scorecard scorecard @relation(fields: [scorecardId], references: [id], onDelete: Cascade)
7982
sections scorecardSection[]
83+
84+
@@index([id]) // Index for direct ID lookups
85+
@@index([scorecardId]) // Index for joining with scorecard table
86+
@@index([sortOrder]) // Index for ordering groups
8087
}
8188

8289
model scorecardSection {
@@ -93,6 +100,10 @@ model scorecardSection {
93100
94101
group scorecardGroup @relation(fields: [scorecardGroupId], references: [id], onDelete: Cascade)
95102
questions scorecardQuestion[]
103+
104+
@@index([id]) // Index for direct ID lookups
105+
@@index([scorecardGroupId]) // Index for joining with scorecardGroup table
106+
@@index([sortOrder]) // Index for ordering sections
96107
}
97108

98109
enum QuestionType {
@@ -121,6 +132,11 @@ model scorecardQuestion {
121132
scaleMax Int? // Maximum value for scale (used when type is SCALE)
122133
123134
section scorecardSection @relation(fields: [scorecardSectionId], references: [id], onDelete: Cascade)
135+
136+
@@index([id]) // Index for direct ID lookups
137+
@@index([scorecardSectionId]) // Index for joining with scorecardSection table
138+
@@index([type]) // Index for filtering questions by type
139+
@@index([sortOrder]) // Index for ordering questions
124140
}
125141

126142
model review {
@@ -141,9 +157,12 @@ model review {
141157
scorecard scorecard @relation(fields: [scorecardId], references: [id], onDelete: Cascade)
142158
reviewItems reviewItem[]
143159
144-
@@index([committed]) // Add index for the committed field
145-
@@index([submissionId]) // Index for submissionId field
146-
@@index([resourceId]) // Index for resourceId field
160+
@@index([committed]) // Index for filtering by committed status
161+
@@index([submissionId]) // Index for filtering by submission
162+
@@index([resourceId]) // Index for filtering by resource (reviewer)
163+
@@index([id]) // Index for direct ID lookups
164+
@@index([phaseId]) // Index for filtering by phase
165+
@@index([scorecardId]) // Index for joining with scorecard table
147166
}
148167

149168
model reviewItem {
@@ -162,8 +181,9 @@ model reviewItem {
162181
163182
review review @relation(fields: [reviewId], references: [id], onDelete: Cascade)
164183
reviewItemComments reviewItemComment[]
165-
@@index([reviewId]) // Index for reviewId field
166-
@@index([id]) // Index for id field
184+
@@index([reviewId]) // Index for joining with review table
185+
@@index([id]) // Index for direct ID lookups
186+
@@index([scorecardQuestionId]) // Index for joining with scorecardQuestion table
167187
}
168188

169189
model reviewItemComment {
@@ -181,8 +201,10 @@ model reviewItemComment {
181201
182202
reviewItem reviewItem @relation(fields: [reviewItemId], references: [id], onDelete: Cascade)
183203
appeal appeal?
184-
@@index([reviewItemId]) // Index for reviewItemId field
185-
@@index([id]) // Index for id field
204+
@@index([reviewItemId]) // Index for joining with reviewItem table
205+
@@index([id]) // Index for direct ID lookups
206+
@@index([resourceId]) // Index for filtering by resource (commenter)
207+
@@index([type]) // Index for filtering by comment type
186208
}
187209

188210
enum ReviewItemCommentType {
@@ -214,7 +236,9 @@ model appeal {
214236
reviewItemComment reviewItemComment @relation(fields: [reviewItemCommentId], references: [id], onDelete: Cascade) // Define fields and references here
215237
appealResponse appealResponse?
216238
217-
@@index([resourceId]) // Index for resourceId field
239+
@@index([resourceId]) // Index for resource ID
240+
@@index([id]) // Index for direct ID lookups
241+
@@index([reviewItemCommentId]) // Index for joining with reviewItemComment table
218242
}
219243

220244
model appealResponse {
@@ -230,6 +254,10 @@ model appealResponse {
230254
updatedBy String
231255
232256
appeal appeal @relation(fields: [appealId], references: [id], onDelete: Cascade)
257+
258+
@@index([id]) // Index for direct ID lookups
259+
@@index([appealId]) // Index for joining with appeal table
260+
@@index([resourceId]) // Index for filtering by resource (responder)
233261
}
234262

235263
model challengeResult {
@@ -254,6 +282,9 @@ model challengeResult {
254282
updatedBy String
255283
256284
@@id([challengeId, userId])
285+
@@index([challengeId]) // Index for filtering by challenge
286+
@@index([userId]) // Index for filtering by user
287+
@@index([submissionId]) // Index for filtering by submission
257288
}
258289

259290
model contactRequest {
@@ -265,4 +296,8 @@ model contactRequest {
265296
createdBy String
266297
updatedAt DateTime @updatedAt
267298
updatedBy String
299+
300+
@@index([id]) // Index for direct ID lookups
301+
@@index([resourceId]) // Index for filtering by resource (requester)
302+
@@index([challengeId]) // Index for filtering by challenge
268303
}

0 commit comments

Comments
 (0)