Initial commit
This commit is contained in:
211
prisma/schema.prisma
Normal file
211
prisma/schema.prisma
Normal file
@@ -0,0 +1,211 @@
|
||||
// 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"
|
||||
output = "../node_modules/.prisma/client"
|
||||
}
|
||||
|
||||
generator python {
|
||||
provider = "prisma-client-py"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model Cliente {
|
||||
id Int @id @default(autoincrement())
|
||||
nombre String @db.VarChar(200)
|
||||
matriculaVehiculo String @unique @map("matricula_vehiculo") @db.VarChar(20)
|
||||
telefono String? @db.VarChar(20)
|
||||
email String? @db.VarChar(255)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
pedidos PedidoCliente[]
|
||||
|
||||
@@index([matriculaVehiculo])
|
||||
@@index([nombre])
|
||||
@@map("clientes")
|
||||
}
|
||||
|
||||
model PedidoCliente {
|
||||
id Int @id @default(autoincrement())
|
||||
numeroPedido String @unique @map("numero_pedido") @db.VarChar(50)
|
||||
clienteId Int @map("cliente_id")
|
||||
fechaPedido DateTime @default(now()) @map("fecha_pedido")
|
||||
fechaCita DateTime? @map("fecha_cita")
|
||||
estado String @default("pendiente_revision") @db.VarChar(30)
|
||||
presupuestoId String? @map("presupuesto_id") @db.VarChar(50)
|
||||
archivoPdfPath String? @map("archivo_pdf_path") @db.VarChar(500)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
cliente Cliente @relation(fields: [clienteId], references: [id], onDelete: Cascade)
|
||||
referencias ReferenciaPedidoCliente[]
|
||||
|
||||
@@index([numeroPedido])
|
||||
@@index([estado])
|
||||
@@index([fechaCita])
|
||||
@@index([fechaPedido])
|
||||
@@map("pedidos_cliente")
|
||||
}
|
||||
|
||||
model ReferenciaPedidoCliente {
|
||||
id Int @id @default(autoincrement())
|
||||
pedidoClienteId Int @map("pedido_cliente_id")
|
||||
referencia String @db.VarChar(100)
|
||||
denominacion String @db.VarChar(500)
|
||||
unidadesSolicitadas Int @default(1) @map("unidades_solicitadas")
|
||||
unidadesEnStock Int @default(0) @map("unidades_en_stock")
|
||||
unidadesPendientes Int @default(0) @map("unidades_pendientes")
|
||||
estado String @default("pendiente") @db.VarChar(20)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
pedidoCliente PedidoCliente @relation(fields: [pedidoClienteId], references: [id], onDelete: Cascade)
|
||||
pedidosProveedor ReferenciaPedidoProveedor[]
|
||||
|
||||
@@index([referencia])
|
||||
@@index([estado])
|
||||
@@index([pedidoClienteId, estado])
|
||||
@@map("referencias_pedido_cliente")
|
||||
}
|
||||
|
||||
model Proveedor {
|
||||
id Int @id @default(autoincrement())
|
||||
nombre String @db.VarChar(200)
|
||||
email String? @db.VarChar(255)
|
||||
tieneWeb Boolean @default(true) @map("tiene_web")
|
||||
activo Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
pedidos PedidoProveedor[]
|
||||
albaranes Albaran[]
|
||||
devoluciones Devolucion[]
|
||||
|
||||
@@index([nombre])
|
||||
@@index([activo])
|
||||
@@map("proveedores")
|
||||
}
|
||||
|
||||
model PedidoProveedor {
|
||||
id Int @id @default(autoincrement())
|
||||
proveedorId Int @map("proveedor_id")
|
||||
numeroPedido String? @map("numero_pedido") @db.VarChar(100)
|
||||
fechaPedido DateTime @default(now()) @map("fecha_pedido")
|
||||
emailConfirmacionPath String? @map("email_confirmacion_path") @db.VarChar(500)
|
||||
estado String @default("pendiente_recepcion") @db.VarChar(30)
|
||||
tipo String @default("web") @db.VarChar(20)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
proveedor Proveedor @relation(fields: [proveedorId], references: [id], onDelete: Cascade)
|
||||
referencias ReferenciaPedidoProveedor[]
|
||||
|
||||
@@index([proveedorId, estado])
|
||||
@@index([fechaPedido])
|
||||
@@index([estado])
|
||||
@@map("pedidos_proveedor")
|
||||
}
|
||||
|
||||
model ReferenciaPedidoProveedor {
|
||||
id Int @id @default(autoincrement())
|
||||
pedidoProveedorId Int @map("pedido_proveedor_id")
|
||||
referenciaPedidoClienteId Int? @map("referencia_pedido_cliente_id")
|
||||
referencia String @db.VarChar(100)
|
||||
denominacion String @db.VarChar(500)
|
||||
unidadesPedidas Int @default(1) @map("unidades_pedidas")
|
||||
unidadesRecibidas Int @default(0) @map("unidades_recibidas")
|
||||
estado String @default("pendiente") @db.VarChar(20)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
pedidoProveedor PedidoProveedor @relation(fields: [pedidoProveedorId], references: [id], onDelete: Cascade)
|
||||
referenciaPedidoCliente ReferenciaPedidoCliente? @relation(fields: [referenciaPedidoClienteId], references: [id], onDelete: Cascade)
|
||||
referenciasAlbaran ReferenciaAlbaran[]
|
||||
|
||||
@@index([referencia])
|
||||
@@index([estado])
|
||||
@@index([pedidoProveedorId, estado])
|
||||
@@map("referencias_pedido_proveedor")
|
||||
}
|
||||
|
||||
model Albaran {
|
||||
id Int @id @default(autoincrement())
|
||||
proveedorId Int? @map("proveedor_id")
|
||||
numeroAlbaran String? @map("numero_albaran") @db.VarChar(100)
|
||||
fechaAlbaran DateTime? @map("fecha_albaran") @db.Date
|
||||
archivoPath String @map("archivo_path") @db.VarChar(500)
|
||||
estadoProcesado String @default("pendiente") @map("estado_procesado") @db.VarChar(30)
|
||||
fechaProcesado DateTime? @map("fecha_procesado")
|
||||
datosOcr Json @default("{}") @map("datos_ocr")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
proveedor Proveedor? @relation(fields: [proveedorId], references: [id], onDelete: Cascade)
|
||||
referencias ReferenciaAlbaran[]
|
||||
devoluciones Devolucion[]
|
||||
|
||||
@@index([proveedorId, estadoProcesado])
|
||||
@@index([numeroAlbaran])
|
||||
@@index([fechaAlbaran])
|
||||
@@index([estadoProcesado])
|
||||
@@map("albaranes")
|
||||
}
|
||||
|
||||
model ReferenciaAlbaran {
|
||||
id Int @id @default(autoincrement())
|
||||
albaranId Int @map("albaran_id")
|
||||
referencia String @db.VarChar(100)
|
||||
denominacion String @db.VarChar(500)
|
||||
unidades Int @default(1)
|
||||
precioUnitario Decimal @default(0) @map("precio_unitario") @db.Decimal(10, 2)
|
||||
impuestoTipo String @default("21") @map("impuesto_tipo") @db.VarChar(5)
|
||||
impuestoValor Decimal @default(0) @map("impuesto_valor") @db.Decimal(10, 2)
|
||||
referenciaPedidoProveedorId Int? @map("referencia_pedido_proveedor_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
albaran Albaran @relation(fields: [albaranId], references: [id], onDelete: Cascade)
|
||||
referenciaPedidoProveedor ReferenciaPedidoProveedor? @relation(fields: [referenciaPedidoProveedorId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([referencia])
|
||||
@@index([albaranId])
|
||||
@@map("referencias_albaran")
|
||||
}
|
||||
|
||||
model Devolucion {
|
||||
id Int @id @default(autoincrement())
|
||||
proveedorId Int @map("proveedor_id")
|
||||
referencia String @db.VarChar(100)
|
||||
denominacion String? @db.VarChar(500)
|
||||
unidades Int @default(1)
|
||||
fechaDevolucion DateTime @default(now()) @map("fecha_devolucion")
|
||||
estadoAbono String @default("pendiente") @map("estado_abono") @db.VarChar(20)
|
||||
albaranAbonoId Int? @map("albaran_abono_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
proveedor Proveedor @relation(fields: [proveedorId], references: [id], onDelete: Cascade)
|
||||
albaranAbono Albaran? @relation(fields: [albaranAbonoId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([proveedorId, estadoAbono])
|
||||
@@index([referencia])
|
||||
@@index([estadoAbono])
|
||||
@@map("devoluciones")
|
||||
}
|
||||
|
||||
model StockReferencia {
|
||||
id Int @id @default(autoincrement())
|
||||
referencia String @unique @db.VarChar(100)
|
||||
unidadesDisponibles Int @default(0) @map("unidades_disponibles")
|
||||
ultimaActualizacion DateTime @updatedAt @map("ultima_actualizacion")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
@@index([referencia])
|
||||
@@map("stock_referencias")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user