-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.prisma
More file actions
365 lines (304 loc) · 11.5 KB
/
Copy pathschema.prisma
File metadata and controls
365 lines (304 loc) · 11.5 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Product {
id String @id
nombre String
estilo String
display String
precio Int
disponible Boolean @default(true)
cat String
imgs String[] @default([])
specMovimiento String? @map("spec_movimiento")
specDimensiones String? @map("spec_dimensiones")
specCaja String? @map("spec_caja")
specCorrea String? @map("spec_correa")
specCristal String? @map("spec_cristal")
specFunciones String? @map("spec_funciones")
specResistenciaAgua String? @map("spec_resistencia_agua")
specPeso String? @map("spec_peso")
specBateria String? @map("spec_bateria")
specReservaMarcha String? @map("spec_reserva_marcha")
specObservaciones String? @map("spec_observaciones")
notasDescripcion String? @map("notas_descripcion")
notasTop String? @map("notas_top")
notasCorazon String? @map("notas_corazon")
notasBase String? @map("notas_base")
marca String?
genero String?
destacado Boolean @default(false)
destacadoOrden Int? @map("destacado_orden")
@@index([cat(ops: raw("gin_trgm_ops"))], type: Gin, map: "productos_cat_trgm_idx")
@@index([marca(ops: raw("gin_trgm_ops"))], type: Gin, map: "productos_marca_trgm_idx")
@@index([genero(ops: raw("gin_trgm_ops"))], type: Gin, map: "productos_genero_trgm_idx")
@@map("productos")
}
enum Rol {
ADMIN
CLIENTE
}
model User {
id String @id @default(uuid())
email String @unique
passwordHash String? @map("password_hash")
nombre String
telefono String?
ciudad String?
departamento String?
direccion String?
rol Rol @default(CLIENTE)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
refreshTokens RefreshToken[]
passwordResets PasswordReset[]
orders Order[]
addresses Address[]
@@map("users")
}
// Libreta de direcciones del usuario — separada de ShippingInfo (que es un
// snapshot inmutable por pedido). Varias direcciones por usuario, una
// marcada como principal a la vez (lo garantiza AccountService, no la BD).
model Address {
id String @id @default(uuid())
userId String @map("user_id")
alias String?
ciudad String
departamento String
direccion String
esPrincipal Boolean @default(false) @map("es_principal")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("addresses")
}
model RefreshToken {
id String @id @default(uuid())
userId String @map("user_id")
tokenHash String @map("token_hash")
expiresAt DateTime @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("refresh_tokens")
}
model OtpCode {
id String @id @default(uuid())
email String
codeHash String @map("code_hash")
expiresAt DateTime @map("expires_at")
used Boolean @default(false)
createdAt DateTime @default(now()) @map("created_at")
@@map("otp_codes")
}
model PasswordReset {
id String @id @default(uuid())
userId String @map("user_id")
tokenHash String @map("token_hash")
expiresAt DateTime @map("expires_at")
used Boolean @default(false)
createdAt DateTime @default(now()) @map("created_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("password_resets")
}
// ─── Orders ──────────────────────────────────────────────────────────────────
enum EstadoPedido {
PENDIENTE
CONFIRMADO
EN_CAMINO
ENTREGADO
CANCELADO
}
enum MetodoPago {
TRANSFERENCIA
CONTRAENTREGA
TARJETA_CREDITO
TARJETA_DEBITO
NEQUI
DAVIPLATA
MERCADOPAGO
}
enum EstadoPago {
PENDIENTE
APROBADO
RECHAZADO
CANCELADO
}
model Order {
id String @id @default(uuid())
orderNumber String @unique @map("order_number")
userId String? @map("user_id")
status EstadoPedido @default(PENDIENTE)
subtotal Int
total Int
paymentMethod MetodoPago @map("payment_method")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
items OrderItem[]
shippingInfo ShippingInfo?
statusHistory OrderStatusHistory[]
payments Payment[]
historicalSales HistoricalSale[]
@@map("orders")
}
model OrderItem {
id String @id @default(uuid())
orderId String @map("order_id")
productId String @map("product_id")
nombre String
precioUnitario Int @map("precio_unitario")
cantidad Int
subtotal Int
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
@@map("order_items")
}
model ShippingInfo {
id String @id @default(uuid())
orderId String @unique @map("order_id")
nombreCompleto String @map("nombre_completo")
email String
telefono String
ciudad String
departamento String
direccion String
notas String?
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
@@map("shipping_info")
}
model OrderStatusHistory {
id String @id @default(uuid())
orderId String @map("order_id")
statusAnterior EstadoPedido? @map("status_anterior")
statusNuevo EstadoPedido @map("status_nuevo")
changedBy String? @map("changed_by")
createdAt DateTime @default(now()) @map("created_at")
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
@@map("order_status_history")
}
// ─── Audit Log ────────────────────────────────────────────────────────────────
model AuditLog {
id String @id @default(uuid())
accion String // CREAR | EDITAR | ELIMINAR | ESTADO
entidad String // producto | pedido
entidadId String @map("entidad_id")
descripcion String
userId String? @map("user_id")
userName String? @map("user_name")
createdAt DateTime @default(now()) @map("created_at")
@@map("audit_log")
}
// ─── Inventario y Precios ─────────────────────────────────────────────────────
model InventarioMaestro {
id String @id @default(uuid())
marca String?
modelo String @unique
stock Int @default(0)
costoUnitario Int @default(0) @map("costo_unitario")
categoria String @default("Reloj")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("inventario_maestro")
}
model PrecioProducto {
id String @id @default(uuid())
marca String?
modelo String @unique
costoUnitario Int @default(0) @map("costo_unitario")
costoAdicional Int @default(25028) @map("costo_adicional")
costoTotal Int @default(0) @map("costo_total")
precioPublico Int? @map("precio_publico")
precioCierre Int? @map("precio_cierre")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("calculo_precios")
}
// ─── Historical Data ──────────────────────────────────────────────────────────
model HistoricalSale {
id String @id @default(uuid())
orderId String? @map("order_id")
fecha DateTime @db.Date
cliente String
celular String?
marca String?
modelo String
estilo String?
precioVenta Int @default(0) @map("precio_venta")
costoProducto Int @default(0) @map("costo_producto")
costoEnvio Int @default(0) @map("costo_envio")
abono Int @default(0)
saldoPendiente Int @default(0) @map("saldo_pendiente")
gananciaNeta Int? @map("ganancia_neta")
fuente String?
estado String
createdAt DateTime @default(now()) @map("created_at")
order Order? @relation(fields: [orderId], references: [id], onDelete: Cascade)
@@map("historical_sales")
}
model Purchase {
id String @id @default(uuid())
fecha DateTime @db.Date
marca String?
modelo String
cantidad Int
costoUnitario Int @map("costo_unitario")
costoTotal Int @map("costo_total")
categoria String
createdAt DateTime @default(now()) @map("created_at")
@@map("purchases")
}
model Expense {
id String @id @default(uuid())
fecha DateTime @db.Date
concepto String
monto Int
responsable String?
estado String?
createdAt DateTime @default(now()) @map("created_at")
@@map("expenses")
}
// ─── Promociones ──────────────────────────────────────────────────────────────
enum PromotionScope {
PRODUCTO
CATEGORIA
MARCA
TODOS
}
model Promotion {
id String @id @default(uuid())
nombre String
alcance PromotionScope
porcentaje Int
productosIncluidos String[] @default([]) @map("productos_incluidos")
categoria String?
marca String?
excluidos String[] @default([])
soloCuentaActiva Boolean @default(false) @map("solo_cuenta_activa")
fechaInicio DateTime @map("fecha_inicio")
fechaFin DateTime @map("fecha_fin")
activo Boolean @default(true)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("promociones")
}
// ─── Payments ─────────────────────────────────────────────────────────────────
model Payment {
id String @id @default(uuid())
orderId String? @map("order_id")
orderNumber String @map("order_number")
userId String? @map("user_id")
estado EstadoPago @default(PENDIENTE)
preferenceId String? @map("preference_id")
mpPaymentId String? @map("mp_payment_id")
checkoutUrl String? @map("checkout_url")
total Int
draftPayload Json? @map("draft_payload")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
order Order? @relation(fields: [orderId], references: [id], onDelete: Cascade)
@@index([orderNumber])
@@map("payments")
}