source: prisma/schema.prisma

main
Last change on this file was 38387ce, checked in by shapkar <naum.shapkarovski@…>, 4 weeks ago

chore

  • Property mode set to 100644
File size: 5.9 KB
Line 
1generator client {
2 provider = "prisma-client-js"
3}
4
5datasource db {
6 provider = "postgresql"
7 url = env("DATABASE_URL")
8}
9
10model Client {
11 id String @id @default(uuid())
12 tenantId String @map("tenant_id")
13 name String
14 email String @unique
15 address Json
16 logoUrl String? @map("logo_url")
17 phoneNumber String? @map("phone_number")
18 vatNumber String? @map("vat_number")
19 companyNumber String? @map("company_number")
20 representative String
21 status ClientStatus @default(active)
22 createdAt DateTime @default(now()) @map("created_at")
23 updatedAt DateTime @updatedAt @map("updated_at")
24
25 tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
26 invoicesReceived Invoice[] @relation("InvoiceTo")
27
28 // Note: Advanced indexes (partial, functional, case-insensitive)
29 // are handled via raw SQL in sql/02_client_email_index.sql
30
31 // Basic indexes that Prisma can handle
32 @@index([email]) // Basic email index
33 @@index([email, tenantId]) // Composite email + tenant index
34 @@index([status]) // Status index
35 @@index([tenantId]) // Tenant index for multi-tenant queries
36}
37
38model Service {
39 id String @id @default(uuid())
40 name String
41 sprint Float
42 hour Float
43 month Float
44 tenantId String @map("tenant_id")
45 tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
46
47 lineItems LineItem[]
48}
49
50model Invoice {
51 id String @id @default(uuid())
52 sent Int?
53 dueDate DateTime @map("due_date")
54 status InvoiceStatus
55 currency Currency
56 quantityType QuantityType @map("quantity_type")
57 subTotal Float @map("sub_total")
58 issueDate DateTime @map("issue_date")
59 month Month
60 discount Float?
61 taxes Float?
62 totalAmount Float @map("total_amount")
63 invoiceNumber String @unique @map("invoice_number")
64 pdfRef String? @map("pdf_ref")
65 createdAt DateTime @default(now()) @map("created_at")
66 updatedAt DateTime @updatedAt @map("updated_at")
67
68 invoiceFromId String @map("tenant_id")
69 invoiceFrom Tenant @relation(fields: [invoiceFromId], references: [id], onDelete: Cascade)
70
71 invoiceToId String @map("client_id")
72 invoiceTo Client @relation("InvoiceTo", fields: [invoiceToId], references: [id], onDelete: Cascade)
73
74 items LineItem[]
75
76 // Performance indexes for common queries
77 @@index([status]) // Status-based queries
78 @@index([invoiceFromId]) // Tenant-based queries
79 @@index([invoiceToId]) // Client-based queries
80 @@index([issueDate]) // Date-based queries
81 @@index([dueDate]) // Due date queries
82 @@index([status, invoiceFromId]) // Combined status + tenant
83 @@index([status, dueDate]) // Overdue invoice queries
84}
85
86model LineItem {
87 id String @id @default(uuid())
88 title String
89 price Float
90 total Float
91 quantity Int
92 description String?
93 serviceId String @map("service_id")
94 service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
95 invoiceId String @map("invoice_id")
96 invoice Invoice @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
97}
98
99model Tenant {
100 id String @id @default(cuid())
101 name String
102 email String @unique
103 address Json
104 bankAccounts Json? @map("bank_accounts")
105 logoUrl String? @map("logo_url")
106 phoneNumber String? @map("phone_number")
107 vatNumber String? @map("vat_number")
108 companyNumber String? @map("company_number")
109 representative String
110 lastInvoiceNumber String @default("0") @map("last_invoice_number")
111 createdAt DateTime @default(now()) @map("created_at")
112 updatedAt DateTime @updatedAt @map("updated_at")
113 invoicesSent Invoice[]
114 services Service[]
115 employees Employee[]
116 clients Client[]
117 users User[]
118}
119
120model Employee {
121 id String @id @default(uuid())
122 name String
123 email String @unique
124 status EmployeeStatus @default(active)
125 iban String?
126 cv String?
127 photo String?
128 project String?
129 tenantId String @map("tenant_id")
130 tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
131 createdAt DateTime @default(now()) @map("created_at")
132 updatedAt DateTime @updatedAt @map("updated_at")
133}
134
135model User {
136 id String @id @default(uuid())
137 uid String @unique // Firebase UID
138 email String @unique
139 displayName String @map("display_name")
140 role UserRole
141 tenantId String @map("tenant_id")
142 tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
143 createdAt DateTime @default(now()) @map("created_at")
144 updatedAt DateTime @updatedAt @map("updated_at")
145}
146
147enum UserRole {
148 ADMIN @map("ADMIN")
149 MANAGER @map("MANAGER")
150 USER @map("USER")
151}
152
153enum ClientStatus {
154 active @map("ACTIVE")
155 banned @map("BANNED")
156 inactive @map("INACTIVE")
157}
158
159enum InvoiceStatus {
160 draft @map("DRAFT")
161 processing @map("PROCESSING")
162 pending @map("PENDING")
163 overdue @map("OVERDUE")
164 paid @map("PAID")
165}
166
167enum Currency {
168 EUR @map("EUR")
169 USD @map("USD")
170}
171
172enum QuantityType {
173 Unit @map("UNIT")
174 Hour @map("HOUR")
175 Sprint @map("SPRINT")
176 Month @map("MONTH")
177}
178
179enum Month {
180 January @map("JANUARY")
181 February @map("FEBRUARY")
182 March @map("MARCH")
183 April @map("APRIL")
184 May @map("MAY")
185 June @map("JUNE")
186 July @map("JULY")
187 August @map("AUGUST")
188 September @map("SEPTEMBER")
189 October @map("OCTOBER")
190 November @map("NOVEMBER")
191 December @map("DECEMBER")
192}
193
194enum EmployeeStatus {
195 active @map("ACTIVE")
196 inactive @map("INACTIVE")
197}
Note: See TracBrowser for help on using the repository browser.