176
prisma/schema.prisma
Normal file
176
prisma/schema.prisma
Normal file
@@ -0,0 +1,176 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
}
|
||||
|
||||
enum LedgerType {
|
||||
CREDIT_DONATION
|
||||
DEBIT_SPEND
|
||||
DEBIT_RAFFLE
|
||||
ADJUSTMENT
|
||||
}
|
||||
|
||||
enum UserRole {
|
||||
USER
|
||||
ADMIN
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
email String @unique
|
||||
emailVerified DateTime?
|
||||
name String?
|
||||
image String?
|
||||
passwordHash String?
|
||||
role UserRole @default(USER)
|
||||
|
||||
accounts Account[]
|
||||
sessions Session[]
|
||||
|
||||
wallet Wallet?
|
||||
ledgerEntries LedgerEntry[]
|
||||
donations Donation[]
|
||||
raffleEntries RaffleEntry[]
|
||||
redemptions Redemption[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model Account {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
type String
|
||||
provider String
|
||||
providerAccountId String
|
||||
refresh_token String? @db.Text
|
||||
access_token String? @db.Text
|
||||
expires_at Int?
|
||||
token_type String?
|
||||
scope String?
|
||||
id_token String? @db.Text
|
||||
session_state String?
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([provider, providerAccountId])
|
||||
}
|
||||
|
||||
model Session {
|
||||
id String @id @default(cuid())
|
||||
sessionToken String @unique
|
||||
userId String
|
||||
expires DateTime
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model VerificationToken {
|
||||
identifier String
|
||||
token String @unique
|
||||
expires DateTime
|
||||
|
||||
@@unique([identifier, token])
|
||||
}
|
||||
|
||||
model Wallet {
|
||||
id String @id @default(cuid())
|
||||
userId String @unique
|
||||
balanceCredits Int @default(0)
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model LedgerEntry {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
delta Int
|
||||
type LedgerType
|
||||
memo String?
|
||||
|
||||
donationId String? @unique
|
||||
donation Donation? @relation(fields: [donationId], references: [id])
|
||||
redemptionId String? @unique
|
||||
redemption Redemption? @relation(fields: [redemptionId], references: [id])
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId])
|
||||
}
|
||||
|
||||
model Donation {
|
||||
id String @id @default(cuid())
|
||||
stripePaymentIntentId String @unique
|
||||
userId String
|
||||
amountUsdCents Int
|
||||
creditsAwarded Int
|
||||
currency String @default("usd")
|
||||
status String @default("succeeded")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
ledgerEntry LedgerEntry?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([userId])
|
||||
}
|
||||
|
||||
model PrizeSku {
|
||||
id String @id @default(cuid())
|
||||
slug String @unique
|
||||
title String
|
||||
description String @db.Text
|
||||
costCredits Int
|
||||
stockHint String?
|
||||
|
||||
redemptions Redemption[]
|
||||
}
|
||||
|
||||
model Redemption {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
prizeSkuId String
|
||||
creditsSpent Int
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
prizeSku PrizeSku @relation(fields: [prizeSkuId], references: [id], onDelete: Cascade)
|
||||
ledgerEntry LedgerEntry?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([userId])
|
||||
}
|
||||
|
||||
model Raffle {
|
||||
id String @id @default(cuid())
|
||||
slug String @unique
|
||||
title String
|
||||
description String @db.Text
|
||||
ticketCostCredits Int
|
||||
endsAt DateTime?
|
||||
|
||||
entries RaffleEntry[]
|
||||
}
|
||||
|
||||
model RaffleEntry {
|
||||
id String @id @default(cuid())
|
||||
raffleId String
|
||||
userId String
|
||||
tickets Int @default(1)
|
||||
creditsSpent Int
|
||||
|
||||
raffle Raffle @relation(fields: [raffleId], references: [id], onDelete: Cascade)
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([raffleId])
|
||||
@@index([userId])
|
||||
}
|
||||
Reference in New Issue
Block a user