diff options
Diffstat (limited to 'prisma/schema.prisma')
| -rw-r--r-- | prisma/schema.prisma | 97 | 
1 files changed, 97 insertions, 0 deletions
| diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..7c99fed --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,97 @@ +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 +}
\ No newline at end of file |