Skip to content

Commit

Permalink
Add unique indexes and modify DfdaUserTreatmentReport
Browse files Browse the repository at this point in the history
Introduced unique constraints on multiple Dfda user report tables to avoid duplicate records. Added a non-null "tried" column to the DfdaUserTreatmentReport table and made "effectiveness" field optional.
  • Loading branch information
mikepsinn committed Sep 5, 2024
1 parent 66ca1ff commit 9c41006
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
25 changes: 25 additions & 0 deletions prisma/migrations/20240905165732_unique_dfda_indexes/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Warnings:
- A unique constraint covering the columns `[userId,conditionId]` on the table `DfdaUserConditionReport` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[userId,sideEffectId,treatmentId]` on the table `DfdaUserSideEffectReport` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[userId,symptomId,conditionId]` on the table `DfdaUserSymptomReport` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[userId,treatmentId,conditionId]` on the table `DfdaUserTreatmentReport` will be added. If there are existing duplicate values, this will fail.
- Added the required column `tried` to the `DfdaUserTreatmentReport` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "DfdaUserTreatmentReport" ADD COLUMN "tried" BOOLEAN NOT NULL,
ALTER COLUMN "effectiveness" DROP NOT NULL;

-- CreateIndex
CREATE UNIQUE INDEX "DfdaUserConditionReport_userId_conditionId_key" ON "DfdaUserConditionReport"("userId", "conditionId");

-- CreateIndex
CREATE UNIQUE INDEX "DfdaUserSideEffectReport_userId_sideEffectId_treatmentId_key" ON "DfdaUserSideEffectReport"("userId", "sideEffectId", "treatmentId");

-- CreateIndex
CREATE UNIQUE INDEX "DfdaUserSymptomReport_userId_symptomId_conditionId_key" ON "DfdaUserSymptomReport"("userId", "symptomId", "conditionId");

-- CreateIndex
CREATE UNIQUE INDEX "DfdaUserTreatmentReport_userId_treatmentId_conditionId_key" ON "DfdaUserTreatmentReport"("userId", "treatmentId", "conditionId");
11 changes: 10 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,8 @@ model DfdaUserConditionReport {
createdAt DateTime @default(now())
deletedAt DateTime?
severity Severity
@@unique([userId, conditionId])
}

model DfdaUserSymptomReport {
Expand All @@ -1353,6 +1355,8 @@ model DfdaUserSymptomReport {
createdAt DateTime @default(now())
deletedAt DateTime?
severity Severity
@@unique([userId, symptomId, conditionId])
}

model DfdaUserTreatmentReport {
Expand All @@ -1366,7 +1370,10 @@ model DfdaUserTreatmentReport {
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
deletedAt DateTime?
effectiveness Effectiveness
effectiveness Effectiveness?
tried Boolean
@@unique([userId, treatmentId, conditionId])
}

model DfdaUserSideEffectReport {
Expand All @@ -1381,6 +1388,8 @@ model DfdaUserSideEffectReport {
createdAt DateTime @default(now())
deletedAt DateTime?
severity Severity
@@unique([userId, sideEffectId, treatmentId])
}

enum Severity {
Expand Down

0 comments on commit 9c41006

Please sign in to comment.