generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") } // TODO: user deletion should delete all transactions model User { id Int @id @default(autoincrement()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt userName String @unique email String @unique fullName String password String refreshTokenVersion Int @default(1) transactions Transaction[] monthlyBudgetHistory MonthlyBudget[] friends Friend[] friendOf Friend[] @relation(name: "friend") collaboratorOf TransactionCollaborator[] } model Transaction { id Int @id @default(autoincrement()) user User @relation(fields: [userId], references: [id]) userId Int createdAt DateTime @default(now()) time DateTime @default(now()) // can be edited from the client side type TransactionType @default(SPENT) value String currency String reason String place String description String collaborators TransactionCollaborator[] } model TransactionCollaborator { id Int @id @default(autoincrement()) transaction Transaction @relation(fields: [transactionId], references: [id]) transactionId Int user User @relation(fields: [userId], references: [id]) userId Int } // each user has a unique monthly limit for each month // the previous limit is set for the next month unless changed // TODO: find a way to auto-generate a row for each user every month // TODO: figure out a way to handle budgets with different currencies // TODO: (maybe have only one primary currency and a budget for just that) model MonthlyBudget { id Int @id @default(autoincrement()) user User @relation(fields: [userId], references: [id]) userId Int createdAt DateTime @default(now()) month Month year Int value Int currency String } model Friend { id Int @id @default(autoincrement()) user User @relation(fields: [userId], references: [id]) userId Int friend User @relation(name: "friend", fields: [friendId], references: [id]) friendId Int @@unique([userId, friendId]) } enum TransactionType { SPENT RECEIVED BORROWED LENT } enum Month { JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER OCTOBER NOVEMBER DECEMBER }