Repository navigation
Expand file tree
/
Copy pathschema.prisma
More file actions
290 lines (249 loc) · 9.68 KB
/
Copy pathschema.prisma
File metadata and controls
290 lines (249 loc) · 9.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// ==========================================
// ユーザー
// ==========================================
model User {
id String @id @default(uuid())
email String @unique
password String
name String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Relations
customers Customer[]
projects Project[]
invoices Invoice[]
expenses Expense[]
expenseCategories ExpenseCategory[]
settings UserSettings?
@@map("users")
}
// ==========================================
// ユーザー設定
// ==========================================
model UserSettings {
id String @id @default(uuid())
userId String @unique @map("user_id")
// 事業者情報
businessName String? @map("business_name") // 屋号・事業者名
representativeName String? @map("representative_name") // 代表者名
postalCode String? @map("postal_code") // 郵便番号
address String? @map("address") // 住所
phone String? @map("phone") // 電話番号
email String? @map("email") // メールアドレス
// 銀行口座情報
bankName String? @map("bank_name") // 銀行名
branchName String? @map("branch_name") // 支店名
accountType String? @map("account_type") // 口座種別(普通/当座)
accountNumber String? @map("account_number") // 口座番号
accountHolder String? @map("account_holder") // 口座名義
// 請求書設定
invoicePrefix String? @default("INV") @map("invoice_prefix") // 請求書番号プレフィックス
taxRate Float? @default(0.10) @map("tax_rate") // 消費税率(デフォルト10%)
defaultPaymentDays Int? @default(30) @map("default_payment_days") // デフォルト支払期限(日数)
invoiceNotes String? @map("invoice_notes") // 請求書デフォルト備考
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Relations
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("user_settings")
}
// ==========================================
// 顧客
// ==========================================
model Customer {
id String @id @default(uuid())
userId String @map("user_id")
name String
contactName String? @map("contact_name")
email String?
phone String?
notes String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
// Relations
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
projects Project[]
invoices Invoice[]
@@index([userId])
@@index([userId, deletedAt])
@@map("customers")
}
// ==========================================
// 案件
// ==========================================
enum ProjectStatus {
PROSPECT // 見込み
IN_PROGRESS // 進行中
COMPLETED // 完了
LOST // 失注
@@map("project_status")
}
enum ContractType {
FIXED // 固定報酬
HOURLY // 時給
COMMISSION // 成果報酬
@@map("contract_type")
}
model Project {
id String @id @default(uuid())
userId String @map("user_id")
customerId String @map("customer_id")
name String
description String?
contractType ContractType @map("contract_type")
contractAmount Int? @map("contract_amount") // 契約金額(円)- 固定報酬の場合
hourlyRate Int? @map("hourly_rate") // 時給(円)- 時給契約の場合
startDate DateTime? @map("start_date")
endDate DateTime? @map("end_date")
status ProjectStatus @default(PROSPECT)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
// Relations
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
customer Customer @relation(fields: [customerId], references: [id], onDelete: Restrict)
invoices Invoice[]
expenses Expense[]
@@index([userId])
@@index([customerId])
@@index([userId, deletedAt])
@@map("projects")
}
// ==========================================
// 請求書
// ==========================================
enum InvoiceStatus {
DRAFT // 下書き
SENT // 請求済
PAID // 入金済
@@map("invoice_status")
}
model Invoice {
id String @id @default(uuid())
userId String @map("user_id")
customerId String @map("customer_id")
projectId String @map("project_id")
invoiceNumber String? @unique @map("invoice_number") // 請求書番号(任意)
status InvoiceStatus @default(DRAFT)
issuedAt DateTime @map("issued_at") // 請求日
dueAt DateTime @map("due_at") // 支払期限
totalAmount Int @map("total_amount") // 合計金額(円)※明細から算出
paidAmount Int @default(0) @map("paid_amount") // 入金済み金額(円)※キャッシュ
notes String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
// Relations
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
customer Customer @relation(fields: [customerId], references: [id], onDelete: Restrict)
project Project @relation(fields: [projectId], references: [id], onDelete: Restrict)
items InvoiceItem[]
payments Payment[]
@@index([userId])
@@index([customerId])
@@index([projectId])
@@index([userId, status])
@@index([userId, issuedAt])
@@index([userId, deletedAt])
@@map("invoices")
}
// ==========================================
// 請求明細
// ==========================================
model InvoiceItem {
id String @id @default(uuid())
invoiceId String @map("invoice_id")
name String // 品目名
description String? // 説明
quantity Int @default(1) // 数量
unitPrice Int @map("unit_price") // 単価(円)
amount Int // 金額(円)※ quantity * unitPrice
hours Float? // 稼働時間(時給契約の場合)
sortOrder Int @default(0) @map("sort_order") // 表示順
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Relations
invoice Invoice @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
@@index([invoiceId])
@@map("invoice_items")
}
// ==========================================
// 入金
// ==========================================
enum PaymentMethod {
BANK_TRANSFER // 銀行振込
CREDIT_CARD // クレジットカード
CASH // 現金
OTHER // その他
@@map("payment_method")
}
model Payment {
id String @id @default(uuid())
invoiceId String @map("invoice_id")
amount Int // 入金額(円)
paidAt DateTime @map("paid_at") // 入金日
paymentMethod PaymentMethod @map("payment_method")
notes String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
// Relations
invoice Invoice @relation(fields: [invoiceId], references: [id], onDelete: Restrict)
@@index([invoiceId])
@@index([paidAt])
@@map("payments")
}
// ==========================================
// 経費カテゴリ
// ==========================================
model ExpenseCategory {
id String @id @default(uuid())
userId String @map("user_id")
name String
color String? // 表示色(任意)
sortOrder Int @default(0) @map("sort_order")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Relations
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
expenses Expense[]
@@index([userId])
@@map("expense_categories")
}
// ==========================================
// 経費
// ==========================================
model Expense {
id String @id @default(uuid())
userId String @map("user_id")
projectId String? @map("project_id") // 案件紐づけ(任意)
categoryId String @map("category_id")
date DateTime // 使用日
amount Int // 金額(円)
paymentMethod PaymentMethod @map("payment_method")
description String? // 説明
notes String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
// Relations
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
project Project? @relation(fields: [projectId], references: [id], onDelete: SetNull)
category ExpenseCategory @relation(fields: [categoryId], references: [id], onDelete: Restrict)
@@index([userId])
@@index([projectId])
@@index([categoryId])
@@index([userId, date])
@@index([userId, deletedAt])
@@map("expenses")
}