prisma: migrate medicine regimens + user notification prefs
Ditch the Reminder model/table, migrate the scheduledAt to be a native array; introduce also notifications enabled and dailyReminderTime to store user's push prefs
Pedro Lucas Porcellis porcellis@eletrotupi.com · 4 months ago
78897ecdf7cee4d440c833ccafd87ac6a75c6a81 Browse filesParents
23893a7Changed files
3
Additions
+28
Deletions
-15
/dev/null → api/prisma/migrations/20260627073054_migrate_scheduled_at_to_array/migration.sql
1 +
-- AlterTable: migrate scheduled_at from text? to text[] preserving existing data
2 +
ALTER TABLE "medicine_regimens"
3 +
ALTER COLUMN "scheduled_at" DROP DEFAULT,
4 +
ALTER COLUMN "scheduled_at" TYPE text[]
5 +
USING CASE
6 +
WHEN "scheduled_at" IS NULL THEN ARRAY[]::text[]
7 +
ELSE ARRAY["scheduled_at"]::text[]
8 +
END,
9 +
ALTER COLUMN "scheduled_at" SET DEFAULT '{}';
api/prisma/migrations/20260627073132_add_user_notification_prefs_drop_reminders/migration.sql
added+15 /dev/null → api/prisma/migrations/20260627073132_add_user_notification_prefs_drop_reminders/migration.sql
1 +
/*
2 +
Warnings:
3 +
4 +
- You are about to drop the `reminders` table. If the table is not empty, all the data it contains will be lost.
5 +
6 +
*/
7 +
-- DropForeignKey
8 +
ALTER TABLE "reminders" DROP CONSTRAINT "reminders_user_id_fkey";
9 +
10 +
-- AlterTable
11 +
ALTER TABLE "users" ADD COLUMN "daily_reminder_time" TEXT,
12 +
ADD COLUMN "notifications_enabled" BOOLEAN NOT NULL DEFAULT true;
13 +
14 +
-- DropTable
15 +
DROP TABLE "reminders";
api/prisma/schema.prisma
1 1
generator client {
2 2
provider = "prisma-client-js"
3 3
//output = "../src/generated/prisma"
4 4
}
5 5
22 22
23 23
activationCode String? @map("activation_code")
24 24
activationCodeExpiresAt DateTime? @map("activation_code_expires_at")
25 25
active Boolean @default(false) @map("active")
26 26
27 -
pushToken String? @map("push_token")
27 +
pushToken String? @map("push_token")
28 +
notificationsEnabled Boolean @default(true) @map("notifications_enabled")
29 +
dailyReminderTime String? @map("daily_reminder_time")
28 30
29 31
moods Mood[]
30 32
triggers Trigger[]
31 -
reminders Reminder[]
32 33
sleepRecords SleepRecord[]
33 34
insights Insight[]
34 35
medicineRegimens MedicineRegimen[]
35 36
careActions CareAction[]
36 37
101 102
model MedicineRegimen {
102 103
id Int @id @default(autoincrement())
103 104
name String
104 105
dosage String
105 106
periodicity MedicinePeriodicity
106 -
scheduledAt String? @map("scheduled_at")
107 +
scheduledAt String[] @default([]) @map("scheduled_at")
107 108
active Boolean @default(true)
108 109
userId Int @map("user_id")
109 110
110 111
user User @relation(fields: [userId], references: [id])
111 112
medicineLogs MedicineLog[]
172 173
careAction CareAction @relation(fields: [careActionId], references: [id], onDelete: Cascade)
173 174
174 175
@@map("activities")
175 176
}
176 177
177 -
model Reminder {
178 -
id Int @id @default(autoincrement())
179 -
hour Int
180 -
minute Int
181 -
description String?
182 -
active Boolean @default(false)
183 -
184 -
userId Int @map("user_id")
185 -
user User @relation(fields: [userId], references: [id])
186 -
187 -
@@map("reminders")
188 -
}
189 178
190 179
model SleepRecord {
191 180
id Int @id @default(autoincrement())
192 181
average Float
193 182
date DateTime @db.Date
312 301
THREE_TIMES_DAILY
313 302
WEEKLY
314 303
BIWEEKLY
315 304
MONTHLY
316 305
}