source: prisma/schema.prisma@ f021aa0

main
Last change on this file since f021aa0 was f021aa0, checked in by shapkar <naum.shapkarovski@…>, 2 weeks ago

update invoice_status trigger

  • Property mode set to 100644
File size: 6.5 KB
Line 
1generator client {
2 provider = "prisma-client-js"
3}
4
5datasource db {
6 provider = "postgresql"
7 url = env("DATABASE_URL")
8}
9
10model Tenant {
11 id String @id @default(cuid())
12 name String @map("company_name")
13 email String @unique @map("company_email")
14 address Json @map("company_address")
15 bankAccounts Json? @map("company_bank_accounts")
16 logoUrl String? @map("company_logo_url")
17 phoneNumber String? @map("company_phone_number")
18 vatNumber String? @map("company_vat_number")
19 companyNumber String? @map("company_no")
20 representative String @map("company_representative")
21 lastInvoiceNumber String @default("0") @map("company_last_invoice_number")
22 createdAt DateTime @default(now()) @map("created_at")
23 updatedAt DateTime @updatedAt @map("updated_at")
24 invoicesSent Invoice[]
25 services Service[]
26 employees Employee[]
27 clients Client[]
28 users User[]
29}
30
31model Client {
32 id String @id @default(uuid())
33 tenantId String @map("tenant_id")
34 name String
35 email String @unique
36 address Json
37 logoUrl String? @map("client_logo_url")
38 phoneNumber String? @map("client_phone_number")
39 vatNumber String? @map("client_vat")
40 companyNumber String? @map("client_company_no")
41 representative String @map("client_representative")
42 status ClientStatus @default(active) @map("client_status")
43 createdAt DateTime @default(now()) @map("created_at")
44 updatedAt DateTime @updatedAt @map("updated_at")
45
46 tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
47 invoicesReceived Invoice[] @relation("InvoiceTo")
48
49 // Note: Advanced indexes (partial, functional, case-insensitive)
50 // are handled via raw SQL in sql/02_client_email_index.sql
51
52 // Basic indexes that Prisma can handle
53 @@index([email]) // Basic email index
54 @@index([email, tenantId]) // Composite email + tenant index
55 @@index([status]) // Status index
56 @@index([tenantId]) // Tenant index for multi-tenant queries
57}
58
59model Service {
60 id String @id @default(uuid())
61 name String
62 sprint Float
63 hour Float
64 month Float
65 tenantId String @map("tenant_id")
66 tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
67
68 lineItems LineItem[]
69}
70
71model Invoice {
72 id String @id @default(uuid())
73 sent Int?
74 dueDate DateTime @map("invoice_due_date")
75 status InvoiceStatus @map("invoice_status")
76 currency Currency @map("invoice_currency")
77 quantityType QuantityType @map("invoice_quantity_type")
78 subTotal Float @map("invoice_sub_total")
79 issueDate DateTime @map("invoice_issue_date")
80 month Month @map("invoice_month")
81 discount Float? @map("invoice_discount")
82 taxes Float? @map("invoice_taxes")
83 totalAmount Float @map("invoice_total_amount")
84 invoiceNumber String @unique @map("invoice_number")
85 pdfRef String? @map("invoice_pdf_ref")
86 createdAt DateTime @default(now()) @map("created_at")
87 updatedAt DateTime @updatedAt @map("updated_at")
88
89 invoiceFromId String @map("tenant_id")
90 invoiceFrom Tenant @relation(fields: [invoiceFromId], references: [id], onDelete: Cascade)
91
92 invoiceToId String @map("client_id")
93 invoiceTo Client @relation("InvoiceTo", fields: [invoiceToId], references: [id], onDelete: Cascade)
94
95 items LineItem[]
96
97 // Performance indexes for common queries
98 @@index([status]) // Status-based queries
99 @@index([invoiceFromId]) // Tenant-based queries
100 @@index([invoiceToId]) // Client-based queries
101 @@index([issueDate]) // Date-based queries
102 @@index([dueDate]) // Due date queries
103 @@index([status, invoiceFromId]) // Combined status + tenant
104 @@index([status, dueDate]) // Overdue invoice queries
105}
106
107model LineItem {
108 id String @id @default(uuid())
109 title String
110 price Float @map("unit_pricr")
111 total Float
112 quantity Int
113 description String?
114 serviceId String @map("service_id")
115 service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
116 invoiceId String @map("invoice_id")
117 invoice Invoice @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
118}
119
120model Employee {
121 id String @id @default(uuid())
122 name String @map("employee_name")
123 email String @unique @map("employee_email")
124 status EmployeeStatus @default(active) @map("employee_status")
125 iban String? @map("employee_iban")
126 cv String? @map("employee_cv_ref")
127 photo String? @map("employee_photo_ref")
128 project String? @map("employee_project")
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.