stacker.news/prisma/schema.prisma

356 lines
10 KiB
Plaintext

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
name String? @unique @db.Citext
email String? @unique
emailVerified DateTime? @map(name: "email_verified")
image String?
items Item[] @relation("UserItems")
fwdItems Item[] @relation("FwdItem")
mentions Mention[]
messages Message[]
actions ItemAct[]
invoices Invoice[]
withdrawls Withdrawl[]
invites Invite[] @relation(name: "Invites")
invite Invite? @relation(fields: [inviteId], references: [id])
inviteId String?
bio Item? @relation(fields: [bioId], references: [id])
bioId Int?
msats Int @default(0)
stackedMsats Int @default(0)
freeComments Int @default(5)
freePosts Int @default(2)
checkedNotesAt DateTime?
tipDefault Int @default(10)
pubkey String? @unique
trust Float @default(0)
upvoteTrust Float @default(0)
lastSeenAt DateTime?
lastCheckedJobs DateTime?
photoId Int?
photo Upload? @relation(fields: [photoId], references: [id])
upvotePopover Boolean @default(false)
tipPopover Boolean @default(false)
// notification settings
noteItemSats Boolean @default(true)
noteEarning Boolean @default(true)
noteAllDescendants Boolean @default(true)
noteMentions Boolean @default(true)
noteDeposits Boolean @default(true)
noteInvites Boolean @default(true)
noteJobIndicator Boolean @default(true)
Earn Earn[]
Upload Upload[] @relation(name: "Uploads")
@@index([createdAt])
@@index([inviteId])
@@map(name: "users")
}
model Upload {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
type String
size Int
width Int?
height Int?
item Item? @relation(fields: [itemId], references: [id])
itemId Int?
user User @relation(name: "Uploads", fields: [userId], references: [id])
userId Int
User User[]
@@index([createdAt])
@@index([itemId])
@@index([userId])
}
model Earn {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
msats Int
user User @relation(fields: [userId], references: [id])
userId Int
@@index([createdAt])
@@index([userId])
}
model LnAuth {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
k1 String @unique
pubkey String?
}
model LnWith {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
k1 String @unique
userId Int
withdrawalId Int?
}
model Invite {
id String @id @default(cuid())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
user User @relation(name: "Invites", fields: [userId], references: [id])
userId Int
gift Int?
limit Int?
revoked Boolean @default(false)
invitees User[]
@@index([userId])
@@index([createdAt])
}
model Message {
id Int @id @default(autoincrement())
text String
user User @relation(fields: [userId], references: [id])
userId Int
}
enum Status {
ACTIVE
STOPPED
NOSATS
}
model Item {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
title String?
text String?
url String?
user User @relation("UserItems", fields: [userId], references: [id])
userId Int
fwdUser User? @relation(name: "FwdItem", fields: [fwdUserId], references: [id])
fwdUserId Int?
parent Item? @relation("ParentChildren", fields: [parentId], references: [id])
parentId Int?
children Item[] @relation("ParentChildren")
actions ItemAct[]
mentions Mention[]
path Unsupported("LTREE")?
pin Pin? @relation(fields: [pinId], references: [id])
pinId Int?
weightedVotes Float @default(0)
boost Int @default(0)
// if sub is null, this is the main sub
sub Sub? @relation(fields: [subName], references: [name])
subName String? @db.Citext
// fields exclusively for job post types right now
minSalary Int?
maxSalary Int?
maxBid Int?
status Status @default(ACTIVE)
statusUpdatedAt DateTime?
location String?
company String?
latitude Float?
longitude Float?
remote Boolean?
User User[]
Upload Upload[]
@@index([createdAt])
@@index([userId])
@@index([parentId])
@@index([status])
@@index([maxBid])
@@index([statusUpdatedAt])
@@index([subName])
@@index([pinId])
@@index([path])
}
enum PostType {
LINK
DISCUSSION
JOB
}
enum RankingType {
WOT
RECENT
AUCTION
}
model Sub {
name String @id @db.Citext
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
postTypes PostType[]
rankingType RankingType
baseCost Int @default(1)
desc String?
Item Item[]
}
// the active pin is the latest one when it's a recurring cron
model Pin {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
cron String?
timezone String?
position Int
Item Item[]
}
enum ItemActType {
VOTE
BOOST
TIP
STREAM
}
model ItemAct {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
sats Int
act ItemActType
item Item @relation(fields: [itemId], references: [id])
itemId Int
user User @relation(fields: [userId], references: [id])
userId Int
@@index([itemId])
@@index([userId])
@@index([act])
@@index([createdAt])
}
model Mention {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
item Item @relation(fields: [itemId], references: [id])
itemId Int
user User @relation(fields: [userId], references: [id])
userId Int
@@unique([itemId, userId])
@@index([createdAt])
@@index([itemId])
@@index([userId])
}
model Invoice {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
user User @relation(fields: [userId], references: [id])
userId Int
hash String @unique
bolt11 String
expiresAt DateTime
confirmedAt DateTime?
msatsRequested Int
msatsReceived Int?
cancelled Boolean @default(false)
@@index([createdAt])
@@index([userId])
}
enum WithdrawlStatus {
CONFIRMED
INSUFFICIENT_BALANCE
INVALID_PAYMENT
PATHFINDING_TIMEOUT
ROUTE_NOT_FOUND
UNKNOWN_FAILURE
}
model Withdrawl {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
user User @relation(fields: [userId], references: [id])
userId Int
hash String
bolt11 String
msatsPaying Int
msatsPaid Int?
msatsFeePaying Int
msatsFeePaid Int?
status WithdrawlStatus?
@@index([createdAt])
@@index([userId])
}
model Account {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
compoundId String @unique @map(name: "compound_id")
userId Int @map(name: "user_id")
providerType String @map(name: "provider_type")
providerId String @map(name: "provider_id")
providerAccountId String @map(name: "provider_account_id")
refreshToken String? @map(name: "refresh_token")
accessToken String? @map(name: "access_token")
accessTokenExpires DateTime? @map(name: "access_token_expires")
@@index([providerAccountId])
@@index([providerId])
@@index([userId])
@@map(name: "accounts")
}
model Session {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
userId Int @map(name: "user_id")
expires DateTime
sessionToken String @unique @map(name: "session_token")
accessToken String @unique @map(name: "access_token")
@@map(name: "sessions")
}
model VerificationRequest {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
identifier String
token String @unique
expires DateTime
@@map(name: "verification_requests")
}