stacker.news/prisma/schema.prisma
ekzyis d89a4a429a
Wallet v2 (#2169)
* Migrate vault entries to new schema (#2092)

* Migrate existing vault entries to new schema

* Read+write new vault schema

* Drop VaultEntry table

* Refactor vaultPrismaFragments

* Remove wrong comment

* Remove TODO

* Fix possible race condition on update of vault key

* Remove lib/object.js

* Wallet schema v2 (#2146)

* Add wallet-v2 TODOs

* Update checkWallet

* Wallet list

* Delete almost all wallet v1 code

and add some code for wallet protocol forms

* Define protocol display name in JSON

* Show form per protocol

* Increase max-height of image in form

* Add JSdoc for protocols, form validation

* Use wallet cards again

My wallet list was quite ugly and I couldn't look at it anymore.

* Refactor hooks in wallet provider

* Fix PasswordInput not used

* Read encrypted wallets

* Decrypt wallets

* useWalletQuery now returns decrypted wallets
* Refactor useIndexedDB because its only purpose will be to store the key, so no need for pagination code etc.
* There is still a bug: if the wallet is not decrypted on first render, the form will not see the decrypted value. See TODO.

* Rename protocolJson to protocol

it no longer uses a JSON file

* Fix form not updated with decrypted API key

* Fix wallet template forms

* Fix optional shown as hint

* Rename to mapUserWalletResolveTypes

* Save LNbits send and recv

TODO:

* implement resolvers for other protocols
* fix double update required for trigger?
* add missing validation on server
* add missing network tests
* don't import from wallets/client on server

* Move definitions to lib/wallets.json and lib/protocols

* Fix ProtocolWallet.updated_at not updated by trigger

* Move wallet fragments into wallets/client/fragments/

* move invoice fragments to fragments/invoice.js
* remove some unused fragments that I don't think I also will not use
* move fragments that will be generated in own file

* Move wallet resolvers into wallets/server/resolvers

* Fix missing authorization check on wallet update

* Run all shared code in generic wallet update function

* Fix 'encrypt' flag not set for blink send currency

* Add mutations for all protocols

* Fix macaroon validation

* Fix CLN socket value not set

* Add server-side schema validation

* Fix JSDoc typedef for protocols

* Don't put JSDoc into separate file

* Create test invoices on save

* Also move type resolvers into wallets/server/resolvers

* Fix unconfigured protocols of UserWallet not found

* Fix Blink API key in wallet seed

* Test send payment on save (except LNC)

This does not include LNC because LNC cannot be saved yet

* Check if window.webln is defined on save

* Create new wallets from templates

* Separate protocols in wallets/lib into individual files

* Use justify-content-start for protocol tabs

and larger margin at the top

* Add LNC to client protocols

* Only return wallets from useWallets

* Query decrypted wallets

* Payments with new wallets

* More wallet logos

* Fix TypeError in useIndexedDB

* Add protocol attach docs

* Fix undefined useWalletRecvPrompt import

* Remove outdated TODOs

* First successful zap to new wallets

* Fix walletLogger imports

* Fix sequences

* the sequences for InvoiceForward and DirectPayment were still starting at 1
* when using setval() with two arguments, nextval() will return the second argument+1 (see https://www.postgresql.org/docs/current/functions-sequence.html)

* Rename ProtocolWallet columns

* Remove more outdated TODOs

* Update wallet indicator

* Fix page reset on route change

* Refactor __typename checks into functions

* Refactor protocol selection into own hook

* Add button to detach protocol

* Refetch wallet on save and detach

* Refetch wallets on change

* Always show all templates

* Refactor WalletLink component

* Also put wallet into forms context

* Remove outdated TODOs

* Use useMemo in wallets hooks

* Passphrase modals

* prompt for password if decryption failed
* add button to reveal passphrase on wallet page

TODO:
* remove button if passphrase was revealed or imported
* encrypt wallets with new key on passphrase reveal

* Fix protocol missing as callback dependency

* Encrypt wallets with new key on passphrase export

* Update 'unlock wallets' text

* Rename wallet mutation hooks

* Remove 'removeWallet' mutation

Wallets are automatically deleted when all protocols are deleted

* Passphrase reset

* Use 110px as minimum width for bip39 words

longest bip39 words are 8 characters and they fit into 103px so I rounded up to 110px.

* Also disable passphrase export on save

* Wallet settings

* Fix wallet receive prompt

* Remove unused parameters from postgres function

* Rename UserWallet to Wallet, ProtocolWallet to WalletProtocol

* Use danger variant for button to show passphrase

* Fix inconsistent imports and exports

* Remove outdated TODOs

* wallet logs

* Remove outdated comment

* Make sure wallets are used in priority order

* Separate wallets from templates in reducer

* Fix missing useCallback dependencies

* Refactor with useWalletLogger hook

* Move enabled to WalletProtocol

* Add checkbox to enable/disable protocol

* Fix migration with prod db dump

* Parse Coinos relay URLs

* Skip network tests if only enabled changed

* Allow IndexedDB calls without session

* Add code to migrate old CryptoKey

* first try to use existing CryptoKey before generating a new one
* bump IDB version to delete old object stores and create new ones
* return IDB callbacks with useMemo
* don't delete old IDB right away, wait until next release

* Fix ghost import error

*Sometimes*, I get import errors because it tries to resolve @/wallets/server to wallets/server.js instead of wallets/server/index.js.

For the files in wallets/server, it kind of makes sense because it's a circular import.

But I don't know why the files in worker/ have this problem.

Interestingly, it only seems to happen with walletLogger imports, so I guess its related to its import chain.

Anyway, this commit should make sure this never happens again ...

* Skip wallets queries if not logged in

* Split CUSTOM wallet into NWC and LN_ADDR

* Migrate local wallets

* Link to /wallets/:id/receive if send not supported

* Hide separator if there are no configured wallets

* Save LNC

* Add one-liner to attach LNC

* Update wallet priorities via DnD

* Wallet logs are part of protocol resolvers

* Fix logging to deleted protocol

* Fix trying to fetch logs for template

* also change type to Int so GraphQL layer can catch trying to fetch string IDs as is the case for templates

* Fix embedded flag for wallets logs not set

* Remove TODO

* Decrease max-height for embedded wallet logs on big screens

* Fix missing refetch on wallet priority update

* Set priorities of all wallets in one tx

* Fix nested state update

* Add DragIcon

* DnD mobile support and refactor

* Add CancelButton to wallet settings

* Remount form if path changes

This fixes the following warning in the console:

"""
Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component.
"""

* Support string and object for wallet.image JSON

* Append domain to lightning address inputs

* Remove outdated TODOs

* Add template IDs to wallet JSON

* Fix missing callback dependency

* Implement lightning address save in receive prompt

* Update TODOs

* Fix missing check for enabled

* Pay QR codes with WebLN as anon

* Add logo for NWC

* Fix trying to save logs for template

* Add template logs

* Fix inconsistent margin

* Always throw on missing key

* Remove misleading comment

Wallets are returned even if decryption fails so we can show the unlock page if a wallet is stored as encrypted in the context.

Maybe I should rethink this.

* Check for existing wallets on local wallet migration

* Fix local wallet migration causing duplicates

* Fix protocol reattached on detach due to migration

* Fix form not centered

* Fix ZEUS lightning address domain

* Add placeholder, help, hints etc. to wallet form inputs

* Fix wallet badges not updated

* Remove unused declared variables

* Rename to ATTACH_PAGE

* Fix 500 error if no amount was given to LNURLp endpoint

* Tag log messages with wallet name

* Only skip network tests if we're disabling the wallet

* Rename var to networkTests

* Continue to store key hash in IndexedDB

* Rethink wallet state management

If decryption failed, the function to decrypt the wallets didn't throw but simply returned wallets that were still encrypted.

This was bad because it meant we could not rely on the wallets in the state being decrypted, even though this was the original idea behind the query hooks: hide the details of encryption and decryption inside them.

Because of this, we had to check if the wallets were still encrypted before we ran the wallet migration since we want to check if a protocol already exists.

This commit fixes this by making encryption and decryption always throw (and catching the errors), as well as returning a ready state from hooks. A hook might not be ready because it still needs to load something (in the case of the crypto hooks, it's loading the key from IndexedDB). Callers check that ready state before they call the function returned by the hook.

So now, the wallet migration hook can itself simply check if the hook to encrypt wallets is ready and if the wallets are no longer loading to let callers know if it itself is ready.

Since we also relied on wallets stored as encrypted in the context to show the unlock page, this was also changed by comparing the local and remote key hash.

* Add empty line

* Save new key hash during wallet reset

* Only receive protocol upserts require networkTests param

* Compare key hashes on server on each save

* Delete old code

* Fix card shows attach instead of configure

* Fix empty wallets created during migration

The old schema can contain '' instead of NULL in the columns of wallets for receiving.

* Update reset passphrase text

* Wrap passphrase reset in try/catch

* Fix migrate called multiple times

* Update key hash on migration if not set

* Fetch local wallets in migrate

* Fix missing await on setKey

* Let first device set key hash

* Fix indicator not shown if wallets locked

* Check if IndexedDB is available

* Fix inconsistent WebLN error message

* Disable WebLN if not available

* Remove outdated TODO

* Cursor-based pagination for wallet logs

* Fix log message x-overflow

* Add context to wallet logs

* Wrap errors are warnings in logs

* Rename wallet v2 migrations

* Update wallet status during logging

* Fix wallet logs loading state

The loading state would go from false -> true -> false because it's false when the lazy query wasn't called yet.

* Add wallet search

* Add Alby Go wallet

* Revert "Add Alby Go wallet"

This reverts commit 926c70638f1673756480c848237e52d5889dc037.

* Fix wallet logs sent by client don't update protocol status

* Fix mutation name

* put drag icon on opposite corner

* Add wallets/README.md

* Fix inconsistent case in wallets/README.md

* Fix autoprefixer warning about mixed support

This warning was in the app logs:

app     | Warning
app     |
app     | (31:3) autoprefixer: end value has mixed support, consider using flex-end instead
app     |
app     | Import trace for requested module:
app     | ./styles/wallet.module.css
app     | ./wallets/client/hooks/prompt.js
app     | ./wallets/client/hooks/index.js
app     | ./wallets/client/context/hooks.js
app     | ./wallets/client/context/provider.js
app     | ./wallets/client/context/index.js

* fix effect of wallet indicators on logo

* Fix deleting wallet template logs

* Use name as primary key of WalletTemplate

* Fix wallet_clear_vault trigger not mentioned in README

* Fix wallet receive prompt

Also remove no longer needed templateId from wallets.json and helper functions

* Use findUnique since name is now primary key

* Merge Alby wallets into one

* Remove unused name parameter from WalletsForm component

* Fix number check to decide if wallet or template

* Update wallet encryption on click, not as effect

* add cashu.me and lightning address logos

* add images

* Use recommended typeof to check if IDB available

* Also check if IDB available on delete

* Use constraint triggers

* Add indices on columns used for joins

* Fix inconsistent CLEAR OR REPLACE TRIGGER

* Attach wallet_check_support trigger to WalletProtocol table

* Update wallets/README.md

* Remove debugging code

* Refactor reducer: replace page with status

* Show 'wallets unavailable' if device does not support IndexedDB

* Remove duplicate ELSIF condition

* Fix hasSendWallet

The useSendWallets hook was not checking if the returned send wallets are enabled.

Since the components that used that hook only need to know if there is a send wallet, I replaced the useSendWallets hook with a useHasSendWallet hook.

* Add Cash App wallet

* fix changes loglevel enum

* Fix key init race condition in strict mode if no key exists yet

* Formatting

* Fix key init race condition via transactions in readwrite mode

* Replace Promise.withResolvers with regular promises

* replace generic spinner with our usual

---------

Co-authored-by: k00b <k00b@stacker.news>
2025-07-15 16:36:43 -05:00

1460 lines
54 KiB
Plaintext

generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Snl {
id Int @id @default(autoincrement())
live Boolean @default(false)
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
name String? @unique(map: "users.name_unique") @db.Citext
email String? @unique(map: "users.email_unique")
emailVerified DateTime? @map("email_verified")
emailHash String? @unique(map: "users.email_hash_unique")
image String?
msats BigInt @default(0)
freeComments Int @default(5)
freePosts Int @default(2)
checkedNotesAt DateTime?
foundNotesAt DateTime?
pubkey String? @unique(map: "users.pubkey_unique")
apiKeyHash String? @unique(map: "users.apikeyhash_unique") @db.Char(64)
apiKeyEnabled Boolean @default(false)
tipDefault Int @default(100)
tipRandomMin Int?
tipRandomMax Int?
bioId Int?
inviteId String?
tipPopover Boolean @default(false)
upvotePopover Boolean @default(false)
trust Float @default(0)
lastSeenAt DateTime?
stackedMsats BigInt @default(0)
stackedMcredits BigInt @default(0)
noteAllDescendants Boolean @default(true)
noteDeposits Boolean @default(true)
noteWithdrawals Boolean @default(true)
noteEarning Boolean @default(true)
noteInvites Boolean @default(true)
noteItemSats Boolean @default(true)
noteMentions Boolean @default(true)
noteItemMentions Boolean @default(true)
noteForwardedSats Boolean @default(true)
lastCheckedJobs DateTime?
noteJobIndicator Boolean @default(true)
photoId Int?
upvoteTrust Float @default(0)
hideInvoiceDesc Boolean @default(false)
wildWestMode Boolean @default(false)
satsFilter Int @default(10)
nsfwMode Boolean @default(false)
fiatCurrency String @default("USD")
withdrawMaxFeeDefault Int @default(10)
autoDropBolt11s Boolean @default(false)
hideFromTopUsers Boolean @default(false)
turboTipping Boolean @default(false)
zapUndos Int?
imgproxyOnly Boolean @default(false)
showImagesAndVideos Boolean @default(true)
hideWalletBalance Boolean @default(false)
disableFreebies Boolean?
referrerId Int?
nostrPubkey String?
greeterMode Boolean @default(false)
nostrAuthPubkey String? @unique(map: "users.nostrAuthPubkey_unique")
nostrCrossposting Boolean @default(false)
slashtagId String? @unique(map: "users.slashtagId_unique")
noteCowboyHat Boolean @default(true)
streak Int?
gunStreak Int?
horseStreak Int?
hasSendWallet Boolean @default(false)
hasRecvWallet Boolean @default(false)
subs String[]
hideCowboyHat Boolean @default(false)
Bookmarks Bookmark[]
Donation Donation[]
Earn Earn[]
invites Invite[] @relation("Invites")
invoices Invoice[]
items Item[] @relation("UserItems")
actions ItemAct[]
mentions Mention[]
messages Message[]
PushSubscriptions PushSubscription[]
ReferralAct ReferralAct[]
Streak Streak[]
ThreadSubscriptions ThreadSubscription[]
SubSubscriptions SubSubscription[]
Upload Upload[] @relation("Uploads")
nostrRelays UserNostrRelay[]
withdrawls Withdrawl[]
bio Item? @relation(fields: [bioId], references: [id])
invite Invite? @relation(fields: [inviteId], references: [id])
photo Upload? @relation(fields: [photoId], references: [id])
referrer User? @relation("referrals", fields: [referrerId], references: [id])
referrees User[] @relation("referrals")
Account Account[]
Session Session[]
itemForwards ItemForward[]
hideBookmarks Boolean @default(false)
hideGithub Boolean @default(true)
hideNostr Boolean @default(true)
hideTwitter Boolean @default(true)
noReferralLinks Boolean @default(false)
githubId String?
twitterId String?
followers UserSubscription[] @relation("follower")
followees UserSubscription[] @relation("followee")
hideWelcomeBanner Boolean @default(false)
hideWalletRecvPrompt Boolean @default(false)
diagnostics Boolean @default(false) @ignore
hideIsContributor Boolean @default(false)
lnAddr String?
autoWithdrawMaxFeePercent Float?
autoWithdrawThreshold Int?
autoWithdrawMaxFeeTotal Int?
mcredits BigInt @default(0)
receiveCreditsBelowSats Int @default(10)
sendCreditsBelowSats Int @default(10)
muters Mute[] @relation("muter")
muteds Mute[] @relation("muted")
ArcOut Arc[] @relation("fromUser")
ArcIn Arc[] @relation("toUser")
Sub Sub[]
SubAct SubAct[]
MuteSub MuteSub[]
wallets Wallet[]
TerritoryTransfers TerritoryTransfer[] @relation("TerritoryTransfer_oldUser")
TerritoryReceives TerritoryTransfer[] @relation("TerritoryTransfer_newUser")
AncestorReplies Reply[] @relation("AncestorReplyUser")
Replies Reply[]
walletLogs WalletLog[]
Reminder Reminder[]
PollBlindVote PollBlindVote[]
ItemUserAgg ItemUserAgg[]
oneDayReferrals OneDayReferral[] @relation("OneDayReferral_referrer")
oneDayReferrees OneDayReferral[] @relation("OneDayReferral_referrees")
vaultKeyHash String @default("")
showPassphrase Boolean @default(true)
walletsUpdatedAt DateTime?
proxyReceive Boolean @default(true)
DirectPaymentReceived DirectPayment[] @relation("DirectPaymentReceived")
DirectPaymentSent DirectPayment[] @relation("DirectPaymentSent")
UserSubTrust UserSubTrust[]
@@index([photoId])
@@index([createdAt], map: "users.created_at_index")
@@index([inviteId], map: "users.inviteId_index")
@@index([streak])
@@index([gunStreak])
@@index([horseStreak])
@@map("users")
}
enum OneDayReferralType {
REFERRAL
POST
COMMENT
PROFILE
TERRITORY
}
model OneDayReferral {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
referrerId Int
refereeId Int
referrer User @relation("OneDayReferral_referrer", fields: [referrerId], references: [id], onDelete: Cascade)
referee User @relation("OneDayReferral_referrees", fields: [refereeId], references: [id], onDelete: Cascade)
type OneDayReferralType
typeId String
landing Boolean @default(false)
@@index([createdAt])
@@index([referrerId])
@@index([refereeId])
@@index([type, typeId])
}
model UserSubTrust {
subName String @db.Citext
userId Int
zapPostTrust Float @default(0)
subZapPostTrust Float @default(0)
zapCommentTrust Float @default(0)
subZapCommentTrust Float @default(0)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
sub Sub @relation(fields: [subName], references: [name], onDelete: Cascade)
@@id([userId, subName])
}
model Vault {
id Int @id @default(autoincrement())
iv String @db.Text
value String @db.Text
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
walletSendNWC WalletSendNWC?
walletSendLNbits WalletSendLNbits?
walletSendPhoenixd WalletSendPhoenixd?
walletSendBlinkApiKey WalletSendBlink? @relation("blinkApiKeySend")
walletSendBlinkCurrency WalletSendBlink? @relation("blinkCurrencySend")
walletSendLNCPairingPhrase WalletSendLNC? @relation("lncPairingPhrase")
walletSendLNCLocalKey WalletSendLNC? @relation("lncLocalKey")
walletSendLNCRemoteKey WalletSendLNC? @relation("lncRemoteKey")
walletSendLNCServerHost WalletSendLNC? @relation("lncServerHost")
}
model WalletLog {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
protocolId Int?
protocol WalletProtocol? @relation(fields: [protocolId], references: [id], onDelete: Cascade)
level LogLevel
message String
invoiceId Int?
invoice Invoice? @relation(fields: [invoiceId], references: [id])
withdrawalId Int?
withdrawal Withdrawl? @relation(fields: [withdrawalId], references: [id])
context Json? @db.JsonB
@@index([userId, createdAt])
}
model Mute {
muterId Int
mutedId Int
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
muter User @relation("muter", fields: [muterId], references: [id], onDelete: Cascade)
muted User @relation("muted", fields: [mutedId], references: [id], onDelete: Cascade)
@@id([muterId, mutedId])
@@index([mutedId, muterId])
}
model Arc {
fromId Int
fromUser User @relation("fromUser", fields: [fromId], references: [id], onDelete: Cascade)
toId Int
toUser User @relation("toUser", fields: [toId], references: [id], onDelete: Cascade)
zapTrust Float
@@id([fromId, toId])
@@index([toId, fromId])
}
enum StreakType {
COWBOY_HAT
GUN
HORSE
}
model Streak {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
startedAt DateTime
endedAt DateTime?
userId Int
type StreakType @default(COWBOY_HAT)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([startedAt, userId, type])
@@index([userId], map: "Streak.userId_index")
@@index([type])
}
model NostrRelay {
addr String @id
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
users UserNostrRelay[]
}
model UserNostrRelay {
userId Int
nostrRelayAddr String
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
NostrRelay NostrRelay @relation(fields: [nostrRelayAddr], references: [addr], onDelete: Cascade)
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@id([userId, nostrRelayAddr])
}
model Donation {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
sats Int
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model ItemUpload {
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
itemId Int
uploadId Int
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
upload Upload @relation(fields: [uploadId], references: [id], onDelete: Cascade)
@@id([itemId, uploadId])
@@index([createdAt])
@@index([itemId])
@@index([uploadId])
}
model Upload {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
type String
size Int
width Int?
height Int?
userId Int
paid Boolean?
invoiceId Int?
invoiceActionState InvoiceActionState?
invoice Invoice? @relation(fields: [invoiceId], references: [id], onDelete: SetNull)
user User @relation("Uploads", fields: [userId], references: [id], onDelete: Cascade)
User User[]
ItemUpload ItemUpload[]
@@index([createdAt], map: "Upload.created_at_index")
@@index([userId], map: "Upload.userId_index")
@@index([invoiceId])
@@index([invoiceActionState])
}
model Earn {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
msats BigInt
userId Int
rank Int?
type EarnType?
typeId Int?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([createdAt], map: "Earn.created_at_index")
@@index([createdAt, userId], map: "Earn.created_at_userId_index")
@@index([userId], map: "Earn.userId_index")
}
model LnAuth {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
k1 String @unique(map: "LnAuth.k1_unique")
pubkey String?
}
model LnWith {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
k1 String @unique(map: "LnWith.k1_unique")
userId Int
withdrawalId Int?
}
model Invite {
id String @id @default(dbgenerated("encode(gen_random_bytes(16), 'hex'::text)"))
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
userId Int
gift Int?
limit Int?
giftedCount Int @default(0)
revoked Boolean @default(false)
user User @relation("Invites", fields: [userId], references: [id], onDelete: Cascade)
invitees User[]
description String?
@@index([createdAt], map: "Invite.created_at_index")
@@index([userId], map: "Invite.userId_index")
}
model Message {
id Int @id @default(autoincrement())
text String
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
/// This model contains an expression index which requires additional setup for migrations. Visit https://pris.ly/d/expression-indexes for more info.
model Item {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
title String?
text String?
url String?
userId Int
parentId Int?
path Unsupported("ltree")?
pinId Int?
latitude Float?
location String?
longitude Float?
maxBid Int?
maxSalary Int?
minSalary Int?
remote Boolean?
subName String? @db.Citext
statusUpdatedAt DateTime?
status Status @default(ACTIVE)
company String?
weightedVotes Float @default(0)
subWeightedVotes Float @default(0)
boost Int @default(0)
oldBoost Int @default(0)
pollCost Int?
paidImgLink Boolean @default(false)
commentMsats BigInt @default(0)
commentMcredits BigInt @default(0)
lastCommentAt DateTime?
lastZapAt DateTime?
ncomments Int @default(0)
nDirectComments Int @default(0)
msats BigInt @default(0)
mcredits BigInt @default(0)
cost Int @default(0)
weightedDownVotes Float @default(0)
subWeightedDownVotes Float @default(0)
bio Boolean @default(false)
freebie Boolean @default(false)
deletedAt DateTime?
otsFile Bytes?
otsHash String?
imgproxyUrls Json?
bounty Int?
noteId String? @unique(map: "Item.noteId_unique")
rootId Int?
bountyPaidTo Int[]
upvotes Int @default(0)
weightedComments Float @default(0)
Bookmark Bookmark[]
parent Item? @relation("ParentChildren", fields: [parentId], references: [id])
children Item[] @relation("ParentChildren")
pin Pin? @relation(fields: [pinId], references: [id])
root Item? @relation("RootDescendant", fields: [rootId], references: [id])
descendants Item[] @relation("RootDescendant")
sub Sub? @relation(fields: [subName], references: [name], onDelete: Cascade, onUpdate: Cascade)
user User @relation("UserItems", fields: [userId], references: [id], onDelete: Cascade)
itemActs ItemAct[]
mentions Mention[]
itemReferrers ItemMention[] @relation("referrer")
itemReferees ItemMention[] @relation("referee")
pollOptions PollOption[]
PollVote PollVote[]
threadSubscriptions ThreadSubscription[]
User User[]
itemForwards ItemForward[]
itemUploads ItemUpload[]
uploadId Int?
invoiceId Int?
invoiceActionState InvoiceActionState?
invoicePaidAt DateTime?
outlawed Boolean @default(false)
apiKey Boolean @default(false)
pollExpiresAt DateTime?
Ancestors Reply[] @relation("AncestorReplyItem")
Replies Reply[]
Reminder Reminder[]
invoice Invoice? @relation(fields: [invoiceId], references: [id], onDelete: SetNull)
PollBlindVote PollBlindVote[]
ItemUserAgg ItemUserAgg[]
AutoSocialPost AutoSocialPost[]
randPollOptions Boolean @default(false)
@@index([uploadId])
@@index([lastZapAt])
@@index([bio], map: "Item.bio_index")
@@index([createdAt], map: "Item.created_at_index")
@@index([freebie], map: "Item.freebie_index")
@@index([maxBid], map: "Item.maxBid_index")
@@index([parentId], map: "Item.parentId_index")
@@index([path], map: "Item.path_index", type: Gist)
@@index([path], map: "Item.path_index0", type: Gist)
@@index([pinId], map: "Item.pinId_index")
@@index([rootId], map: "Item.rootId_index")
@@index([statusUpdatedAt], map: "Item.statusUpdatedAt_index")
@@index([status], map: "Item.status_index")
@@index([subName], map: "Item.subName_index")
@@index([userId], map: "Item.userId_index")
@@index([weightedDownVotes], map: "Item.weightedDownVotes_index")
@@index([weightedVotes], map: "Item.weightedVotes_index")
@@index([invoiceId])
@@index([invoiceActionState])
@@index([cost])
@@index([url])
@@index([boost])
@@index([invoicePaidAt])
}
// we use this to denormalize a user's aggregated interactions (zaps) with an item
// we need to do this to safely modify the aggregates in a read committed transaction
// because we can't lock an aggregate query to guard a potentially conflicting update
// (e.g. sum("ItemAct".msats), but we can lock a row where we store the aggregate
// this is important because zaps do not update "weightedVotes" linearly
// see: https://stackoverflow.com/questions/61781595/postgres-read-commited-doesnt-re-read-updated-row?noredirect=1#comment109279507_61781595
// or: https://www.cybertec-postgresql.com/en/transaction-anomalies-with-select-for-update/
model ItemUserAgg {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
itemId Int
userId Int
zapSats BigInt @default(0)
downZapSats BigInt @default(0)
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([itemId, userId])
@@index([itemId])
@@index([userId])
@@index([createdAt])
}
// record auto social posts so we can avoid duplicates
model AutoSocialPost {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
itemId Int
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
@@index([itemId])
@@index([createdAt])
}
// this is a denomalized table that is used to make reply notifications
// more efficient ... it is populated by a trigger when replies are created
model Reply {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
ancestorId Int
ancestorUserId Int
itemId Int
userId Int
level Int
User User @relation(fields: [userId], references: [id])
Item Item @relation(fields: [itemId], references: [id])
AncestorUser User @relation("AncestorReplyUser", fields: [ancestorUserId], references: [id])
AncestorItem Item @relation("AncestorReplyItem", fields: [ancestorId], references: [id])
@@index([ancestorId])
@@index([ancestorUserId])
@@index([itemId])
@@index([userId])
@@index([level])
@@index([createdAt])
}
// TODO: make all Item's forward 100% of sats to the OP by default
// so that forwards aren't a special case everywhere
model ItemForward {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
itemId Int // The item from which sats are forwarded
userId Int // The recipient of the forwarded sats
pct Int // The percentage of sats from the item to forward to this user
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([itemId], map: "ItemForward.itemId_index")
@@index([userId], map: "ItemForward.userId_index")
@@index([createdAt], map: "ItemForward.createdAt_index")
}
model PollOption {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
itemId Int
option String
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
PollVote PollVote[]
@@index([itemId], map: "PollOption.itemId_index")
}
model PollVote {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
itemId Int
pollOptionId Int
invoiceId Int?
invoiceActionState InvoiceActionState?
invoice Invoice? @relation(fields: [invoiceId], references: [id], onDelete: SetNull)
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
pollOption PollOption @relation(fields: [pollOptionId], references: [id], onDelete: Cascade)
@@index([pollOptionId], map: "PollVote.pollOptionId_index")
@@index([invoiceId])
@@index([invoiceActionState])
}
model PollBlindVote {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
itemId Int
userId Int
invoiceId Int?
invoiceActionState InvoiceActionState?
invoice Invoice? @relation(fields: [invoiceId], references: [id], onDelete: SetNull)
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([itemId, userId], map: "PollBlindVote.itemId_userId_unique")
@@index([userId], map: "PollBlindVote.userId_index")
@@index([invoiceActionState])
}
enum BillingType {
MONTHLY
YEARLY
ONCE
}
enum RankingType {
WOT
RECENT
AUCTION
}
model Sub {
name String @id @db.Citext
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
userId Int
parentName String? @db.Citext
path Unsupported("ltree")?
postTypes PostType[]
rankingType RankingType
allowFreebies Boolean @default(true)
baseCost Int @default(1)
replyCost Int @default(1)
rewardsPct Int @default(30)
desc String?
status Status @default(ACTIVE)
statusUpdatedAt DateTime?
billingType BillingType
billingCost Int
billingAutoRenew Boolean @default(false)
billedLastAt DateTime @default(now())
billPaidUntil DateTime?
moderated Boolean @default(false)
moderatedCount Int @default(0)
nsfw Boolean @default(false)
parent Sub? @relation("ParentChildren", fields: [parentName], references: [name])
children Sub[] @relation("ParentChildren")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Item Item[]
SubAct SubAct[]
MuteSub MuteSub[]
SubSubscription SubSubscription[]
TerritoryTransfer TerritoryTransfer[]
UserSubTrust UserSubTrust[]
@@index([parentName])
@@index([createdAt])
@@index([userId])
@@index([statusUpdatedAt])
@@index([path], type: Gist)
}
model SubAct {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
userId Int
subName String @db.Citext
msats BigInt
type SubActType
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
sub Sub @relation(fields: [subName], references: [name], onDelete: Cascade, onUpdate: Cascade)
@@index([userId])
@@index([userId, type])
@@index([type])
@@index([createdAt])
@@index([createdAt, type])
@@index([userId, createdAt, type])
}
model MuteSub {
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
subName String @db.Citext
userId Int
sub Sub @relation(fields: [subName], references: [name], onDelete: Cascade, onUpdate: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@id([userId, subName])
@@index([subName])
@@index([createdAt])
}
model Pin {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
cron String?
timezone String?
position Int
Item Item[]
}
model ReferralAct {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
referrerId Int
itemActId Int
msats BigInt
itemAct ItemAct @relation(fields: [itemActId], references: [id], onDelete: Cascade)
referrer User @relation(fields: [referrerId], references: [id], onDelete: Cascade)
@@index([referrerId])
@@index([itemActId])
}
model ItemAct {
id Int @id(map: "Vote_pkey") @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
msats BigInt
act ItemActType
itemId Int
userId Int
invoiceId Int?
invoiceActionState InvoiceActionState?
invoice Invoice? @relation(fields: [invoiceId], references: [id], onDelete: SetNull)
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
ReferralAct ReferralAct[]
@@index([act], map: "ItemAct.act_index")
@@index([createdAt], map: "ItemAct.created_at_index")
@@index([createdAt, itemId, act], map: "ItemAct.created_at_itemId_act_index")
@@index([itemId, createdAt, act], map: "ItemAct.itemId_created_at_act_index")
@@index([itemId], map: "ItemAct.itemId_index")
@@index([itemId, userId, act], map: "ItemAct.itemId_userId_act_index")
@@index([userId, createdAt, act], map: "ItemAct.userId_created_at_act_index")
@@index([userId], map: "ItemAct.userId_index")
@@index([itemId], map: "Vote.itemId_index")
@@index([userId], map: "Vote.userId_index")
@@index([invoiceId])
@@index([invoiceActionState])
}
model Mention {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
itemId Int
userId Int
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([itemId, userId], map: "Mention.itemId_userId_unique")
@@index([createdAt], map: "Mention.created_at_index")
@@index([itemId], map: "Mention.itemId_index")
@@index([userId], map: "Mention.userId_index")
}
enum InvoiceActionType {
BUY_CREDITS
ITEM_CREATE
ITEM_UPDATE
ZAP
DOWN_ZAP
BOOST
DONATE
POLL_VOTE
TERRITORY_CREATE
TERRITORY_UPDATE
TERRITORY_BILLING
TERRITORY_UNARCHIVE
RECEIVE
}
enum InvoiceActionState {
PENDING
PENDING_HELD
HELD
PAID
FAILED
FORWARDING
FORWARDED
FAILED_FORWARD
RETRYING
CANCELING
}
model ItemMention {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
referrerId Int
refereeId Int
referrerItem Item @relation("referrer", fields: [referrerId], references: [id], onDelete: Cascade)
refereeItem Item @relation("referee", fields: [refereeId], references: [id], onDelete: Cascade)
@@unique([referrerId, refereeId], map: "ItemMention.referrerId_refereeId_unique")
@@index([createdAt], map: "ItemMention.created_at_index")
@@index([referrerId], map: "ItemMention.referrerId_index")
@@index([refereeId], map: "ItemMention.refereeId_index")
}
model Invoice {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
userId Int
hash String @unique(map: "Invoice.hash_unique")
preimage String? @unique(map: "Invoice.preimage_unique")
isHeld Boolean?
bolt11 String
expiresAt DateTime
confirmedAt DateTime?
confirmedIndex BigInt?
cancelled Boolean @default(false)
cancelledAt DateTime?
userCancel Boolean?
paymentAttempt Int @default(0)
retryPendingSince DateTime?
msatsRequested BigInt
msatsReceived BigInt?
desc String?
comment String?
lud18Data Json?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
invoiceForward InvoiceForward?
predecessorId Int? @unique(map: "Invoice.predecessorId_unique")
predecessorInvoice Invoice? @relation("PredecessorInvoice", fields: [predecessorId], references: [id], onDelete: Cascade)
successorInvoice Invoice? @relation("PredecessorInvoice")
actionState InvoiceActionState?
actionType InvoiceActionType?
actionOptimistic Boolean?
actionId Int?
actionArgs Json? @db.JsonB
actionError String?
actionResult Json? @db.JsonB
ItemAct ItemAct[]
Item Item[]
Upload Upload[]
PollVote PollVote[]
PollBlindVote PollBlindVote[]
WalletLog WalletLog[]
@@index([createdAt], map: "Invoice.created_at_index")
@@index([userId], map: "Invoice.userId_index")
@@index([confirmedIndex], map: "Invoice.confirmedIndex_index")
@@index([isHeld])
@@index([confirmedAt])
@@index([cancelledAt])
@@index([actionType])
@@index([actionState])
}
model DirectPayment {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
senderId Int?
receiverId Int?
preimage String? @unique
bolt11 String?
hash String? @unique
desc String?
comment String?
lud18Data Json?
msats BigInt
protocolId Int?
sender User? @relation("DirectPaymentSent", fields: [senderId], references: [id], onDelete: Cascade)
receiver User? @relation("DirectPaymentReceived", fields: [receiverId], references: [id], onDelete: Cascade)
protocol WalletProtocol? @relation(fields: [protocolId], references: [id], onDelete: SetNull)
@@index([createdAt])
@@index([senderId])
@@index([receiverId])
}
model InvoiceForward {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
bolt11 String
maxFeeMsats Int
protocolId Int
// we get these values when the invoice is held
expiryHeight Int?
acceptHeight Int?
// we get these values when the outgoing invoice is settled
invoiceId Int @unique
withdrawlId Int? @unique
invoice Invoice @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
withdrawl Withdrawl? @relation(fields: [withdrawlId], references: [id], onDelete: SetNull)
@@index([invoiceId])
@@index([protocolId])
@@index([withdrawlId])
}
model Withdrawl {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
userId Int
hash String?
preimage String?
bolt11 String?
msatsPaying BigInt
msatsPaid BigInt?
msatsFeePaying BigInt
msatsFeePaid BigInt?
status WithdrawlStatus?
autoWithdraw Boolean @default(false)
protocolId Int?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
protocol WalletProtocol? @relation(fields: [protocolId], references: [id], onDelete: SetNull)
invoiceForward InvoiceForward?
WalletLog WalletLog[]
@@index([createdAt], map: "Withdrawl.created_at_index")
@@index([userId], map: "Withdrawl.userId_index")
@@index([hash])
@@index([protocolId])
@@index([autoWithdraw])
@@index([status])
}
model Account {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
userId Int @map("user_id")
type String @map("provider_type")
provider String @map("provider_id")
providerAccountId String @map("provider_account_id")
refresh_token String? @map("refresh_token")
access_token String? @map("access_token")
expires_at String? @map("access_token_expires")
token_type String?
scope String?
id_token String?
session_state String?
// twitter oauth 1.0 needs these https://authjs.dev/reference/core/providers_twitter#notes
oauth_token String?
oauth_token_secret String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@index([userId], map: "accounts.user_id_index")
@@map("accounts")
}
model OFAC {
id Int @id @default(autoincrement())
startIP Unsupported("ipaddress")
endIP Unsupported("ipaddress")
country String
countryCode String
}
model Session {
id Int @id @default(autoincrement())
sessionToken String @unique(map: "sessions.session_token_unique") @map("session_token")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
userId Int @map("user_id")
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("sessions")
}
model VerificationToken {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
identifier String
token String @unique(map: "verification_requests.token_unique")
expires DateTime
attempts Int @default(0)
@@unique([identifier, token])
@@map("verification_requests")
}
model Bookmark {
userId Int
itemId Int
createdAt DateTime @default(now()) @map("created_at")
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@id([userId, itemId])
@@index([createdAt], map: "Bookmark.created_at_index")
}
// TODO: make thread subscriptions for OP by default so they can
// unsubscribe from their own threads and its not a special case
model ThreadSubscription {
userId Int
itemId Int
createdAt DateTime @default(now()) @map("created_at")
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@id([userId, itemId])
@@index([createdAt], map: "ThreadSubscription.created_at_index")
}
model UserSubscription {
followerId Int
followeeId Int
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
postsSubscribedAt DateTime?
commentsSubscribedAt DateTime?
follower User @relation("follower", fields: [followerId], references: [id], onDelete: Cascade)
followee User @relation("followee", fields: [followeeId], references: [id], onDelete: Cascade)
@@id([followerId, followeeId])
@@index([createdAt], map: "UserSubscription.created_at_index")
@@index([followerId], map: "UserSubscription.follower_index")
@@index([followeeId], map: "UserSubscription.followee_index")
}
model SubSubscription {
userId Int
subName String @db.Citext
createdAt DateTime @default(now()) @map("created_at")
sub Sub @relation(fields: [subName], references: [name], onDelete: Cascade, onUpdate: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
@@id([userId, subName])
@@index([createdAt], map: "SubSubscription.created_at_index")
}
model PushSubscription {
id Int @id @default(autoincrement())
userId Int
endpoint String
p256dh String
auth String
createdAt DateTime @default(now()) @map("created_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId], map: "PushSubscription.userId_index")
}
model Log {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
level LogLevel
name String
message String
env Json?
context Json?
@@index([createdAt, name], map: "Log.name_index")
@@ignore
}
model TerritoryTransfer {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
oldUserId Int
newUserId Int
subName String @db.Citext
oldUser User @relation("TerritoryTransfer_oldUser", fields: [oldUserId], references: [id], onDelete: Cascade)
newUser User @relation("TerritoryTransfer_newUser", fields: [newUserId], references: [id], onDelete: Cascade)
sub Sub @relation(fields: [subName], references: [name], onDelete: Cascade)
@@index([createdAt, newUserId], map: "TerritoryTransfer.newUserId_index")
@@index([createdAt, oldUserId], map: "TerritoryTransfer.oldUserId_index")
}
model Reminder {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
userId Int
itemId Int
remindAt DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
@@index([userId, remindAt], map: "Reminder.userId_reminderAt_index")
}
enum EarnType {
POST
COMMENT
TIP_COMMENT
TIP_POST
FOREVER_REFERRAL
ONE_DAY_REFERRAL
}
enum SubActType {
BILLING
REVENUE
}
enum Status {
ACTIVE
STOPPED
NOSATS
GRACE
}
enum PostType {
LINK
DISCUSSION
JOB
POLL
BOUNTY
}
enum ItemActType {
VOTE
BOOST
TIP
STREAM
POLL
DONT_LIKE_THIS
FEE
}
enum WithdrawlStatus {
INSUFFICIENT_BALANCE
INVALID_PAYMENT
PATHFINDING_TIMEOUT
ROUTE_NOT_FOUND
CONFIRMED
UNKNOWN_FAILURE
}
enum LogLevel {
OK
DEBUG
INFO
WARNING
ERROR
}
// ===================
// ==== WALLET V2 ====
// ===================
enum WalletProtocolName {
NWC
LNBITS
PHOENIXD
BLINK
WEBLN
LN_ADDR
LNC
CLN_REST
LND_GRPC
}
enum WalletSendProtocolName {
NWC
LNBITS
PHOENIXD
BLINK
WEBLN
LNC
}
enum WalletRecvProtocolName {
NWC
LNBITS
PHOENIXD
BLINK
LN_ADDR
CLN_REST
LND_GRPC
}
enum WalletProtocolStatus {
OK
WARNING
ERROR
}
enum WalletName {
ALBY
BLINK
BLIXT
CASHU_ME
CLN
COINOS
FOUNTAIN
LIFPAY
LNBITS
LND
MINIBITS
NPUB_CASH
PHOENIXD
PRIMAL
RIZFUL
SHOCKWALLET
SPEED
STRIKE
VOLTAGE
WALLET_OF_SATOSHI
ZBD
ZEUS
NWC
LN_ADDR
CASH_APP
}
model WalletTemplate {
name WalletName @id
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
sendProtocols WalletSendProtocolName[]
recvProtocols WalletRecvProtocolName[]
wallets Wallet[]
}
model Wallet {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
priority Int @default(0)
userId Int
templateName WalletName
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
template WalletTemplate @relation(fields: [templateName], references: [name], onDelete: Cascade)
protocols WalletProtocol[]
@@index([userId])
@@index([templateName])
}
model WalletProtocol {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
// NOTE: this denormalized json field exists to make polymorphic joins efficient
// when reading wallets ... it's populated by a trigger when wallet descendants update
// otherwise reading wallets would require a join on every descendant table.
// this pattern gives us fast reads and fast, type safe writes
config Json? @db.JsonB
walletId Int
wallet Wallet @relation(fields: [walletId], references: [id], onDelete: Cascade)
send Boolean
name WalletProtocolName
enabled Boolean @default(true)
status WalletProtocolStatus @default(OK)
withdrawals Withdrawl[]
directPayments DirectPayment[]
invoiceForward InvoiceForward[]
logs WalletLog[]
walletSendNWC WalletSendNWC?
walletSendLNbits WalletSendLNbits?
walletSendPhoenixd WalletSendPhoenixd?
walletSendBlink WalletSendBlink?
walletSendWebLN WalletSendWebLN?
walletSendLNC WalletSendLNC?
walletRecvNWC WalletRecvNWC?
walletRecvLNbits WalletRecvLNbits?
walletRecvPhoenixd WalletRecvPhoenixd?
walletRecvBlink WalletRecvBlink?
walletRecvLightningAddress WalletRecvLightningAddress?
walletRecvCLNRest WalletRecvCLNRest?
walletRecvLNDGRPC WalletRecvLNDGRPC?
@@index([walletId])
@@unique(name: "WalletProtocol_walletId_send_name_key", [walletId, send, name])
}
model WalletSendNWC {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
urlVaultId Int @unique
url Vault @relation(fields: [urlVaultId], references: [id], onDelete: Cascade)
}
model WalletSendLNbits {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
url String
apiKeyVaultId Int @unique
apiKey Vault @relation(fields: [apiKeyVaultId], references: [id], onDelete: Cascade)
}
model WalletSendPhoenixd {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
url String
apiKeyVaultId Int @unique
apiKey Vault @relation(fields: [apiKeyVaultId], references: [id], onDelete: Cascade)
}
model WalletSendBlink {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
currencyVaultId Int @unique
currency Vault @relation("blinkCurrencySend", fields: [currencyVaultId], references: [id], onDelete: Cascade)
apiKeyVaultId Int @unique
apiKey Vault @relation("blinkApiKeySend", fields: [apiKeyVaultId], references: [id], onDelete: Cascade)
}
model WalletSendWebLN {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
}
model WalletSendLNC {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
pairingPhraseVaultId Int @unique
pairingPhrase Vault? @relation("lncPairingPhrase", fields: [pairingPhraseVaultId], references: [id])
localKeyVaultId Int @unique
localKey Vault? @relation("lncLocalKey", fields: [localKeyVaultId], references: [id])
remoteKeyVaultId Int @unique
remoteKey Vault? @relation("lncRemoteKey", fields: [remoteKeyVaultId], references: [id])
serverHostVaultId Int @unique
serverHost Vault? @relation("lncServerHost", fields: [serverHostVaultId], references: [id])
}
model WalletRecvNWC {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
url String
}
model WalletRecvLNbits {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
url String
apiKey String
}
model WalletRecvPhoenixd {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
url String
apiKey String
}
model WalletRecvBlink {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
currency String
apiKey String
}
model WalletRecvLightningAddress {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
address String
}
model WalletRecvCLNRest {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
socket String
rune String
cert String?
}
model WalletRecvLNDGRPC {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
protocolId Int @unique
protocol WalletProtocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
socket String
macaroon String
cert String?
}