Commit ade84ace authored by ThinhNC's avatar ThinhNC

Merge branch 'refactor/phase-3-wallet-management-schema' into 'develop'

refactor(prisma): improve wallet management schema

See merge request !9
parents f4a20935 253f5929
...@@ -13,31 +13,32 @@ enum TransactionType { ...@@ -13,31 +13,32 @@ enum TransactionType {
} }
model User { model User {
id String @id @default(uuid()) @db.Uuid id String @id @default(uuid()) @db.Uuid
email String? @unique email String? @unique
password String? password String?
fullName String? @map("full_name") fullName String? @map("full_name")
avatarUrl String? @map("avatar_url") avatarUrl String? @map("avatar_url")
phoneNumber String? @unique @map("phone_number") phoneNumber String? @unique @map("phone_number")
isActive Boolean @default(false) @map("is_active") isActive Boolean @default(false) @map("is_active")
deletedAt DateTime? @map("deleted_at") deletedAt DateTime? @map("deleted_at")
deletedBy String? @map("deleted_by") @db.Uuid deletedBy String? @map("deleted_by") @db.Uuid
roleId String @map("role_id") @db.Uuid roleId String @map("role_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at") updatedAt DateTime @updatedAt @map("updated_at")
// Relations // Relations
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade) role Role @relation(fields: [roleId], references: [id], onDelete: Restrict)
wallets Wallet[] wallets Wallet[]
categories Category[] categories Category[]
transactions Transaction[] transactions Transaction[]
budgets Budget[] budgets Budget[]
refreshTokens RefreshToken[] refreshTokens RefreshToken[]
socialAccounts UserSocial[] socialAccounts UserSocial[]
verificationTokens VerificationToken[] verificationTokens VerificationToken[]
passwordResetTokens PasswordResetToken[] passwordResetTokens PasswordResetToken[]
devices UserDevice[] devices UserDevice[]
@@index([roleId])
@@map("users") @@map("users")
} }
...@@ -52,33 +53,47 @@ model Role { ...@@ -52,33 +53,47 @@ model Role {
} }
model Wallet { model Wallet {
id String @id @default(uuid()) @db.Uuid id String @id @default(uuid()) @db.Uuid
userId String @map("user_id") @db.Uuid userId String @map("user_id") @db.Uuid
name String name String
balance Float balance Decimal @default(0) @db.Decimal(18, 2)
createdAt DateTime @default(now()) @map("created_at") currency String @default("VND") @db.VarChar(3)
updatedAt DateTime @updatedAt @map("updated_at") icon String?
color String?
description String?
isDefault Boolean @default(false) @map("is_default")
isArchived Boolean @default(false) @map("is_archived")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade)
transactions Transaction[] transactions Transaction[]
@@unique([userId, name]) @@unique([userId, name])
@@index([userId])
@@map("wallets") @@map("wallets")
} }
model Category { model Category {
id String @id @default(uuid()) @db.Uuid id String @id @default(uuid()) @db.Uuid
userId String @map("user_id") @db.Uuid userId String @map("user_id") @db.Uuid
parentId String? @map("parent_id") @db.Uuid
name String name String
type TransactionType type TransactionType
icon String?
color String?
createdAt DateTime @default(now()) @map("created_at") createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at") updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade)
parent Category? @relation("CategoryHierarchy", fields: [parentId], references: [id], onDelete: SetNull)
children Category[] @relation("CategoryHierarchy")
transactions Transaction[] transactions Transaction[]
budgets Budget[] budgets Budget[]
@@unique([userId, name, type]) @@unique([userId, name, type])
@@index([userId])
@@index([parentId])
@@map("categories") @@map("categories")
} }
...@@ -87,17 +102,25 @@ model Transaction { ...@@ -87,17 +102,25 @@ model Transaction {
userId String @map("user_id") @db.Uuid userId String @map("user_id") @db.Uuid
walletId String @map("wallet_id") @db.Uuid walletId String @map("wallet_id") @db.Uuid
categoryId String @map("category_id") @db.Uuid categoryId String @map("category_id") @db.Uuid
amount Float amount Decimal @db.Decimal(18, 2)
type TransactionType type TransactionType
description String? description String?
receiptUrl String? @map("receipt_url")
location String?
date DateTime date DateTime
createdAt DateTime @default(now()) @map("created_at") createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at") updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade)
wallet Wallet @relation(fields: [walletId], references: [id], onDelete: Cascade) wallet Wallet @relation(fields: [walletId], references: [id], onDelete: Restrict)
category Category @relation(fields: [categoryId], references: [id], onDelete: Restrict) category Category @relation(fields: [categoryId], references: [id], onDelete: Restrict)
@@index([userId])
@@index([walletId])
@@index([categoryId])
@@index([date])
@@index([userId, date])
@@index([userId, type])
@@map("transactions") @@map("transactions")
} }
...@@ -105,16 +128,17 @@ model Budget { ...@@ -105,16 +128,17 @@ model Budget {
id String @id @default(uuid()) @db.Uuid id String @id @default(uuid()) @db.Uuid
userId String @map("user_id") @db.Uuid userId String @map("user_id") @db.Uuid
categoryId String @map("category_id") @db.Uuid categoryId String @map("category_id") @db.Uuid
name String amount Decimal @db.Decimal(18, 2)
amount Float
startDate DateTime @map("start_date") startDate DateTime @map("start_date")
endDate DateTime @map("end_date") endDate DateTime @map("end_date")
createdAt DateTime @default(now()) @map("created_at") createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at") updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade)
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade) category Category @relation(fields: [categoryId], references: [id], onDelete: Restrict)
@@index([categoryId])
@@index([userId, startDate, endDate])
@@map("budgets") @@map("budgets")
} }
...@@ -136,13 +160,14 @@ model RefreshToken { ...@@ -136,13 +160,14 @@ model RefreshToken {
model UserSocial { model UserSocial {
id String @id @default(uuid()) @db.Uuid id String @id @default(uuid()) @db.Uuid
userId String @map("user_id") @db.Uuid userId String @map("user_id") @db.Uuid
provider String // "ZALO", "GOOGLE", etc. provider String // "ZALO", "GOOGLE", etc.
providerUserId String @map("provider_user_id") providerUserId String @map("provider_user_id")
createdAt DateTime @default(now()) @map("created_at") createdAt DateTime @default(now()) @map("created_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerUserId]) @@unique([provider, providerUserId])
@@index([userId])
@@map("user_socials") @@map("user_socials")
} }
...@@ -155,6 +180,7 @@ model VerificationToken { ...@@ -155,6 +180,7 @@ model VerificationToken {
user User @relation(fields: [userId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId])
@@map("verification_tokens") @@map("verification_tokens")
} }
...@@ -167,6 +193,7 @@ model PasswordResetToken { ...@@ -167,6 +193,7 @@ model PasswordResetToken {
user User @relation(fields: [userId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId])
@@map("password_reset_tokens") @@map("password_reset_tokens")
} }
...@@ -179,10 +206,8 @@ model UserDevice { ...@@ -179,10 +206,8 @@ model UserDevice {
createdAt DateTime @default(now()) @map("created_at") createdAt DateTime @default(now()) @map("created_at")
lastLoginAt DateTime @default(now()) @map("last_login_at") lastLoginAt DateTime @default(now()) @map("last_login_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([userId, deviceHash]) @@unique([userId, deviceHash])
@@map("user_devices") @@map("user_devices")
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment