Skip to content

Commit

Permalink
Use profile as foreign key
Browse files Browse the repository at this point in the history
  • Loading branch information
wxh06 committed Aug 25, 2023
1 parent 5bb79c2 commit e3f3f15
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 11 additions & 0 deletions prisma/migrations/20230825014821_profile_foreign_key/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- DropForeignKey
ALTER TABLE "Activity" DROP CONSTRAINT "Activity_userId_fkey";

-- DropForeignKey
ALTER TABLE "Paste" DROP CONSTRAINT "Paste_userId_fkey";

-- AddForeignKey
ALTER TABLE "Activity" ADD CONSTRAINT "Activity_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Profile"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Paste" ADD CONSTRAINT "Paste_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Profile"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;
14 changes: 7 additions & 7 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ model User {
profile Profile?
snapshots Snapshot[]
replies Reply[]
pastes Paste[]
judgements Judgement[]
discussionTakedowns DiscussionTakedown[]
replyTakedowns ReplyTakedown[]
activities Activity[]
}

enum Color {
Expand All @@ -37,8 +35,8 @@ enum Color {
}

model Profile {
user User @relation(fields: [uid], references: [id])
uid Int @id
user User @relation(fields: [uid], references: [id])
uid Int @id
name String
slogan String?
badge String?
Expand All @@ -48,7 +46,9 @@ model Profile {
ccfLevel Int
background String
isRoot Boolean?
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt
activities Activity[]
paste Paste[]
}

model Discussion {
Expand Down Expand Up @@ -110,15 +110,15 @@ model Activity {
id Int @id
type Int
time DateTime @db.Timestamp(0)
user User @relation(fields: [userId], references: [id])
user Profile @relation(fields: [userId], references: [uid])
userId Int
content String
}

model Paste {
id String @id @db.Char(8)
time DateTime @db.Timestamp(0)
user User @relation(fields: [userId], references: [id])
user Profile @relation(fields: [userId], references: [uid])
userId Int
snapshots PasteSnapshot[]
Expand Down

0 comments on commit e3f3f15

Please sign in to comment.