|
| 1 | +generator client { |
| 2 | + provider = "prisma-client-js" |
| 3 | +} |
| 4 | + |
1 | 5 | datasource db { |
2 | 6 | provider = "postgresql" |
3 | 7 | url = env("DATABASE_URL") |
4 | 8 | } |
5 | 9 |
|
6 | | -generator client { |
7 | | - provider = "prisma-client-js" |
| 10 | +model User { |
| 11 | + id String @id @default(cuid()) |
| 12 | + name String |
| 13 | + email String @unique |
| 14 | + avatarUrl String? |
| 15 | + role Role @default(USER) |
| 16 | + createdAt DateTime @default(now()) |
| 17 | + updatedAt DateTime @updatedAt |
| 18 | +
|
| 19 | + accounts Account[] |
| 20 | + posts PostAuthor[] // posts authored (many-to-many) |
| 21 | + likes Like[] |
| 22 | + comments Comment[] |
| 23 | + reports Report[] |
| 24 | + followers Follow[] @relation("UserFollowers") |
| 25 | + following Follow[] @relation("UserFollowing") |
| 26 | + leaderboard LeaderboardSnapshot[] |
| 27 | +} |
| 28 | + |
| 29 | +model Account { |
| 30 | + id String @id @default(cuid()) |
| 31 | + userId String |
| 32 | + provider String |
| 33 | + providerAccountId String |
| 34 | + accessToken String? |
| 35 | + refreshToken String? |
| 36 | + expiresAt Int? |
| 37 | +
|
| 38 | + user User @relation(fields: [userId], references: [id]) |
| 39 | +
|
| 40 | + @@unique([provider, providerAccountId]) |
| 41 | +} |
| 42 | + |
| 43 | +model Post { |
| 44 | + id String @id @default(cuid()) |
| 45 | + title String |
| 46 | + description String |
| 47 | + previewUrl String? |
| 48 | + createdAt DateTime @default(now()) |
| 49 | + updatedAt DateTime @updatedAt |
| 50 | +
|
| 51 | + authors PostAuthor[] |
| 52 | + likes Like[] |
| 53 | + comments Comment[] |
| 54 | + reports Report[] |
| 55 | + leaderboard LeaderboardSnapshot[] |
| 56 | +} |
| 57 | + |
| 58 | +model PostAuthor { |
| 59 | + id String @id @default(cuid()) |
| 60 | + userId String |
| 61 | + postId String |
| 62 | +
|
| 63 | + user User @relation(fields: [userId], references: [id]) |
| 64 | + post Post @relation(fields: [postId], references: [id]) |
| 65 | +
|
| 66 | + @@unique([userId, postId]) |
| 67 | +} |
| 68 | + |
| 69 | +model Like { |
| 70 | + id String @id @default(cuid()) |
| 71 | + userId String |
| 72 | + postId String |
| 73 | + createdAt DateTime @default(now()) |
| 74 | +
|
| 75 | + user User @relation(fields: [userId], references: [id]) |
| 76 | + post Post @relation(fields: [postId], references: [id]) |
| 77 | +
|
| 78 | + @@unique([userId, postId]) |
| 79 | +} |
| 80 | + |
| 81 | +model Comment { |
| 82 | + id String @id @default(cuid()) |
| 83 | + userId String |
| 84 | + postId String |
| 85 | + content String |
| 86 | + createdAt DateTime @default(now()) |
| 87 | + updatedAt DateTime @updatedAt |
| 88 | +
|
| 89 | + user User @relation(fields: [userId], references: [id]) |
| 90 | + post Post @relation(fields: [postId], references: [id]) |
| 91 | +} |
| 92 | + |
| 93 | +model Report { |
| 94 | + id String @id @default(cuid()) |
| 95 | + userId String |
| 96 | + postId String |
| 97 | + reason String |
| 98 | + createdAt DateTime @default(now()) |
| 99 | +
|
| 100 | + user User @relation(fields: [userId], references: [id]) |
| 101 | + post Post @relation(fields: [postId], references: [id]) |
| 102 | +} |
| 103 | + |
| 104 | +model Follow { |
| 105 | + id String @id @default(cuid()) |
| 106 | + followerId String |
| 107 | + followingId String |
| 108 | + createdAt DateTime @default(now()) |
| 109 | +
|
| 110 | + follower User @relation("UserFollowers", fields: [followerId], references: [id]) |
| 111 | + following User @relation("UserFollowing", fields: [followingId], references: [id]) |
| 112 | +
|
| 113 | + @@unique([followerId, followingId]) |
| 114 | +} |
| 115 | + |
| 116 | +model LeaderboardSnapshot { |
| 117 | + id String @id @default(cuid()) |
| 118 | + month String // e.g., "2025-09" |
| 119 | + userId String |
| 120 | + postId String? |
| 121 | + score Int |
| 122 | + rank Int |
| 123 | + createdAt DateTime @default(now()) |
| 124 | +
|
| 125 | + user User @relation(fields: [userId], references: [id]) |
| 126 | + post Post? @relation(fields: [postId], references: [id]) |
| 127 | +} |
| 128 | + |
| 129 | +enum Role { |
| 130 | + USER |
| 131 | + MODERATOR |
8 | 132 | } |
0 commit comments