Skip to content

Commit b2d4367

Browse files
Add new schema to maintain notes version history, and apply migrations
1 parent 39a45b5 commit b2d4367

File tree

2 files changed

+68
-14
lines changed

2 files changed

+68
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- AlterTable
2+
ALTER TABLE "Collaborator" ADD COLUMN "todoHistoryId" TEXT;
3+
4+
-- AlterTable
5+
ALTER TABLE "Image" ADD COLUMN "todoHistoryId" TEXT;
6+
7+
-- CreateTable
8+
CREATE TABLE "TodoHistory" (
9+
"id" TEXT NOT NULL,
10+
"todoId" TEXT NOT NULL,
11+
"title" TEXT,
12+
"description" TEXT,
13+
"done" BOOLEAN,
14+
"todoColor" TEXT,
15+
"lastModifiedBy" TEXT NOT NULL,
16+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
17+
"userId" TEXT,
18+
19+
CONSTRAINT "TodoHistory_pkey" PRIMARY KEY ("id")
20+
);
21+
22+
-- CreateIndex
23+
CREATE INDEX "TodoHistory_todoId_idx" ON "TodoHistory"("todoId");
24+
25+
-- AddForeignKey
26+
ALTER TABLE "TodoHistory" ADD CONSTRAINT "TodoHistory_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
27+
28+
-- AddForeignKey
29+
ALTER TABLE "TodoHistory" ADD CONSTRAINT "TodoHistory_todoId_fkey" FOREIGN KEY ("todoId") REFERENCES "Todo"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
30+
31+
-- AddForeignKey
32+
ALTER TABLE "Collaborator" ADD CONSTRAINT "Collaborator_todoHistoryId_fkey" FOREIGN KEY ("todoHistoryId") REFERENCES "TodoHistory"("id") ON DELETE SET NULL ON UPDATE CASCADE;

prisma/schema.prisma

+36-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ model User {
2424
updatedAt DateTime @default(now()) @updatedAt
2525
todos Todo[]
2626
collaborators Collaborator[]
27+
TodoHistory TodoHistory[]
2728
}
2829

2930
model Todo {
@@ -39,26 +40,47 @@ model Todo {
3940
images Image[] // Relation to the Image model
4041
collaborators Collaborator[]
4142
lastModifiedBy String @default("")
43+
TodoHistory TodoHistory[]
44+
}
45+
46+
model TodoHistory {
47+
id String @id @default(uuid())
48+
todoId String
49+
title String?
50+
description String?
51+
done Boolean?
52+
todoColor String?
53+
lastModifiedBy String
54+
createdAt DateTime @default(now())
55+
collaborators Collaborator[]
56+
userId String?
57+
user User? @relation(fields: [userId], references: [id])
58+
Todo Todo @relation(fields: [todoId], references: [id])
59+
60+
@@index([todoId])
4261
}
4362

4463
model Image {
45-
id String @id @default(cuid())
46-
url String
47-
todo Todo @relation(fields: [todoId], references: [id], onDelete: Cascade)
48-
todoId String
49-
createdAt DateTime @default(now())
50-
updatedAt DateTime @default(now()) @updatedAt
64+
id String @id @default(cuid())
65+
url String
66+
todo Todo @relation(fields: [todoId], references: [id], onDelete: Cascade)
67+
todoId String
68+
createdAt DateTime @default(now())
69+
updatedAt DateTime @default(now()) @updatedAt
70+
todoHistoryId String?
5171
}
5272

5373
model Collaborator {
54-
id String @id @default(cuid())
55-
user User @relation(fields: [userId], references: [id])
56-
userId String
57-
todo Todo @relation(fields: [todoId], references: [id], onDelete: Cascade)
58-
todoId String
59-
isOwner Boolean @default(false)
60-
createdAt DateTime @default(now())
61-
updatedAt DateTime @default(now()) @updatedAt
74+
id String @id @default(cuid())
75+
user User @relation(fields: [userId], references: [id])
76+
userId String
77+
todo Todo @relation(fields: [todoId], references: [id], onDelete: Cascade)
78+
todoId String
79+
isOwner Boolean @default(false)
80+
createdAt DateTime @default(now())
81+
updatedAt DateTime @default(now()) @updatedAt
82+
TodoHistory TodoHistory? @relation(fields: [todoHistoryId], references: [id])
83+
todoHistoryId String?
6284
6385
@@unique([userId, todoId])
6486
}

0 commit comments

Comments
 (0)